/**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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);
     }
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Exemple #7
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();
         }
     }
 }
Exemple #8
0
 /**
  * @return User|null Related user
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }
Exemple #9
0
 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if ($this->profile !== null) {
         $this->profile->save(false);
     }
 }