Commit d13ed432 by Alexander Makarov

Fixed signup/restore password flow

parent 9da28421
...@@ -32,6 +32,8 @@ class User extends ActiveRecord implements IdentityInterface ...@@ -32,6 +32,8 @@ class User extends ActiveRecord implements IdentityInterface
/** @var User $user */ /** @var User $user */
$user = new static(); $user = new static();
$user->setAttributes($attributes); $user->setAttributes($attributes);
$user->setPassword($attributes['password']);
$user->generateAuthKey();
if ($user->save()) { if ($user->save()) {
return $user; return $user;
} else { } else {
...@@ -142,6 +144,14 @@ class User extends ActiveRecord implements IdentityInterface ...@@ -142,6 +144,14 @@ class User extends ActiveRecord implements IdentityInterface
} }
/** /**
* Generates "remember me" authentication key
*/
public function generateAuthKey()
{
$this->auth_key = Security::generateRandomKey();
}
/**
* Generates new password reset token * Generates new password reset token
*/ */
public function generatePasswordResetToken() public function generatePasswordResetToken()
......
...@@ -122,11 +122,13 @@ class SiteController extends Controller ...@@ -122,11 +122,13 @@ class SiteController extends Controller
public function actionRequestPasswordReset() public function actionRequestPasswordReset()
{ {
$model = new PasswordResetRequestForm(); $model = new PasswordResetRequestForm();
if ($model->load(Yii::$app->request->post()) && $model->sendEmail()) { if ($model->load(Yii::$app->request->post())) {
Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.'); if ($model->sendEmail()) {
return $this->goHome(); Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.');
} else { return $this->goHome();
Yii::$app->getSession()->setFlash('error', 'There was an error sending email.'); } else {
Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
}
} }
return $this->render('requestPasswordResetToken', [ return $this->render('requestPasswordResetToken', [
......
...@@ -20,7 +20,7 @@ class PasswordResetRequestForm extends Model ...@@ -20,7 +20,7 @@ class PasswordResetRequestForm extends Model
['email', 'filter', 'filter' => 'trim'], ['email', 'filter', 'filter' => 'trim'],
['email', 'required'], ['email', 'required'],
['email', 'email'], ['email', 'email'],
['email', 'exist', 'targetClass' => 'User', 'message' => 'There is no user with such email.'], ['email', 'exist', 'targetClass' => '\common\models\User', 'message' => 'There is no user with such email.'],
]; ];
} }
......
...@@ -27,7 +27,7 @@ class SignupForm extends Model ...@@ -27,7 +27,7 @@ class SignupForm extends Model
['email', 'filter', 'filter' => 'trim'], ['email', 'filter', 'filter' => 'trim'],
['email', 'required'], ['email', 'required'],
['email', 'email'], ['email', 'email'],
['email', 'unique', 'targetClass' => 'User', 'message' => 'This email address has already been taken.'], ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'],
['password', 'required'], ['password', 'required'],
['password', 'string', 'min' => 6], ['password', 'string', 'min' => 6],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment