/**
  * @return false OR \nepster\users\models\User
  */
 public function recovery()
 {
     $this->_user = User::findByEmail($this->email, ['status']);
     if ($this->_user !== null) {
         $this->_user->generateSecureKey();
         if ($this->_user->save(false)) {
             return $this->_user;
         }
     }
     return false;
 }
 /**
  * Валидация пароля
  */
 public function validatePassword($attribute)
 {
     $this->_user = static::$_user;
     if (!$this->_user || !$this->_user->validatePassword($this->{$attribute})) {
         $this->addError('username', '');
         $this->addError($attribute, Yii::t('users', 'INVALID_USERNAME_OR_PASSWORD'));
     }
     if ($this->_user && !$this->_user->status) {
         $this->addError($attribute, Yii::t('users', 'MUST_ACTIVATE_ACCOUNT'));
     }
 }
 /**
  * @return false OR \nepster\users\models\User
  */
 public function resend()
 {
     $this->_user = User::findByEmail($this->email, ['status' => User::STATUS_INACTIVE]);
     if ($this->_user !== null) {
         $this->_user->generateSecureKey();
         if ($this->_user->save(false)) {
             return $this->_user;
         }
     }
     return false;
 }
 /**
  * Поиск пользователя по id.
  *
  * @return User|null User instance
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::find()->where(['id' => Yii::$app->user->identity->id])->status(User::STATUS_ACTIVE)->one();
     }
     return $this->_user;
 }
 /**
  * @return boolean
  */
 public function isValidToken()
 {
     if (Security::isValidToken($this->secure_key, $this->module->recoveryWithin) === true) {
         return ($this->_user = User::findBySecureKey($this->secure_key, ['status'])) !== null;
     }
     return false;
 }
 /**
  * @return boolean
  */
 public function activation()
 {
     $model = User::findBySecureKey($this->secure_key, ['emailVerified' => 0]);
     if ($model !== null) {
         return $model->mailVerification();
     }
     return false;
 }
示例#7
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (\nepster\users\models\User::beforeSave($insert)) {
         if (!empty($this->password)) {
             $this->setPassword($this->password);
         } else {
             $this->password = $this->getOldAttribute('password');
         }
         return true;
     }
     return true;
 }
示例#8
0
 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if ($insert) {
         // Сохраняем профиль
         $this->profile->user_id = $this->id;
         $this->profile->save(false);
         // Сохраняем данные юридического лица
         if ($this->person) {
             $this->person->user_id = $this->id;
             $this->person->save(false);
         }
     }
 }
 /**
  * Send Email
  *
  * @param $email
  * @param $view
  * @param $subject
  * @param $content
  *
  * Command: php yii users/control/send-email [email] [view] [subject] [content]
  */
 public function actionSendEmail($email, $view, $subject, $content = null)
 {
     $this->_user = User::find()->where('email = :email', [':email' => $email])->one();
     if ($this->_user) {
         $mail = Yii::$app->getMailer();
         $mail->viewPath = $this->mailViewPath;
         $send = $mail->compose($view, ['user' => $this->_user, 'content' => $content])->setFrom(Yii::$app->getMailer()->messageConfig['from'])->setTo($this->_user['email'])->setSubject($subject)->send();
         if ($send) {
             $this->stdout("SUCESS" . PHP_EOL, Console::FG_GREEN);
             Yii::getLogger()->log('SUCCESS: E-MAIL: ' . $this->_user['email'] . ', view: ' . $view, Logger::LEVEL_INFO, 'users.send');
         } else {
             $this->stdout("ERROR" . PHP_EOL, Console::FG_RED);
             Yii::getLogger()->log('ERROR: E-MAIL: ' . $this->_user['email'] . ', view: ' . $view, Logger::LEVEL_ERROR, 'users.send');
         }
     } else {
         Yii::getLogger()->log('ERROR: send fail. DATA: ' . $email . ', ' . $view . ', ' . $subject, Logger::LEVEL_ERROR, 'users.send');
     }
 }
示例#10
0
 /**
  * @return $this
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id'])->inverseOf('profile');
 }
示例#11
0
 /**
  * @return $this
  */
 public function control()
 {
     $this->andWhere([User::tableName() . '.group' => $this->module->accessGroupsToControlpanel]);
     return $this;
 }
示例#12
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }