/** * @param Request $request * @return bool * @throws UserException * @Route("/user/change_password/", name="user.change_password", methods="POST") */ public function changePassword(Request $request) : bool { $oldPassword = $request->request->get('oldPassword'); $newPassword = $request->request->get('newPassword'); /** @var UserVO $user */ $user = $request->attributes->get('user'); if (!$this->passwordHasher->verifyHash($oldPassword, $user->getPassword())) { throw new UserException('Invalid Password given'); } $this->user->changePassword($user, $newPassword); return true; }
/** * @param UserVO $user * @throws UserException */ protected function checkInput(UserVO $user) { if (mb_strlen($user->username) <= 1) { throw new UserException('Username must not be empty'); } if (mb_strlen($user->password) <= 1) { throw new UserException('Password must not be empty'); } try { $this->userProvider->loadUserByUsername($user->getUsername()); throw new UserException(sprintf('User %s already exists', $user->getUsername())); } catch (UserNotFoundException $e) { // all fine } }
/** * @param string $userName * @throws UserException */ public function sendCodeViaMail($userName) { try { $user = $this->userProvider->loadUserByUsername($userName); if (empty($user->email)) { throw new UserException(_('No email address defined for this user')); } $code = $this->totp->current($user->one_time_secret); $event = new SendMailEvent($user->email, $code, $code); $this->dispatchEvent($event); } catch (UsernameNotFoundException $e) { throw new UserException(_('Invalid username')); } }
/** * Receives a list of all registered user names. indexed by user-id * * @return string[] * @Route("/user/list/", name="authenticate.list_user", methods="GET", options={"cache":30}) */ public function getList() : array { return array_flip($this->userProvider->getAllUserNames()); }