protected function saveAccount(Request $request)
 {
     global $app;
     $user = $app['security']->getToken()->getUser();
     $username = $request->request->get('username');
     $currentPassword = $request->request->get('current_password');
     if (empty($username) || empty($currentPassword)) {
         $this->addNotification('error', 'error.usernameOrPasswordEmpty');
         return $this->redirect('editAccount');
     }
     if ($app['security.encoder.digest']->encodePassword($currentPassword, $user->getSalt()) !== $user->getPassword()) {
         $this->addNotification('error', 'error.passwordInvalid');
         return $this->redirect('editAccount');
     }
     if ($user->getUsername() !== $username) {
         if (User::exists($username)) {
             $this->addNotification('error', 'error.usernameAlreadyUsed');
             return $this->redirect('editAccount');
         }
         $user->setUsername($username);
     }
     $newPassword = $request->request->get('new_password');
     $passwordConfirm = $request->request->get('password_confirm');
     if (!empty($newPassword) || !empty($passwordConfirm)) {
         if ($newPassword !== $passwordConfirm) {
             $this->addNotification('error', 'error.passwordsDiffer');
             return $this->redirect('editAccount');
         }
         $user->setRawPassword($newPassword);
     }
     $user->save();
     return $this->redirect('editAccount');
 }
 protected function removeUser(Request $request)
 {
     $userId = $request->request->get('userId');
     if (!empty($userId)) {
         if (User::deleteByUserId($userId)) {
             UserRole::deleteByUserId($userId);
             Sharing::deleteByUserId($userId);
             return $this->success();
         }
     }
     $this->abort(500, 'error.cannotRemoveUser');
 }
예제 #3
0
 public function loadUserByUsername($username)
 {
     if (DEBUG && $username === DEBUG_USERNAME) {
         $user = new User(0, $username, null, null, time(), time(), array('ROLE_ADMIN'));
         $user->setRawPassword(DEBUG_PASSWORD);
     } else {
         $user = User::loadByUsername($username);
     }
     if ($user === null) {
         throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
     }
     return $user;
 }