Exemplo n.º 1
0
 public function changePasswordAction()
 {
     $confirmCurrent = $this->dispatcher->wasForwarded() ? false : true;
     $user = User::findFirst($this->session->get('id'));
     if ($user) {
         /* for this specific form we can pass boolean value as first parameter
            to signify whether the user must confirm the current password */
         $form = new \Adiachenko\Project\Form\changePasswordForm($user, ['confirmCurrent' => $confirmCurrent]);
         if ($this->request->isPost()) {
             if ($form->isValid($this->request->getPost())) {
                 if (password_verify($this->request->getPost('current-password'), $user->passwordHash)) {
                     if ($this->request->getPost('current-password') !== $this->request->getPost('password')) {
                         $user->passwordHash = password_hash($this->request->getPost('password'), PASSWORD_BCRYPT);
                         if ($user->save()) {
                             $this->flash->notice('Your password was changed.');
                         }
                         return $this->response->redirect('index');
                     } else {
                         $form->addModelError('password', 'New password must differ from the current one');
                     }
                 } else {
                     $form->addModelError('current-password', 'Failed to confirm your current password');
                 }
             }
         }
     }
     $this->view->form = $form;
 }
Exemplo n.º 2
0
 public function signInUsingSessionHash($hash)
 {
     $session = UserSession::findFirstByHash($hash);
     if ($session) {
         $user = User::findFirst($session->userId);
         $this->signIn($user, false, false);
     }
 }
Exemplo n.º 3
0
 public function sendActivationLinkAction($id)
 {
     $user = User::findFirst($id);
     $this->activation->request($user);
     return $this->response->redirect('index');
 }