function setPassword()
{
- if (Event::handle('StartRegistrationTry', array($this))) {
- if (!empty($this->invitation)) {
- $email = $this->invitation->address;
- } else if (!empty($this->confirmation)) {
- $email = $this->confirmation->address;
- } else {
- // TRANS: Exception.
- throw new Exception('No confirmation thing.');
- }
-
- if (!$this->tos) {
- // TRANS: Error text when trying to register without accepting TOS and privacy policy.
- $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) {
- $this->error = _m('Passwords do not match.');
- }
+ if (!empty($this->invitation)) {
+ $email = $this->invitation->address;
+ } else if (!empty($this->confirmation)) {
+ $email = $this->confirmation->address;
+ } else {
+ throw new Exception('No confirmation thing.');
+ }
- if (!empty($this->error)) {
- $nickname = $this->nicknameFromEmail($email);
- $this->form = new ConfirmRegistrationForm($this, $nickname, $this->email, $this->code);
- $this->showPage();
- return;
- }
+ if (!$this->tos) {
+ $this->error = _('You must accept the terms of service and privacy policy to register.');
+ return;
+ } else if (empty($this->password1)) {
+ $this->error = _('You must set a password');
+ } else if (strlen($this->password1) < 6) {
+ $this->error = _('Password must be 6 or more characters.');
+ } else if ($this->password1 != $this->password2) {
+ $this->error = _('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)) {
- // TRANS: Exception thrown when user registration fails.
- throw new Exception('Failed to register user.');
- }
-
- common_set_user($this->user);
- // this is a real login
- common_real_login(true);
+ if (empty($this->user)) {
+ throw new Exception("Failed to register user.");
+ }
- // Re-init language env in case it changed (not yet, but soon)
- common_init_language();
+ common_set_user($this->user);
+ // this is a real login
+ common_real_login(true);
- if (!empty($this->invitation)) {
- $inviter = User::staticGet('id', $this->invitation->user_id);
- if (!empty($inviter)) {
- Subscription::start($inviter->getProfile(),
- $this->user->getProfile());
- }
+ // Re-init language env in case it changed (not yet, but soon)
+ common_init_language();
- $this->invitation->delete();
- } else if (!empty($this->confirmation)) {
- $this->confirmation->delete();
- } else {
- // TRANS: Exception.
- throw new Exception('No confirmation thing.');
+ if (!empty($this->invitation)) {
+ $inviter = User::staticGet('id', $this->invitation->user_id);
+ if (!empty($inviter)) {
+ Subscription::start($inviter->getProfile(),
+ $this->user->getProfile());
}
- Event::handle('EndRegistrationTry', array($this));
+ $this->invitation->delete();
+ } else if (!empty($this->confirmation)) {
+ $this->confirmation->delete();
+ } else {
+ throw new Exception('No confirmation thing.');
}
common_redirect(common_local_url('doc', array('title' => 'welcome')),