Esempio n. 1
0
 /**
  * Attempts to find the member and send them an email
  *
  * @return bool
  */
 public function sendEmail()
 {
     $member = Member::find()->where(['email' => ['like', 'email', $this->email]])->limit(1)->one();
     /* @var $member \yii\db\ActiveRecord */
     if ($member) {
         if ($member->isActive) {
             // Create a new Password Reset Key
             $member->passwordResetKey = Util::getRandomString(32);
             $member->save();
             $encrypted = JWT::encode(['i' => $member->id, 'k' => $member->passwordResetKey], Yii::$app->params['secret']);
             // Send email
             return Yii::$app->mailer->compose(['html' => 'password-reset/html', 'text' => 'password-reset/text'], ['encrypted' => $encrypted, 'member' => $member])->setFrom(Yii::$app->params['fromEmail'])->setTo($this->email)->setSubject('Password Reset - ' . Yii::$app->params['siteName'])->send();
         } else {
             $this->addError('email', 'You account is not active.');
         }
     } else {
         $this->addError('email', 'Could not find you!');
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Attempts to find the member and send them an email
  *
  * @return bool
  */
 public function register()
 {
     $member = Member::find()->where(['email' => ['like', 'email', $this->email]])->limit(1)->one();
     if (!$member) {
         // Create a new member
         $member = new Member();
         $member->email = $this->email;
         $member->name = $this->name;
         $member->isActive = 0;
         $member->passwordResetKey = Util::getRandomString(32);
         $member->setRawPassword($this->password);
         $member->save();
         $encrypted = JWT::encode(['i' => $member->id, 'k' => $member->passwordResetKey], Yii::$app->params['secret']);
         // Send email
         return Yii::$app->mailer->compose(['html' => 'register/html', 'text' => 'register/text'], ['encrypted' => $encrypted, 'member' => $member])->setFrom(Yii::$app->params['fromEmail'])->setTo($this->email)->setSubject('Registration Confirmation - ' . Yii::$app->params['siteName'])->send();
     } else {
         $this->addError('email', 'An account already exists for ' . $this->email);
     }
     return false;
 }