Пример #1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     // logout users don't have special permission
     if (!$this->isGuest && !$this->hasPermission('navigate:backend')) {
         $this->logout();
     }
 }
Пример #2
0
 /**
  * Finds user by username
  *
  * @param string $username
  * @return static|null
  */
 public static function findByUsername($username)
 {
     $user = self::find()->with('person')->where(['username' => $username, 'status' => self::STATUS_ENABLED])->one();
     if ($user === null) {
         return null;
     }
     $userData = ['id' => $user->id, 'password' => $user->password, 'username' => $user->username, 'email' => $user->person->email, 'first_name' => $user->person->first_name, 'last_name' => $user->person->last_name, 'auth_key' => $user->auth_key, 'language' => $user->person->default_language];
     // save user data
     Yii::$app->commonCache->set(self::getCacheKey($user->id), $userData, self::$cacheDuration, new TagDependency(['tags' => [UserComponent::getCacheTag(), UserComponent::getCacheTag($user->id)]]));
     return new self($userData);
 }