Inheritance: extends yii\db\ActiveRecord
 /**
  * Signs user up.
  *
  * @return User|false the saved model or false if saving fails
  */
 public function signup($runValidation = true)
 {
     if ($runValidation && !$this->validate()) {
         return false;
     }
     $user = new User();
     $user->mobile = $this->_session['mobileSignup'];
     $user->setPassword($this->_session['mobileSignupPassword']);
     $user->generateAuthKey();
     $user->generateAccessToken();
     $transaction = Yii::$app->db->beginTransaction();
     try {
         if (!$user->save(false)) {
             throw new \Exception();
         }
         $userAccount = new UserAccount();
         $userAccount->id = $user->id;
         $userAccount->password_hash = null;
         if (!$userAccount->save(false)) {
             throw new \Exception();
         }
         $transaction->commit();
         return $user;
     } catch (\Exception $e) {
         $transaction->rollBack();
         return false;
     }
 }
Ejemplo n.º 2
0
 /**
  * Finds user by [[accountName]]
  *
  * @return UserAccount|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = UserAccount::find()->byName($this->accountName)->active()->one();
     }
     return $this->_user;
 }
Ejemplo n.º 3
0
 /**
  * Creates a form model given a token.
  *
  * @param string $token
  * @param array $config name-value pairs that will be used to initialize the object properties
  * @throws \yii\base\InvalidParamException if token is empty or not valid
  */
 public function __construct($token, $config = [])
 {
     if (empty($token) || !is_string($token)) {
         throw new InvalidParamException('Password reset token cannot be blank.');
     }
     $this->_user = UserAccount::findByPasswordResetToken($token);
     if (!$this->_user) {
         throw new InvalidParamException('Wrong password reset token.');
     }
     parent::__construct($config);
 }
 public function testSendEmailSuccessfully()
 {
     $userFixture = $this->tester->grabFixture('userAccount', 0);
     $model = new PasswordResetRequestForm();
     $model->email = $userFixture['email'];
     $user = UserAccount::findOne(['password_reset_token' => $userFixture['password_reset_token']]);
     expect_that($model->sendEmail());
     expect_that($user->password_reset_token);
     $emailMessage = $this->tester->grabLastSentEmail();
     expect('valid email is sent', $emailMessage)->isInstanceOf('yii\\mail\\MessageInterface');
     expect($emailMessage->getTo())->hasKey($model->email);
     expect($emailMessage->getFrom())->hasKey(Yii::$app->params['supportEmail']);
 }
 /**
  * Sends an email with a link, for resetting the password.
  *
  * @return bool whether the email was send
  */
 public function sendEmail()
 {
     /* @var $user UserAccount */
     $user = UserAccount::findOne(['status' => UserAccount::STATUS_ACTIVE, 'email' => $this->email]);
     if (!$user) {
         return false;
     }
     if (!UserAccount::isPasswordResetTokenValid($user->password_reset_token)) {
         $user->generatePasswordResetToken();
     }
     if (!$user->save()) {
         return false;
     }
     return Yii::$app->mailer->compose(['html' => 'password-reset-token-html', 'text' => 'password-reset-token-text'], ['user' => $user])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . Yii::$app->name)->send();
 }
Ejemplo n.º 6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getOwner()
 {
     return $this->hasOne(UserAccount::className(), ['id' => 'owner_id']);
 }
 public function process()
 {
     $this->user->setPassword($this->password);
     $this->user->tryUpdate(false);
 }