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