예제 #1
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $user = common_current_user();
     if (!empty($user)) {
         // TRANS: Client exception thrown when trying to register while already logged in.
         throw new ClientException(_m('You are already logged in.'));
     }
     $this->code = $this->trimmed('code');
     $this->confirm = Confirm_address::getKV('code', $this->code);
     if (empty($this->confirm)) {
         // TRANS: Client exception thrown when trying to register with a non-existing confirmation code.
         throw new ClientException(_m('Confirmation code not found.'));
         return;
     }
     $this->user = User::getKV('id', $this->confirm->user_id);
     if (empty($this->user)) {
         // TRANS: Client exception thrown when trying to register with a confirmation code that is not connected with a user.
         throw new ServerException(_m('No user for that confirmation code.'));
     }
     $type = $this->confirm->address_type;
     if ($type != 'email') {
         // TRANS: Client exception thrown when trying to register with a invalid e-mail address.
         // TRANS: %s is the invalid e-mail address.
         throw new ServerException(sprintf(_m('Unrecognized address type %s.'), $type));
     }
     if (!empty($this->user->email) && $this->user->email == $confirm->address) {
         // TRANS: Client error for an already confirmed email/jabber/sms address.
         throw new ClientException(_m('That address has already been confirmed.'));
     }
     if ($this->isPost()) {
         $this->checkSessionToken();
         $password = $this->trimmed('password');
         $confirm = $this->trimmed('confirm');
         if (strlen($password) < 6) {
             // TRANS: Client exception thrown when trying to register with too short a password.
             throw new ClientException(_m('Password too short.'));
             return;
         } else {
             if (0 != strcmp($password, $confirm)) {
                 // TRANS: Client exception thrown when trying to register without providing the same password twice.
                 throw new ClientException(_m('Passwords do not match.'));
                 return;
             }
         }
         $this->password = $password;
     }
     return true;
 }
예제 #2
0
 function checkCode()
 {
     $code = $this->trimmed('code');
     $confirm = Confirm_address::getKV('code', $code);
     if (!$confirm) {
         // TRANS: Client error displayed when password recovery code is not correct.
         $this->clientError(_('No such recovery code.'));
     }
     if ($confirm->address_type != 'recover') {
         // TRANS: Client error displayed when no proper password recovery code was submitted.
         $this->clientError(_('Not a recovery code.'));
     }
     $user = User::getKV($confirm->user_id);
     if (!$user) {
         // TRANS: Server error displayed trying to recover password without providing a user.
         $this->serverError(_('Recovery code for unknown user.'));
     }
     $touched = strtotime($confirm->modified);
     $email = $confirm->address;
     // Burn this code
     $result = $confirm->delete();
     if (!$result) {
         common_log_db_error($confirm, 'DELETE', __FILE__);
         // TRANS: Server error displayed removing a password recovery code from the database.
         $this->serverError(_('Error with confirmation code.'));
     }
     // These should be reaped, but for now we just check mod time
     // Note: it's still deleted; let's avoid a second attempt!
     if (time() - $touched > MAX_RECOVERY_TIME) {
         common_log(LOG_WARNING, 'Attempted redemption on recovery code ' . 'that is ' . $touched . ' seconds old. ');
         // TRANS: Client error displayed trying to recover password with too old a recovery code.
         $this->clientError(_('This confirmation code is too old. ' . 'Please start again.'));
     }
     // If we used an outstanding confirmation to send the email,
     // it's been confirmed at this point.
     if (!$user->email) {
         $orig = clone $user;
         $user->email = $email;
         // Throws exception on failure.
         $user->updateWithKeys($orig);
     }
     // Success!
     $this->setTempUser($user);
     $this->showPasswordForm();
 }
예제 #3
0
 function prepare($argarray)
 {
     parent::prepare($argarray);
     if (common_config('site', 'closed')) {
         // TRANS: Client exception trown when registration by e-mail is not allowed.
         throw new ClientException(_m('Registration not allowed.'), 403);
     }
     if ($this->isPost()) {
         $this->checkSessionToken();
         $this->email = $this->trimmed('email');
         if (!empty($this->email)) {
             if (common_config('site', 'inviteonly')) {
                 // TRANS: Client exception trown when trying to register without an invitation.
                 throw new ClientException(_m('Sorry, only invited people can register.'), 403);
             }
             $this->email = common_canonical_email($this->email);
             $this->state = self::NEWEMAIL;
         } else {
             $this->state = self::SETPASSWORD;
             $this->code = $this->trimmed('code');
             if (empty($this->code)) {
                 // TRANS: Client exception thrown when no confirmation code was provided.
                 throw new ClientException(_m('No confirmation code.'));
             }
             $this->invitation = Invitation::getKV('code', $this->code);
             if (!empty($this->invitation)) {
                 if (!empty($this->invitation->registered_user_id)) {
                     // TRANS: Client exception trown when using an invitation multiple times.
                     throw new ClientException(_m('Invitation already used.'), 403);
                 }
             } else {
                 $this->confirmation = Confirm_address::getKV('code', $this->code);
                 if (empty($this->confirmation)) {
                     // TRANS: Client exception thrown when given confirmation code was not issued.
                     throw new ClientException(_m('No such confirmation code.'), 403);
                 }
             }
             $this->nickname = Nickname::normalize($this->trimmed('nickname'));
             $this->password1 = $this->trimmed('password1');
             $this->password2 = $this->trimmed('password2');
             $this->tos = $this->boolean('tos');
         }
     } else {
         // GET
         $this->code = $this->trimmed('code');
         if (empty($this->code)) {
             if (common_config('site', 'inviteonly')) {
                 // TRANS: Client exception trown when trying to register without an invitation.
                 throw new ClientException(_m('Sorry, only invited people can register.'), 403);
             }
             $this->state = self::NEWREGISTER;
         } else {
             $this->invitation = Invitation::getKV('code', $this->code);
             if (!empty($this->invitation)) {
                 if (!empty($this->invitation->registered_user_id)) {
                     // TRANS: Client exception trown when using an invitation multiple times.
                     throw new ClientException(_m('Invitation already used.'), 403);
                 }
                 $this->state = self::CONFIRMINVITE;
             } else {
                 $this->state = self::CONFIRMREGISTER;
                 $this->confirmation = Confirm_address::getKV('code', $this->code);
                 if (empty($this->confirmation)) {
                     // TRANS: Client exception thrown when given confirmation code was not issued.
                     throw new ClientException(_m('No such confirmation code.'), 405);
                 }
             }
         }
     }
     return true;
 }
예제 #4
0
 /**
  * Accept a confirmation code
  *
  * Checks the code and confirms the address in the
  * user record
  *
  * @param args $args $_REQUEST array
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (!common_logged_in()) {
         common_set_returnto($this->selfUrl());
         common_redirect(common_local_url('login'));
     }
     $code = $this->trimmed('code');
     if (!$code) {
         // TRANS: Client error displayed when not providing a confirmation code in the contact address confirmation action.
         $this->clientError(_('No confirmation code.'));
     }
     $confirm = Confirm_address::getKV('code', $code);
     if (!$confirm) {
         // TRANS: Client error displayed when providing a non-existing confirmation code in the contact address confirmation action.
         $this->clientError(_('Confirmation code not found.'));
     }
     $cur = common_current_user();
     if ($cur->id != $confirm->user_id) {
         // TRANS: Client error displayed when not providing a confirmation code for another user in the contact address confirmation action.
         $this->clientError(_('That confirmation code is not for you!'));
     }
     $type = $confirm->address_type;
     $transports = array();
     Event::handle('GetImTransports', array(&$transports));
     if (!in_array($type, array('email', 'sms')) && !in_array($type, array_keys($transports))) {
         // TRANS: Server error for an unknown address type, which can be 'email', 'sms', or the name of an IM network (such as 'xmpp' or 'aim')
         $this->serverError(sprintf(_('Unrecognized address type %s'), $type));
     }
     $this->address = $confirm->address;
     $cur->query('BEGIN');
     if (in_array($type, array('email', 'sms'))) {
         if ($cur->{$type} == $confirm->address) {
             // TRANS: Client error for an already confirmed email/jabber/sms address.
             $this->clientError(_('That address has already been confirmed.'));
         }
         $orig_user = clone $cur;
         $cur->{$type} = $confirm->address;
         if ($type == 'sms') {
             $cur->carrier = $confirm->address_extra + 0;
             $carrier = Sms_carrier::getKV($cur->carrier);
             $cur->smsemail = $carrier->toEmailAddress($cur->sms);
         }
         // Throws exception on failure.
         $cur->updateWithKeys($orig_user);
         if ($type == 'email') {
             $cur->emailChanged();
         }
     } else {
         $user_im_prefs = new User_im_prefs();
         $user_im_prefs->transport = $confirm->address_type;
         $user_im_prefs->user_id = $cur->id;
         if ($user_im_prefs->find() && $user_im_prefs->fetch()) {
             if ($user_im_prefs->screenname == $confirm->address) {
                 // TRANS: Client error for an already confirmed IM address.
                 $this->clientError(_('That address has already been confirmed.'));
             }
             $user_im_prefs->screenname = $confirm->address;
             $result = $user_im_prefs->update();
             if (!$result) {
                 common_log_db_error($user_im_prefs, 'UPDATE', __FILE__);
                 // TRANS: Server error displayed when updating IM preferences fails.
                 $this->serverError(_('Could not update user IM preferences.'));
             }
         } else {
             $user_im_prefs = new User_im_prefs();
             $user_im_prefs->screenname = $confirm->address;
             $user_im_prefs->transport = $confirm->address_type;
             $user_im_prefs->user_id = $cur->id;
             $result = $user_im_prefs->insert();
             if (!$result) {
                 common_log_db_error($user_im_prefs, 'INSERT', __FILE__);
                 // TRANS: Server error displayed when adding IM preferences fails.
                 $this->serverError(_('Could not insert user IM preferences.'));
             }
         }
     }
     $result = $confirm->delete();
     if (!$result) {
         common_log_db_error($confirm, 'DELETE', __FILE__);
         // TRANS: Server error displayed when an address confirmation code deletion from the
         // TRANS: database fails in the contact address confirmation action.
         $this->serverError(_('Could not delete address confirmation.'));
     }
     $cur->query('COMMIT');
     $this->showPage();
 }