/**
  * Check if secure key is valid.
  *
  * @return boolean true if secure key is valid
  */
 public function isValidSecureKey()
 {
     if (Security::isValidToken($this->secure_key, $this->module->recoveryWithin) === true) {
         return ($this->_user = User::findBySecureKey($this->secure_key, 'active')) !== null;
     }
     return false;
 }
Beispiel #2
0
 /**
  * Finds user by id.
  *
  * @return User|null User instance
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::find()->where(['id' => Yii::$app->user->identity->id])->active()->one();
     }
     return $this->_user;
 }
 /**
  * Send a recovery password token.
  *
  * @return boolean true if recovery token was successfully sent
  */
 public function recovery()
 {
     $this->_model = User::findByEmail($this->email, 'active');
     if ($this->_model !== null) {
         return $this->send();
     }
     return false;
 }
 /**
  * User page.
  *
  * @param string $username Username
  */
 public function actionView($username)
 {
     if (($model = User::findByUsername($username, 'active')) !== null) {
         return $this->render('view', ['model' => $model]);
     } else {
         throw new HttpException(404);
     }
 }
Beispiel #5
0
 /**
  * Finds user by username.
  *
  * @return User|null User instance
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $scope = $this->module->isBackend ? ['admin', 'active'] : 'active';
         $this->_user = User::findByUsername($this->username, $scope);
     }
     return $this->_user;
 }
Beispiel #6
0
 /**
  * Finds user by username.
  *
  * @return User|null User instance
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $scope = $this->scenario === 'admin' ? ['admin', 'active'] : 'active';
         $this->_user = User::findByUsername($this->username, $scope);
     }
     return $this->_user;
 }
Beispiel #7
0
 /**
  * Activates user account.
  *
  * @return boolean true if account was successfully activated
  */
 public function activation()
 {
     $model = User::findByToken($this->token, 'inactive');
     if ($model !== null) {
         return $model->activation();
     }
     return false;
 }
 /**
  * Activates user account.
  *
  * @return boolean true if account was successfully activated
  */
 public function activation()
 {
     /** @var User $model */
     $model = User::findBySecureKey($this->secure_key, 'inactive');
     if ($model !== null) {
         return $model->activation();
     }
     return false;
 }
 /**
  * Send a recovery password token.
  *
  * @return boolean true if recovery token was successfully sent
  */
 public function recovery()
 {
     $this->_model = User::findByEmail($this->email, 'active');
     if ($this->_model !== null) {
         $this->_model->token = Security::generateExpiringRandomString();
         $this->_model->save();
         return $this->send();
     }
     return false;
 }
Beispiel #10
0
 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if ($insert) {
         if ($this->profile !== null) {
             $this->profile->save(false);
         }
         if ($this->module->requireEmailConfirmation === true) {
             $this->send();
         }
     }
 }
Beispiel #11
0
 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if ($insert) {
         if ($this->profile !== null) {
             $this->profile->save(false);
         }
         $auth = Yii::$app->authManager;
         $role = $auth->getRole(self::ROLE_DEFAULT);
         $auth->assign($role, $this->id);
         if ($this->module->requireEmailConfirmation === true) {
             $this->send();
         }
     }
 }
Beispiel #12
0
 /**
  * Finds user by username.
  *
  * @return User|boolean User instance
  */
 protected function getUser()
 {
     if ($this->_user === false) {
         $user = User::findByUsername($this->username, 'active');
         if ($user !== null) {
             if ($this->module->isBackend) {
                 if (Yii::$app->authManager->checkAccess($user->id, 'accessBackend')) {
                     $this->_user = $user;
                 }
             } else {
                 $this->_user = $user;
             }
         }
     }
     return $this->_user;
 }
Beispiel #13
0
 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if ($this->profile !== null) {
         $this->profile->save(false);
     }
     $auth = Yii::$app->authManager;
     $name = $this->role ? $this->role : self::ROLE_DEFAULT;
     $role = $auth->getRole($name);
     if (!$insert) {
         $auth->revokeAll($this->id);
     }
     $auth->assign($role, $this->id);
 }
Beispiel #14
0
 /**
  * @return Profile|null Profile user
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id'])->inverseOf('profile');
 }
Beispiel #15
0
 /**
  * @return vova07\users\models\User|null Related user
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }
Beispiel #16
0
 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if ($this->profile !== null) {
         $this->profile->save(false);
     }
 }