/** * Регистрация на сайте * * @return bool|RegistrationForm */ public function actionRegistration() { $model = new RegistrationForm(); if ($model->load(\Yii::$app->request->post(), '') && $model->registration()) { Yii::$app->getSession()->setFlash('success', Module::t('registration', 'MESSAGE_CONFIRM_EMAIL')); return true; } else { return $model; } }
/** * Validates the username and password. * This method serves as the inline validation for password. */ public function validatePassword() { if (!$this->hasErrors()) { $user = $this->getUser(); if (!$user || !$user->validatePassword($this->password)) { $this->addError('password', Module::t('login', 'ERROR_WRONG_USERNAME_OR_PASSWORD')); } elseif ($user && $user->status == User::STATUS_BLOCKED) { $this->addError('username', Module::t('login', 'ERROR_PROFILE_BLOCKED')); } elseif ($user && $user->status == User::STATUS_WAIT) { $this->addError('username', Module::t('login', 'ERROR_PROFILE_NOT_CONFIRMED')); } } }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { /* @var $user User */ $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { if (!User::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } if ($user->save()) { return \Yii::$app->mailer->compose('user/passwordResetToken', ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => Yii::$app->name . ' robot'])->setTo($this->email)->setSubject(Module::t('password', 'SUBJECT_RESET_PASSWORD {APP_NAME}', ['APP_NAME' => Yii::$app->name]))->send(); } } return false; }
/** * Registration * * @return User|null the saved model or null if saving fails */ public function registration() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->status = User::STATUS_WAIT; $user->generateAuthKey(); $user->generateEmailConfirmToken(); if ($user->save()) { Yii::$app->mailer->compose('user/confirmEmail', ['user' => $user])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name])->setTo($this->email)->setSubject(Module::t('registration', 'EMAIL_CONFIRMATION_SUBJECT_FOR {APP_NAME}', ['APP_NAME' => Yii::$app->name]))->send(); } return $user; } return null; }
<?php use frontend\modules\user\Module; use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $user common\models\User */ $confirmLink = Yii::$app->urlManager->createAbsoluteUrl(['user/default/confirm-email', 'token' => $user->email_confirm_token]); $this->title = Module::t('signup', 'EMAIL_CONFIRMATION_SUBJECT_FOR {APP_NAME}', ['APP_NAME' => Yii::$app->name]); ?> <div class="confirm-email"> <h3><?php echo Module::t('main', 'HELLO {username}', ['username' => Html::encode($user->username)]); ?> </h3> <h3><?php echo Module::t('signup', 'FOLLOW_TO_CONFIRM_EMAIL'); ?> </h3> <p><?php echo Html::a(Html::encode($confirmLink), $confirmLink); ?> </p> <p><?php echo Module::t('signup', 'IGNORE_IF_DO_NOT_REGISTER'); ?> </p> </div>
/** * Reset password * * @param string $token * @return string|\yii\web\Response * @throws BadRequestHttpException */ public function actionResetPassword($token) { try { $model = new PasswordResetForm($token); } catch (InvalidParamException $e) { throw new BadRequestHttpException($e->getMessage()); } if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) { Yii::$app->getSession()->setFlash('success', Module::t('password', 'MESSAGE_SUCCESS_RESET_PASSWORD')); return $this->goHome(); } return $this->render('resetPassword', ['model' => $model]); }
/** * @inheritdoc */ public function attributeLabels() { return ['password' => Module::t('password', 'USER_NEW_PASSWORD')]; }
<div> <?php echo Html::activePasswordInput($model, 'password', ['class' => 'form-control', 'ng-model' => 'model.password']); ?> <error field="password"></error> </div> </div> <div class="form-group required"> <?php echo Html::activeLabel($model, 'verifyPassword', ['class' => 'control-label']); ?> <div> <?php echo Html::activePasswordInput($model, 'verifyPassword', ['class' => 'form-control', 'ng-model' => 'model.verifyPassword']); ?> <error field="verifyPassword"></error> </div> </div> <div class="form-group"> <?php echo Html::submitButton(Module::t('registration', 'USER_BUTTON_REGISTRATION'), ['class' => 'btn btn-primary', 'ladda' => 'loading', 'ng-click' => 'registration()']); ?> </div> <?php echo Html::endForm(); ?> </div> </div> </div>
use yii\helpers\Html; use yii\bootstrap\ActiveForm; /* @var $this yii\web\View */ /* @var $form yii\bootstrap\ActiveForm */ /* @var $model frontend\modules\user\models\PasswordResetRequestForm */ $this->title = Module::t('password', 'TITLE_RESET_PASSWORD'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="user-default-request-password-reset"> <h1><?php echo Html::encode($this->title); ?> </h1> <p><?php echo Module::t('password', 'PLEASE_FILL_FOR_RESET_REQUEST'); ?> </p> <div class="row"> <div class="col-lg-5"> <?php $form = ActiveForm::begin(['id' => 'request-password-reset-form']); ?> <?php echo $form->field($model, 'email'); ?> <div class="form-group"> <?php echo Html::submitButton(Yii::t('app', 'BUTTON_SEND'), ['class' => 'btn btn-primary']); ?>
<?php echo Html::activePasswordInput($model, 'password', ['class' => 'form-control', 'ng-model' => 'model.password']); ?> <error field="password"></error> </div> </div> <div class="form-group"> <?php echo Html::activeCheckbox($model, 'rememberMe', ['class' => '']); ?> </div> <div style="color:#999;margin:1em 0"> <?php echo Html::a(Module::t('login', 'LINK_RESET_PASSWORD'), ['request-password-reset']); ?> . </div> <div class="form-group"> <?php echo Html::submitButton(Module::t('login', 'BUTTON_LOGIN'), ['class' => 'btn btn-primary', 'ladda' => 'loginLoading', 'ng-click' => 'login()']); ?> </div> <?php echo Html::endForm(); ?> </div> </div> </div>
<?php use frontend\modules\user\Module; use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $user common\models\User */ $resetLink = Yii::$app->urlManager->createAbsoluteUrl(['user/default/reset-password', 'token' => $user->password_reset_token]); $this->title = Module::t('password', 'SUBJECT_RESET_PASSWORD {APP_NAME}', ['APP_NAME' => Yii::$app->name]); ?> <div class="password-reset"> <h3><?php echo Module::t('main', 'HELLO {username}', ['username' => Html::encode($user->username)]); ?> ,</h3> <p><?php echo Module::t('password', 'FOLLOW_TO_RESET_PASSWORD'); ?> </p> <p><?php echo Html::a(Html::encode($resetLink), $resetLink); ?> </p> </div>