Пример #1
0
 public function resetPassword()
 {
     if ($this->request()->isPost()) {
         $user = User::find_by_name($this->params()->user['name']);
         if ($user) {
             $new_password = $user->reset_password();
             $this->notice('Password reset to ' . $new_password);
             if ($user->email) {
                 // try {
                 UserMailer::mail('new_password', [$user, $new_password])->deliver();
                 // } catch (\Exception $e) {
                 // $this->respond_to_success("Specified user's email address was invalid",
                 // ['#reset_password'], ['api' => ['result' => 'invalid-email']]);
                 // return;
                 // }
             }
         } else {
             $this->notice('That account does not exist');
             $this->redirectTo('#reset_password');
         }
     } else {
         $this->user = new User();
     }
 }
Пример #2
0
 public function resetPassword()
 {
     $this->set_title('Reset Password');
     if ($this->request()->isPost()) {
         $this->user = User::where(['name' => $this->params()->user['name']])->first();
         if (!$this->user) {
             $this->respond_to_error("That account does not exist", '#reset_password', ['api' => ['result' => "unknown-user"]]);
             return;
         }
         if (!$this->user->email) {
             $this->respond_to_error("You never supplied an email address, therefore you cannot have your password automatically reset", '#login', ['api' => ['result' => "no-email"]]);
             return;
         }
         if ($this->user->email != $this->params()->user['email']) {
             $this->respond_to_error("That is not the email address you supplied", '#login', ['api' => ['result' => "wrong-email"]]);
             return;
         }
         # iTODO:
         try {
             // User.transaction do
             # If the email is invalid, abort the password reset
             $new_password = $this->user->reset_password();
             UserMailer::mail('new_password', [$this->user, $new_password])->deliver();
             $this->respond_to_success("Password reset. Check your email in a few minutes.", '#login', ['api' => ['result' => "success"]]);
             return;
             // end
         } catch (Exception $e) {
             // rescue Net::SMTPSyntaxError, Net::SMTPFatalError
             $this->respond_to_success("Your email address was invalid", '#login', ['api' => ['result' => "invalid-email"]]);
             return;
         }
     } else {
         $this->user = new User();
         if ($this->params()->format and $this->params()->format != 'html') {
             $this->redirectTo('root');
         }
     }
 }