Exemplo n.º 1
0
 public function forgotPasswordAction()
 {
     $form = new ForgotPasswordForm();
     if ($this->request->isPost()) {
         if ($form->isValid($this->request->getPost()) == false) {
             foreach ($form->getMessages() as $message) {
                 $this->flash->error($message);
             }
         } else {
             $user = Users::findFirstByEmail($this->request->getPost('email'));
             if (!$user) {
                 $this->flash->success('There is no account associated to this email');
             } else {
                 $resetPassword = new ResetPasswords();
                 $resetPassword->usersId = $user->id;
                 if ($resetPassword->save()) {
                     $this->flash->success('Success! Please check your messages for an email reset password');
                 } else {
                     foreach ($resetPassword->getMessages() as $message) {
                         $this->flash->error($message);
                     }
                 }
             }
         }
     }
     $this->view->form = $form;
 }
Exemplo n.º 2
0
 public function check($credentials)
 {
     $user = Users::findFirstByEmail($credentials['email']);
     if ($user == false) {
         $this->registerUserThrottling(0);
         throw new Exception('Wrong email/password combination');
     }
     if (!$this->security->checkHash($credentials['password'], $user->password)) {
         $this->registerUserThrottling($user->id);
         throw new Exception('Wrong email/password combination');
     }
     //检测active, suspend, banned标志
     $this->checkUserFlags($user);
     //将成功登录的信息保存到success_login表中
     $this->saveSuccessLogin($user);
     if (isset($credentials['remember'])) {
         $this->createRememberEnviroment($user);
     }
     $this->session->set('auth-identity', array('id' => $user->id, 'name' => $user->name, 'profile' => $user->profile->name));
 }