Example #1
0
 /**
  * Update users profile(password)
  *
  * @return \Framework\Response\Response|\Framework\Response\ResponseRedirect
  * @throws SecurityException
  */
 public function updateAction()
 {
     $route = Service::get('route');
     if (Service::get('security')->isAuthenticated()) {
         if ($this->getRequest()->isPost()) {
             $user = Service::get('session')->get('user');
             if ($user->password == $this->getRequest()->post('password') && $this->getRequest()->post('newpassword1') == $this->getRequest()->post('newpassword2')) {
                 try {
                     $us = new User();
                     $us->email = $user->email;
                     $us->password = md5($this->getRequest()->post('newpassword1'));
                     $us->role = $user->role;
                     $us->update('email', $user->email);
                     return $this->redirect($this->generateRoute('profile'), 'The password update successfully');
                 } catch (DatabaseException $e) {
                     $errors = array($e->getMessage());
                 }
             } else {
                 return $this->redirect($this->getRequest()->getUri(), 'Password mismatch', 'error');
             }
         } else {
             return $this->getAction();
         }
     } else {
         throw new SecurityException('Please, login', $route->buildRoute('login'));
     }
     return $this->render('updateprofile.html', array('errors' => $errors));
 }