forked from GNUsocial/gnu-social
Add registration events to EmailregisterAction
This commit is contained in:
parent
d9d9a10b6f
commit
cd0d7be251
@ -240,78 +240,85 @@ class EmailregisterAction extends Action
|
|||||||
|
|
||||||
function setPassword()
|
function setPassword()
|
||||||
{
|
{
|
||||||
if (!empty($this->invitation)) {
|
if (Event::handle('StartRegistrationTry', array($this))) {
|
||||||
$email = trim($this->invitation->address);
|
if (!empty($this->invitation)) {
|
||||||
} else if (!empty($this->confirmation)) {
|
$email = trim($this->invitation->address);
|
||||||
$email = trim($this->confirmation->address);
|
} else if (!empty($this->confirmation)) {
|
||||||
} else {
|
$email = trim($this->confirmation->address);
|
||||||
throw new Exception('No confirmation thing.');
|
} else {
|
||||||
}
|
throw new Exception('No confirmation thing.');
|
||||||
|
|
||||||
if (!$this->tos) {
|
|
||||||
// TRANS: Error text when trying to register without agreeing to the terms.
|
|
||||||
$this->error = _m('You must accept the terms of service and privacy policy to register.');
|
|
||||||
return;
|
|
||||||
} else if (empty($this->password1)) {
|
|
||||||
// TRANS: Error text when trying to register without a password.
|
|
||||||
$this->error = _m('You must set a password');
|
|
||||||
} else if (strlen($this->password1) < 6) {
|
|
||||||
// TRANS: Error text when trying to register with too short a password.
|
|
||||||
$this->error = _m('Password must be 6 or more characters.');
|
|
||||||
} else if ($this->password1 != $this->password2) {
|
|
||||||
// TRANS: Error text when trying to register without providing the same password twice.
|
|
||||||
$this->error = _m('Passwords do not match.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($this->error)) {
|
|
||||||
$nickname = $this->nicknameFromEmail($email);
|
|
||||||
$this->form = new ConfirmRegistrationForm($this, $nickname, $this->email, $this->code);
|
|
||||||
$this->showPage();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$nickname = $this->nicknameFromEmail($email);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->user = User::register(array('nickname' => $nickname,
|
|
||||||
'email' => $email,
|
|
||||||
'password' => $this->password1,
|
|
||||||
'email_confirmed' => true));
|
|
||||||
} catch (ClientException $e) {
|
|
||||||
$this->error = $e->getMessage();
|
|
||||||
$nickname = $this->nicknameFromEmail($email);
|
|
||||||
$this->form = new ConfirmRegistrationForm($this, $nickname, $this->email, $this->code);
|
|
||||||
$this->showPage();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($this->user)) {
|
|
||||||
throw new Exception('Failed to register user.');
|
|
||||||
}
|
|
||||||
|
|
||||||
common_set_user($this->user);
|
|
||||||
// this is a real login
|
|
||||||
common_real_login(true);
|
|
||||||
|
|
||||||
// Re-init language env in case it changed (not yet, but soon)
|
|
||||||
common_init_language();
|
|
||||||
|
|
||||||
if (!empty($this->invitation)) {
|
|
||||||
$inviter = User::staticGet('id', $this->invitation->user_id);
|
|
||||||
if (!empty($inviter)) {
|
|
||||||
Subscription::start($inviter->getProfile(),
|
|
||||||
$this->user->getProfile());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->invitation->delete();
|
if (!$this->tos) {
|
||||||
} else if (!empty($this->confirmation)) {
|
// TRANS: Error text when trying to register without agreeing to the terms.
|
||||||
$this->confirmation->delete();
|
$this->error = _m('You must accept the terms of service and privacy policy to register.');
|
||||||
} else {
|
return;
|
||||||
throw new Exception('No confirmation thing.');
|
} else if (empty($this->password1)) {
|
||||||
|
// TRANS: Error text when trying to register without a password.
|
||||||
|
$this->error = _m('You must set a password');
|
||||||
|
} else if (strlen($this->password1) < 6) {
|
||||||
|
// TRANS: Error text when trying to register with too short a password.
|
||||||
|
$this->error = _m('Password must be 6 or more characters.');
|
||||||
|
} else if ($this->password1 != $this->password2) {
|
||||||
|
// TRANS: Error text when trying to register without providing the same password twice.
|
||||||
|
$this->error = _m('Passwords do not match.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($this->error)) {
|
||||||
|
$nickname = $this->nicknameFromEmail($email);
|
||||||
|
$this->form = new ConfirmRegistrationForm($this, $nickname, $this->email, $this->code);
|
||||||
|
$this->showPage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$nickname = $this->nicknameFromEmail($email);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->user = User::register(array('nickname' => $nickname,
|
||||||
|
'email' => $email,
|
||||||
|
'password' => $this->password1,
|
||||||
|
'email_confirmed' => true));
|
||||||
|
} catch (ClientException $e) {
|
||||||
|
$this->error = $e->getMessage();
|
||||||
|
$nickname = $this->nicknameFromEmail($email);
|
||||||
|
$this->form = new ConfirmRegistrationForm($this, $nickname, $this->email, $this->code);
|
||||||
|
$this->showPage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($this->user)) {
|
||||||
|
throw new Exception('Failed to register user.');
|
||||||
|
}
|
||||||
|
|
||||||
|
common_set_user($this->user);
|
||||||
|
// this is a real login
|
||||||
|
common_real_login(true);
|
||||||
|
|
||||||
|
// Re-init language env in case it changed (not yet, but soon)
|
||||||
|
common_init_language();
|
||||||
|
|
||||||
|
if (!empty($this->invitation)) {
|
||||||
|
$inviter = User::staticGet('id', $this->invitation->user_id);
|
||||||
|
if (!empty($inviter)) {
|
||||||
|
Subscription::start($inviter->getProfile(),
|
||||||
|
$this->user->getProfile());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->invitation->delete();
|
||||||
|
} else if (!empty($this->confirmation)) {
|
||||||
|
$this->confirmation->delete();
|
||||||
|
} else {
|
||||||
|
throw new Exception('No confirmation thing.');
|
||||||
|
}
|
||||||
|
|
||||||
|
Event::handle('EndRegistrationTry', array($this));
|
||||||
}
|
}
|
||||||
|
|
||||||
common_redirect(common_local_url('doc', array('title' => 'welcome')),
|
if (Event::handle('StartRegisterSuccess', array($this))) {
|
||||||
303);
|
common_redirect(common_local_url('doc', array('title' => 'welcome')),
|
||||||
|
303);
|
||||||
|
Event::handle('EndRegisterSuccess', array($this));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendConfirmEmail($confirm)
|
function sendConfirmEmail($confirm)
|
||||||
|
Loading…
Reference in New Issue
Block a user