示例#1
0
文件: Gentime.php 项目: brainexe/core
 /**
  * @param UserVO|null $user
  * @return string
  */
 protected function getUsername($user)
 {
     if ($user instanceof UserVO && !$user instanceof AnonymusUserVO) {
         /** @var UserVO $user */
         return $user->getUsername();
     } else {
         return '-anonymous-';
     }
 }
示例#2
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
     }
 }
示例#3
0
 /**
  * @param UserVO $user
  * @return int $userId
  */
 public function register(UserVO $user) : int
 {
     $redis = $this->getRedis()->pipeline();
     $userArray = ['username' => $user->getUsername(), 'password' => $this->generateHash($user->password), 'roles' => implode(',', $user->roles), 'one_time_secret' => $user->one_time_secret, 'avatar' => $user->avatar];
     $newUserId = $this->generateUniqueId('userid');
     $redis->hset(self::REDIS_USER_NAMES, mb_strtolower($user->getUsername()), $newUserId);
     $redis->hmset($this->getKey($newUserId), $userArray);
     $redis->execute();
     $user->id = $newUserId;
     return $newUserId;
 }