This repository has been archived by the owner on Nov 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Add UserRecover Form, So that users can recover their password if they forget. 2. Add main recover function in UserConfirmForm. BREAKING CHANGE: Database Stucture of `users_confirms` change
- Loading branch information
Showing
9 changed files
with
259 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Rhilip | ||
* Date: 2019/6/4 | ||
* Time: 14:42 | ||
*/ | ||
|
||
namespace apps\models\form; | ||
|
||
|
||
use apps\components\User\UserInterface; | ||
use Rid\Helpers\StringHelper; | ||
use Rid\Validators\CaptchaTrait; | ||
use Rid\Validators\Validator; | ||
|
||
class UserRecoverForm extends Validator | ||
{ | ||
use CaptchaTrait; | ||
|
||
public $email; | ||
|
||
protected $_action = 'recover'; | ||
|
||
public static function inputRules() | ||
{ | ||
return [ | ||
'email' => 'required | email', | ||
]; | ||
} | ||
|
||
public static function callbackRules() | ||
{ | ||
return ['validateCaptcha']; | ||
} | ||
|
||
// TODO Add rate limit for user only can recover once in a time interval | ||
|
||
/** | ||
* Check email in our database and send recover link to that email | ||
* Notice: if this email is not exist in our database , will also return bool(true) for security reason. | ||
* However, We will not send recover-confirm-link email. | ||
* @return bool|string bool(true) means flush success , | ||
* any other value (string) performs like error msg | ||
*/ | ||
public function flush() { | ||
// Check this email is in our database or not? | ||
$user_info = app()->pdo->createCommand('SELECT `id`,`status` FROM `users` WHERE `email` = :email;')->bindParams([ | ||
'email' => $this->email | ||
])->queryOne(); | ||
if ($user_info !== false) { | ||
if ($user_info['status'] !== UserInterface::STATUS_CONFIRMED) { | ||
return 'std_user_account_unconfirmed'; | ||
} | ||
|
||
// Send user email to get comfirm link | ||
$confirm_key = StringHelper::getRandomString(32); | ||
app()->pdo->createCommand('INSERT INTO `users_confirm` (`uid`,`serect`,`action`) VALUES (:uid,:serect,:action)')->bindParams([ | ||
'uid' => $user_info['id'], 'serect' => $confirm_key, 'action' => $this->_action | ||
])->execute(); | ||
$confirm_url = app()->request->root() . '/auth/confirm?' . http_build_query([ | ||
'secret' => $confirm_key, | ||
'action' => $this->_action | ||
]); | ||
|
||
$mail_sender = \Rid\Libraries\Mailer::newInstanceByConfig('libraries.[swiftmailer]'); | ||
$mail_sender->send([$this->email], 'Please confirm your action to recover your password', "Click this link $confirm_url to confirm."); // FIXME change to email template | ||
} | ||
return true; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,33 @@ | ||
<?php | ||
/** | ||
* | ||
* Created by PhpStorm. | ||
* User: Rhilip | ||
* Date: 2019/3/8 | ||
* Time: 19:44 | ||
* | ||
* @var League\Plates\Template\Template $this | ||
* @var string $action 'register'|'recover' | ||
*/ | ||
?> | ||
|
||
<?= $this->layout('auth/base') ?> | ||
|
||
<?php $this->start('container') ?> | ||
<div class="jumbotron"> | ||
<?php if ($action == 'register'): ?> | ||
<h1>Your account is success Confirmed.</h1> | ||
<p>Click <!--suppress HtmlUnknownTarget --><a href="/auth/login">Login Page</a> to login</p> | ||
<?php elseif ($action == 'recover'): ?> | ||
<h1>Your password has been reset and new password has been send to your email, Please find it and login.</h1> | ||
<?php endif; ?> | ||
<p>Click <!--suppress HtmlUnknownTarget --><a href="/auth/login">Login Page</a> to login, Or wait 5 seconds to auto redirect.</p> <!-- TODO wait seconds change --> | ||
</div> | ||
<?php $this->end(); ?> | ||
|
||
<?php $this->push('script') ?> | ||
<script> | ||
window.setTimeout(function () { | ||
location.href = '/auth/login'; | ||
}, 2000); | ||
}, 5e3); | ||
</script> | ||
<?php $this->end(); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Rhilip | ||
* Date: 2019/6/3 | ||
* Time: 23:10 | ||
*/ | ||
?> | ||
|
||
<?= $this->layout('auth/base') ?> | ||
|
||
<?php $this->start('container') ?> | ||
<div class="row"> | ||
<div class="col-md-7 col-md-offset-3"> | ||
<div class="panel"> | ||
<div class="panel-heading">Recover lost user name or password</div> | ||
<div class="panel-body"> | ||
<fieldset style="margin-bottom: 10px"> | ||
<legend class="text-special">1. Enter Your Email</legend> | ||
|
||
<form class="auth-form" method="post"> | ||
<div class="form-group"> | ||
<label for="email">Email</label> | ||
<div class="input-group"> | ||
<span class="input-group-addon"><span class="fas fa-envelope fa-fw"></span></span> | ||
<input type="email" class="form-control" id="email" name="email" required> | ||
</div> | ||
<div class="help-block">The Email when your sign account.</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="captcha">Captcha</label> | ||
<div class="row"> | ||
<div class="col-md-4"> | ||
<div class="input-group"> | ||
<span class="input-group-addon"><span class="fas fa-sync-alt fa-fw"></span></span> | ||
<input type="text" class="form-control" id="captcha" name="captcha" maxlength="6" | ||
required autocomplete="off"> | ||
</div> | ||
<div class="help-block">Case insensitive.</div> | ||
</div> | ||
<div class="col-md-4"> | ||
<?= $this->insert('layout/captcha') ?> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="text-center"> | ||
<button type="submit" value="Register" class="btn btn-primary">Recover it!!</button> | ||
</div> | ||
</form> | ||
</fieldset> | ||
|
||
<fieldset><legend>2. Follow The Confirm Link to reset your password.</legend></fieldset> | ||
<fieldset><legend>3. Get new generate password from Email and login.</legend></fieldset> | ||
<fieldset><legend>4. Set your own password in user panel.</legend></fieldset> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<?php $this->end(); ?> |
Oops, something went wrong.