コード例 #1
0
 /**
  * Check if token is valid.
  *
  * @return boolean true if token is valid
  */
 public function isValidToken()
 {
     if (SecurityHelper::isValidToken($this->token, Module::param('emailWithin', 14400)) === true) {
         return ($this->_model = static::findOne(['token' => $this->token])) !== null;
     }
     return false;
 }
コード例 #2
0
 /**
  * Sign Up page.
  * If record will be successful created, user will be redirected to home page.
  */
 public function run()
 {
     $user = Yii::createObject($this->modelClass, ['scenario' => 'signup']);
     $profile = Yii::createObject($this->profileClass);
     $post = Yii::$app->request->post();
     if ($user->load($post) && $profile->load($post)) {
         if ($user->validate() && $profile->validate()) {
             $user->populateRelation('profile', $profile);
             if ($user->save(false)) {
                 if (Module::param('requireEmailConfirmation', false)) {
                     $this->trigger('success', new Event(['data' => Module::t('model', 'Your account has been created successfully. An email has been sent to you with detailed instructions.', ['url' => Url::to($this->resendRoute)])]));
                 } else {
                     Yii::$app->user->login($user);
                     $this->trigger('success', new Event(['data' => Module::t('model', 'Your account has been created successfully.')]));
                 }
                 return $this->controller->goHome();
             } else {
                 $this->trigger('danger', new Event(['data' => Module::t('model', 'Create account failed. Please try again later.')]));
                 return $this->controller->refresh();
             }
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return array_merge(ActiveForm::validate($user), ActiveForm::validate($profile));
         }
     }
     return $this->render(compact('user', 'profile'));
 }
コード例 #3
0
 /**
  * Check if token is valid.
  *
  * @return boolean true if token is valid
  */
 public function isValidToken()
 {
     if (SecurityHelper::isValidToken($this->token, Module::param('recoveryWithin', false)) === true) {
         return ($this->_user = User::findByToken($this->token, 'active')) !== null;
     }
     return false;
 }
コード例 #4
0
ファイル: Module.php プロジェクト: artkost/yii2-starter-kit
 public static function sendSignUpEmail(Model $model)
 {
     if (Module::param('requireEmailConfirmation', false)) {
         return self::getInstance()->getMail()->compose('signup', ['model' => $model])->setTo($model->email)->setSubject(Module::t('mail', 'EMAIL_SUBJECT_SIGNUP') . ' ' . Yii::$app->name)->send();
     }
     return false;
 }
コード例 #5
0
ファイル: UserBase.php プロジェクト: artkost/yii2-starter-kit
 /**
  * @param int $status
  * @return $this
  */
 public function setDefaultStatus($status = self::STATUS_ACTIVE)
 {
     if (Module::param('requireEmailConfirmation', false)) {
         $status = self::STATUS_INACTIVE;
     }
     // Set default status
     if (!$this->status_id) {
         $this->status_id = $status;
     }
     return $this;
 }