Пример #1
0
 /**
  * @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
     }
 }
Пример #2
0
 /**
  * @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'));
     }
 }