예제 #1
0
 /**
  * @return bool
  */
 public function changePassword()
 {
     if (!$this->validate()) {
         return false;
     }
     $user = User::findIdentity(\Yii::$app->user->identity->getId());
     $user->password_hash = User::hashPassword($this->new_password);
     $user->save();
     return true;
 }
예제 #2
0
 /**
  * @return bool
  */
 public function generatePasswordResetToken()
 {
     if (!$this->validate()) {
         return false;
     }
     $new_password = \Yii::$app->security->generateRandomString(8);
     /** @var User $user */
     $user = User::findOne(['email' => $this->email]);
     $user->password_reset_token = User::generatePasswordResetToken();
     $user->password_hash = User::hashPassword($new_password);
     $user->status = User::USER_STATUS_INACTIVE;
     $user->save();
     $isSend = \Yii::$app->mailer->compose('user/forgot_password', ['user_name' => $user->name, 'token' => $user->password_reset_token, 'new_password' => $new_password])->setFrom(Settings::value('general', 'shopEmail'))->setTo($this->email)->setSubject(\Yii::t('mail', 'New password activation'))->send();
     if (!$isSend) {
         $this->addError(\Yii::t('mail', 'Oops, can\'t deliver letter to such email address.'));
     }
     return $isSend;
 }
예제 #3
0
 /**
  * @throws \yii\base\Exception
  * @throws \yii\base\InvalidConfigException
  */
 public function register()
 {
     if (!$this->validate()) {
         return false;
     }
     $user = new User();
     $user->email = $this->email;
     $user->name = $this->name;
     $user->country_id = $this->country_id;
     $user->phone = $this->phone;
     $user->address = $this->address;
     $user->password_hash = User::hashPassword($this->password);
     $user->generateAuthKey();
     $user->status = User::USER_STATUS_ACTIVE;
     $user->save();
     return User::login($this->email, true);
 }