Commit 77b7aa25 authored by xiabin's avatar xiabin

修改找回密码的严重问题

parent 3b38a40b
...@@ -81,11 +81,11 @@ class SiteController extends Controller ...@@ -81,11 +81,11 @@ class SiteController extends Controller
], ],
'captcha' => [ 'captcha' => [
'class' => 'yii\captcha\CaptchaAction', 'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => false ? 'testme' : NULL, 'fixedVerifyCode' => FALSE ? 'testme' : NULL,
'maxLength'=>6, 'maxLength' => 6,
'minLength'=>6, 'minLength' => 6,
'transparent'=>TRUE, 'transparent' => TRUE,
'padding'=>10, 'padding' => 10,
], ],
]; ];
...@@ -203,19 +203,7 @@ class SiteController extends Controller ...@@ -203,19 +203,7 @@ class SiteController extends Controller
$model = new PasswordResetRequestForm(); $model = new PasswordResetRequestForm();
$request = Yii::$app->request; $request = Yii::$app->request;
if ($model->load($request->post()) && $model->validate()) { if ($model->load($request->post()) && $model->validate()) {
$geetestChallenge = $request->post('geetest_challenge'); if ($model->sendMsg()) {
$geetestSeccode = $request->post('geetest_seccode');
$geetestValidate = $request->post('geetest_validate');
$GtSdk = new Geetest(Yii::$app->params['captchaId'], Yii::$app->params['privateKey']);
$user_id = Yii::$app->session->get(self::GT_USER_ID);
if (Yii::$app->session->get(self::GT_SERVER) == 1) { //服务器正常
$gtResult = $GtSdk->success_validate($geetestChallenge, $geetestValidate, $geetestSeccode, $user_id);
} else { //服务器宕机,走failback模式
$gtResult = $GtSdk->fail_validate($geetestChallenge, $geetestValidate, $geetestSeccode);
}
if ($gtResult && $model->sendMsg()) {
Yii::$app->session->set(self::PASSWORD_RESET_KEY, $model->telephone); Yii::$app->session->set(self::PASSWORD_RESET_KEY, $model->telephone);
Yii::$app->session->set(self::RESET_PASSWORD_FIRST, TRUE); Yii::$app->session->set(self::RESET_PASSWORD_FIRST, TRUE);
return $this->redirect('token-input'); return $this->redirect('token-input');
...@@ -224,16 +212,15 @@ class SiteController extends Controller ...@@ -224,16 +212,15 @@ class SiteController extends Controller
} }
} }
return $this->render('requestPasswordResetToken', [ return $this->render('requestPasswordResetToken', ['model' => $model,]);
'model' => $model, }
]);
}
/** /**
* @return mixed * @return mixed
*/ */
public function actionTokenInput() public
{ function actionTokenInput()
{
if (!Yii::$app->session->has(self::RESET_PASSWORD_FIRST)) { if (!Yii::$app->session->has(self::RESET_PASSWORD_FIRST)) {
$this->redirect('request-password-reset'); $this->redirect('request-password-reset');
} }
...@@ -250,17 +237,15 @@ class SiteController extends Controller ...@@ -250,17 +237,15 @@ class SiteController extends Controller
return $this->render('tokenInput', [ return $this->render('tokenInput', [
'model' => $model, 'model' => $model,
]); ]);
} }
/** /**
* Resets password. * Resets password.
* @return mixed * @return mixed
*/ */
public function actionResetPassword() public
{ function actionResetPassword()
// if (!Yii::$app->session->has(self::RESET_PASSWORD_SECOND)) { {
// $this->redirect('request-password-reset');
// }
$model = new ResetPasswordForm(Yii::$app->session->get(self::PASSWORD_RESET_KEY)); $model = new ResetPasswordForm(Yii::$app->session->get(self::PASSWORD_RESET_KEY));
if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) { if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) {
Yii::$app->session->set(self::RESET_PASSWORD_THREE, TRUE); Yii::$app->session->set(self::RESET_PASSWORD_THREE, TRUE);
...@@ -272,27 +257,29 @@ class SiteController extends Controller ...@@ -272,27 +257,29 @@ class SiteController extends Controller
return $this->render('resetPassword', [ return $this->render('resetPassword', [
'model' => $model, 'model' => $model,
]); ]);
} }
/** /**
* 密码设置成功 * 密码设置成功
* @return string * @return string
*/ */
public function actionResetPasswordSuccess() public
{ function actionResetPasswordSuccess()
{
if (!Yii::$app->session->has(self::RESET_PASSWORD_THREE)) { if (!Yii::$app->session->has(self::RESET_PASSWORD_THREE)) {
$this->redirect('request-password-reset'); $this->redirect('request-password-reset');
} }
Yii::$app->session->remove(self::RESET_PASSWORD_THREE); Yii::$app->session->remove(self::RESET_PASSWORD_THREE);
return $this->render('resetPasswordSuccess'); return $this->render('resetPasswordSuccess');
} }
/** /**
* 极验证开始 * 极验证开始
* ajax * ajax
*/ */
public function actionStartCaptcha() public
{ function actionStartCaptcha()
{
if (Yii::$app->request->isAjax) { if (Yii::$app->request->isAjax) {
$type = Yii::$app->request->get('type'); $type = Yii::$app->request->get('type');
if ($type == 'pc') { if ($type == 'pc') {
...@@ -308,30 +295,32 @@ class SiteController extends Controller ...@@ -308,30 +295,32 @@ class SiteController extends Controller
} else { } else {
throw new \yii\web\ForbiddenHttpException('非法请求'); throw new \yii\web\ForbiddenHttpException('非法请求');
} }
} }
/** /**
* 设置登录后回调url * 设置登录后回调url
* @param $url * @param $url
* @throws \yii\web\ForbiddenHttpException * @throws \yii\web\ForbiddenHttpException
*/ */
public function actionSetReturnUrl($url) public
{ function actionSetReturnUrl($url)
{
if (Yii::$app->request->isAjax) { if (Yii::$app->request->isAjax) {
Yii::$app->user->setReturnUrl($url); Yii::$app->user->setReturnUrl($url);
Utils::ajaxResponse(TRUE); Utils::ajaxResponse(TRUE);
} else { } else {
throw new \yii\web\ForbiddenHttpException('非法请求'); throw new \yii\web\ForbiddenHttpException('非法请求');
} }
} }
/** /**
* 发送注册短信 * 发送注册短信
* ajax * ajax
* @throws \yii\web\ForbiddenHttpException * @throws \yii\web\ForbiddenHttpException
*/ */
public function actionSendSignupMsg() public
{ function actionSendSignupMsg()
{
if (Yii::$app->request->isAjax) { if (Yii::$app->request->isAjax) {
$telephone = trim(Yii::$app->request->get('telephone')); $telephone = trim(Yii::$app->request->get('telephone'));
if (Utils::isTelephone($telephone)) { if (Utils::isTelephone($telephone)) {
...@@ -359,5 +348,5 @@ class SiteController extends Controller ...@@ -359,5 +348,5 @@ class SiteController extends Controller
} else { } else {
throw new \yii\web\ForbiddenHttpException('非法请求'); throw new \yii\web\ForbiddenHttpException('非法请求');
} }
} }
} }
...@@ -17,6 +17,7 @@ class PasswordResetRequestForm extends Model ...@@ -17,6 +17,7 @@ class PasswordResetRequestForm extends Model
public $telephone; public $telephone;
public $verifyCode;
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -30,11 +31,21 @@ class PasswordResetRequestForm extends Model ...@@ -30,11 +31,21 @@ class PasswordResetRequestForm extends Model
'filter' => ['status' => User::STATUS_ACTIVE], 'filter' => ['status' => User::STATUS_ACTIVE],
'message' => 'There is no user with such telephone.' 'message' => 'There is no user with such telephone.'
], ],
['verifyCode', 'required'],
['verifyCode', 'captcha']
]; ];
} }
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'verifyCode'=>''
];
}
public function sendMsg() public function sendMsg()
{ {
......
...@@ -45,7 +45,7 @@ class ResetPasswordForm extends Model ...@@ -45,7 +45,7 @@ class ResetPasswordForm extends Model
['password', 'required'], ['password', 'required'],
['password', 'string', 'min' => 6], ['password', 'string', 'min' => 6],
['rePassword', 'string', 'min' => 6], ['rePassword', 'string', 'min' => 6],
['rePassword', 'compare', 'compareAttribute' => 'rePassword'], ['rePassword', 'compare', 'compareAttribute' => 'password','message'=>'两次密码输入不一致'],
]; ];
} }
......
...@@ -35,7 +35,7 @@ class SignupForm extends Model ...@@ -35,7 +35,7 @@ class SignupForm extends Model
[['password', 'rePassword'], 'required'], [['password', 'rePassword'], 'required'],
['password', 'string', 'min' => 6], ['password', 'string', 'min' => 6],
['rePassword', 'string', 'min' => 6], ['rePassword', 'string', 'min' => 6],
['rePassword', 'compare', 'compareAttribute' => 'rePassword'], ['rePassword', 'compare', 'compareAttribute' => 'password'],
['from', 'integer'], ['from', 'integer'],
['verifyCode', 'required'], ['verifyCode', 'required'],
['verifyCode', 'captcha'] ['verifyCode', 'captcha']
......
...@@ -21,6 +21,7 @@ class TokenInputForm extends Model ...@@ -21,6 +21,7 @@ class TokenInputForm extends Model
{ {
public $token; public $token;
public $verifyCode;
/** /**
* @return array * @return array
*/ */
...@@ -29,10 +30,24 @@ class TokenInputForm extends Model ...@@ -29,10 +30,24 @@ class TokenInputForm extends Model
return [ return [
['token', 'trim'], ['token', 'trim'],
['token', 'required'], ['token', 'required'],
['token', 'string'] ['token', 'string'],
['verifyCode', 'required'],
['verifyCode', 'captcha']
]; ];
} }
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'verifyCode'=>''
];
}
/** /**
* @inheritdoc * @inheritdoc
*/ */
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
/* @var $model \frontend\models\PasswordResetRequestForm */ /* @var $model \frontend\models\PasswordResetRequestForm */
use yii\bootstrap\ActiveForm; use yii\bootstrap\ActiveForm;
use yii\captcha\Captcha;
$this->title = '找回密码'; $this->title = '找回密码';
\frontend\assets\AppAsset::addScript($this, '@web/assets/request_password_reset.js'); \frontend\assets\AppAsset::addScript($this, '@web/assets/request_password_reset.js');
...@@ -36,15 +37,20 @@ $this->registerJsFile('http://static.geetest.com/static/tools/gt.js'); ...@@ -36,15 +37,20 @@ $this->registerJsFile('http://static.geetest.com/static/tools/gt.js');
<input name="telephone" type="text" class="" placeholder="请输入注册的手机号码" required="" autofocus=""> <input name="telephone" type="text" class="" placeholder="请输入注册的手机号码" required="" autofocus="">
<!--<span class="tips">手机号或者密码错误</span>--> <!--<span class="tips">手机号或者密码错误</span>-->
</div> </div>
<div class="password input-wrapper last-wrapper"">
<?= $form->field($model, 'verifyCode')->widget(Captcha::className(),[
'template' => "{image}",
'imageOptions' => ['alt' => '验证码'],
'captchaAction' => 'site/captcha',
])->error(FALSE); ?>
<input id="verifyCode" name="verifyCode" type="text" placeholder="输入验证码" required="">
<span id="verifyCode" class="tips"><?= $model->getFirstError('verifyCode') ?></span>
</div> </div>
<div class="v-geetest">
<div id="embed-captcha"></div>
<p id="wait" class="show">正在加载验证码......</p>
<p id="notice" class="hide">请先拖动验证码到相应位置</p>
</div> </div>
<div class="foot-reg-btn"> <div class="foot-reg-btn">
<button id="submit" class="btn btn-log" type="submit">获取验证码</button> <button id="submit" class="btn btn-log" type="submit">获取验证码</button>
</div> </div>
......
...@@ -8,20 +8,6 @@ use yii\helpers\Html; ...@@ -8,20 +8,6 @@ use yii\helpers\Html;
use yii\bootstrap\ActiveForm; use yii\bootstrap\ActiveForm;
$this->title = 'Reset password'; $this->title = 'Reset password';
$jsString = <<<JS
$("#submit").unbind().click(function() {
console.log($("#password").val());
console.log($("#repassword").val());
if($("#password").val() != $("#repassword").val()){
$("#repassword_tips").html('两次密码不一致');
return false;
}
});
JS;
$this->registerJs($jsString);
?> ?>
<div class="container"> <div class="container">
<div class="z-m-center"> <div class="z-m-center">
...@@ -41,20 +27,21 @@ $this->registerJs($jsString); ...@@ -41,20 +27,21 @@ $this->registerJs($jsString);
<div class="tab-pane fade in active" id="three"> <div class="tab-pane fade in active" id="three">
<?php $form = ActiveForm::begin(['id' => 'request-password-reset-form']); ?> <?php $form = ActiveForm::begin(['id' => 'request-password-reset-form']); ?>
<div class="reg-box"> <div class="reg-box">
<div class="password input-wrapper"> <div class="password input-wrapper">
<input value="<?= $model->password ?>" id="password" name="password" type="password" class="" <input value="<?= $model->password ?>" id="password" name="password" type="password" class=""
placeholder="设置新密码" required=""> placeholder="设置新密码" >
<span id="repassword_tips" class="tips"><?= $model->getFirstError('password') ?></span>
</div> </div>
<div class="check-password input-wrapper last-wrapper"> <div class="check-password input-wrapper">
<input value="<?= $model->rePassword ?>" id="repassword" name="rePassword" type="password" class="" placeholder="重复输入密码" required=""> <input value="<?= $model->rePassword ?>" id="repassword" name="rePassword" type="password" class="" placeholder="重复输入密码" >
<span id="repassword_tips" class="tips"><?= $model->getFirstError('rePassword') ?></span> <span id="repassword_tips" class="tips"><?= $model->getFirstError('rePassword') ?></span>
</div> </div>
</div> </div>
<div class="foot-reg-btn"> <div class="foot-reg-btn">
<button id="submit" class="btn btn-log" type="submit">确认</button> <button class="btn btn-log" type="submit">确认</button>
</div> </div>
<?php ActiveForm::end() ?> <?php ActiveForm::end() ?>
</div> </div>
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
*/ */
use yii\captcha\Captcha;
use yii\helpers\Html; use yii\helpers\Html;
use yii\bootstrap\ActiveForm; use yii\bootstrap\ActiveForm;
...@@ -40,10 +41,14 @@ $this->registerJsFile('http://static.geetest.com/static/tools/gt.js'); ...@@ -40,10 +41,14 @@ $this->registerJsFile('http://static.geetest.com/static/tools/gt.js');
<input name="token" type="text" class="" value="<?= $model->token?>" placeholder="请输入6位验证码" required="" autofocus=""> <input name="token" type="text" class="" value="<?= $model->token?>" placeholder="请输入6位验证码" required="" autofocus="">
<span class="tips"><?= $model->getFirstError('token') ?></span> <span class="tips"><?= $model->getFirstError('token') ?></span>
</div> </div>
<div style="margin-top: 20px;margin-bottom: 20px"> <div class="password input-wrapper last-wrapper"">
<div id="embed-captcha"></div> <?= $form->field($model, 'verifyCode')->widget(Captcha::className(),[
<p id="wait" class="show">正在加载验证码......</p> 'template' => "{image}",
<p id="notice" class="hide">请先拖动验证码到相应位置</p> 'imageOptions' => ['alt' => '验证码'],
'captchaAction' => 'site/captcha',
])->error(FALSE); ?>
<input id="verifyCode" name="verifyCode" type="text" placeholder="输入验证码" required="">
<span id="verifyCode" class="tips"><?= $model->getFirstError('verifyCode') ?></span>
</div> </div>
</div> </div>
<div class="foot-reg-btn"> <div class="foot-reg-btn">
......
/** /**
* Created by xiabin on 2016/9/26. * Created by xiabin on 2016/9/26.
*/ */
var handlerEmbed = function (captchaObj) {
$("#submit").unbind().click(function (e) {
var validate = captchaObj.getValidate();
if (!validate) {
$("#notice")[0].className = "show";
setTimeout(function () {
$("#notice")[0].className = "hide";
}, 2000);
return false;
}else{
$("#request-password-reset-form").submit();
}
});
// 将验证码加到id为captcha的元素里,同时会有三个input的值:geetest_challenge, geetest_validate, geetest_seccode
captchaObj.appendTo("#embed-captcha");
captchaObj.onReady(function () {
$("#wait")[0].className = "hide";
});
// 更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html
};
$.ajax({
// 获取id,challenge,success(是否启用failback)
url: __BASE_URL__ + "site/start-captcha?type=pc&t=" + (new Date()).getTime(), // 加随机数防止缓存
type: "get",
dataType: "json",
success: function (data) {
// 使用initGeetest接口
// 参数1:配置参数
// 参数2:回调,回调的第一个参数验证码对象,之后可以使用它做appendTo之类的事件
initGeetest({
gt: data.gt,
challenge: data.challenge,
product: "float", // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效
offline: !data.success // 表示用户后台检测极验服务器是否宕机,一般不需要关注
// 更多配置参数请参见:http://www.geetest.com/install/sections/idx-client-sdk.html#config
}, handlerEmbed);
}
});
...@@ -4,41 +4,6 @@ ...@@ -4,41 +4,6 @@
/** /**
* Created by xiabin on 2016/9/26. * Created by xiabin on 2016/9/26.
*/ */
var handlerEmbed = function (captchaObj) {
$("#token_input").click(function () {
var validate = captchaObj.getValidate();
if (!validate) {
$("#notice")[0].className = "show";
setTimeout(function () {
$("#notice")[0].className = "hide";
}, 2000);
return false;
}
});
// 将验证码加到id为captcha的元素里,同时会有三个input的值:geetest_challenge, geetest_validate, geetest_seccode
captchaObj.appendTo("#embed-captcha");
captchaObj.onReady(function () {
$("#wait")[0].className = "hide";
});
// 更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html
};
$.ajax({
// 获取id,challenge,success(是否启用failback)
url: __BASE_URL__ + "site/start-captcha?type=pc&t=" + (new Date()).getTime(), // 加随机数防止缓存
type: "get",
dataType: "json",
success: function (data) {
// 使用initGeetest接口
// 参数1:配置参数
// 参数2:回调,回调的第一个参数验证码对象,之后可以使用它做appendTo之类的事件
initGeetest({
gt: data.gt,
challenge: data.challenge,
product: "float", // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效
offline: !data.success // 表示用户后台检测极验服务器是否宕机,一般不需要关注
// 更多配置参数请参见:http://www.geetest.com/install/sections/idx-client-sdk.html#config
}, handlerEmbed);
}
});
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