Authored by 郝肖肖

弱密码页面

... ... @@ -419,6 +419,22 @@ const validateMobileInSession = (req, res, next) => {
next();
};
const weakPasswordPage = (req, res, next) => {
passportHelper.getLeftBannerAsync().then(result => {
res.render('back/weak-pwd', Object.assign({
module: 'passport',
page: 'back-weak-pwd',
simpleHeader: simpleHeaderModel.setSimpleHeaderData(),
title: '重置密码'
}, {
resetPwd: {
coverHref: result.url,
coverImg: result.img,
}
}));
}).catch(next);
};
module.exports = {
index, // 首页
fakeGetUserInfoAPI, // 通过邮箱或手机号获得用户信息
... ... @@ -449,6 +465,8 @@ module.exports = {
validateSuccessStatusPage, // 验证重设密码状态
validateExistCodePage, // 验证参数是否存在code
validatePwdPage // 验证密码是否合法
validatePwdPage, // 验证密码是否合法
weakPasswordPage // 弱密码页面
};
... ...
... ... @@ -185,4 +185,6 @@ router.get('/passport/back/resetSuccess',
router.get('/passport/images.png', captcha.generate);
router.post('/passport/captcha/img', captcha.checkAPI);
router.get('/passport/back/weak', back.weakPasswordPage);
module.exports = router;
... ...
<div class="reset-pwd-page back-page passport-page yoho-page clearfix">
{{# resetPwd}}
{{> back/cover}}
<div class="content">
<h2 class="title2">重置密码</h2>
<form id="reset-pwd-form" class="reset-pwd-form" method="POST" action="/passport/back/update">
<ul>
<li class="input-container-li po-re">
<input id="pwd" class="input va pwd" type="password" name="pwd" placeholder="新密码"
maxlength="20">
<div class="pwd-intensity-container">
<span class="pwd-intensity low"></span>
<span class="pwd-intensity mid"></span>
<span class="pwd-intensity high"></span>
</div>
<div id="pwd-tips" class="pwd-tips hide">
<div class="default" id="pwd-tip1">
<i></i>
密码只支持6-20位字符
</div>
<div class="default" id="pwd-tip2">
<i></i>
由字母、 数字组合,不能包含特殊符号
</div>
</div>
<span id="pwd-err" class="err-tip hide">
<i></i>
<em>请输入密码</em>
</span>
</li>
<li class="input-container-li clearfix po-re">
<input id="re-input" class="input va re-input repwd" type="password" name="re-input"
placeholder="再次输入" maxlength="20">
<span id="repwd-err" class="err-tip hide">
<i></i>
<em>请输入密码确认</em>
</span>
</li>
<li class="input-container-li clearfix">
<input type="hidden" name="code" value="{{code}}">
<input type="hidden" name="mobile" value="{{mobile}}">
<input type="hidden" name="area" value="{{area}}">
<input type="hidden" name="token" value="{{token}}">
<input type="hidden" name="createdAt" value="{{createdAt}}">
<input id="reset-pwd-btn" class="btn reset-pwd-btn" type="submit" value="提交" disabled="">
</li>
</ul>
</form>
</div>
{{/ resetPwd}}
</div>
... ...
/**
* 找回密码
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/12/14
*/
var $ = require('yoho-jquery');
var regx = require('../common/mail-phone-regx');
var Captcha = require('../../plugins/captcha');
var emailAc = require('../common/ac-email'); // 邮箱自动完成
var emailReg = regx.emailRegx,
phoneRegx = regx.phoneRegx;
var $cr = $('#country-code-hide'),
$phoneNum = $('#phone-num'),
$ca = $('#captcha'),
$ccList = $('#country-code-list'),
$cc = $('#country-code'),
$btn = $('#find-btn'),
$accErr = $('#account-err'),
caCount = 4, // 验证码位数
hasPh = false,
captcha = new Captcha('#captcha-img').init();
require('../../simple-header');
require('yoho-jquery-placeholder');
require('../../common/promise');
require('../../common');
function authcode() {
return $.ajax({
type: 'POST',
url: '/passport/back/authcode',
data: {
verifyCode: captcha.getResults(),
phoneNum: $phoneNum.val(),
area: $cr.val()
}
}).then(function(data) {
if (data.code === 200) {
$('#captcha-value').val(captcha.getResults());
return $.Deferred().resolve().promise(); //eslint-disable-line
} else if (data.code === 402) {
$accErr.removeClass('hide').find('em').text('该账号不存在');
$phoneNum.addClass('error');
captcha.refresh();
return $.Deferred().reject().promise();//eslint-disable-line
} else if (data.code === 405) {
captcha.showTip(data.message);
return $.Deferred().reject().promise();//eslint-disable-line
}
});
}
function vaPn(v) {
var pass = true,
errTxt = '';
v = $.trim(v);
if (v !== '') {
if (/^[0-9]+$/.test(v)) {
if (phoneRegx[$cr.val()].test(v)) {
pass = true;
} else {
errTxt = '手机号码格式不正确, 请重新输入';
pass = false;
}
} else {
if (emailReg.test(v)) {
pass = true;
} else {
errTxt = '邮箱格式不正确, 请重新输入';
pass = false;
}
}
} else {
errTxt = '账户名不能为空';
pass = false;
}
hasPh = pass;
return {
pass: pass,
errTxt: errTxt
};
}
function validatePhone() {
var pnVa = vaPn($phoneNum.val());
if (pnVa.pass) {
$accErr.addClass('hide');
$phoneNum.removeClass('error');
} else {
$accErr.removeClass('hide').find('em').text(pnVa.errTxt);
$phoneNum.addClass('error');
}
return pnVa.pass;
}
emailAc($phoneNum, function() {
validatePhone();
});
$ca.attr('maxlength', caCount);
// IE8 placeholder
$('input').placeholder();
$cc.on('click', function(e) {
e.stopPropagation();
if ($ccList.css('style') === 'block') {
$ccList.slideUp('fast');
} else {
$ccList.slideDown('fast');
}
});
$ccList.delegate('li', 'click', function(e) {
var $cur = $(this),
code = $cur.data('cc'),
pnVa;
e.stopPropagation();
$cr.val(code);
$cc.find('em').html($cur.text());
// 切换后验证手机号码
if ($.trim($phoneNum.val()) !== '') {
pnVa = vaPn($phoneNum.val());
if (hasPh) {
$accErr.addClass('hide');
$phoneNum.removeClass('error');
} else {
$accErr.removeClass('hide').text(pnVa.errTxt);
$phoneNum.addClass('error');
}
}
$ccList.slideUp('fast');
});
$(document).click(function() {
if ($ccList.css('display') === 'block') {
$ccList.slideUp();
}
});
$phoneNum.keyup(function() {
vaPn($.trim($(this).val()));
}).focus(function() {
$(this).removeClass('error');
// focus隐藏错误提示
$accErr.addClass('hide');
});
// 下一步
$btn.click(function(e) {
if (!validatePhone()) {
return;
}
if (!captcha.getResults()) {
captcha.showTip();
return;
}
if (/^[0-9]+$/.test($.trim($phoneNum.val()))) {
$('#find-form').attr('action', '/passport/back/mobile');
}
$('#captcha-value').val(captcha.getResults());
if (hasPh) {
authcode().then(function() {
$.post($('#back-form').attr('action'), {
phoneNum: $('#phone-num').val(),
area: $('#country-code-hide').val()
}).then(function(result) {
if (result.code === 200) {
window.jumpUrl(result.data.refer);
return;
}
if (result.code === 405) {
captcha.showTip(result.message);
$accErr.addClass('hide');
$phoneNum.removeClass('error');
return;
}
$accErr.removeClass('hide').find('em').text(result.message);
$phoneNum.addClass('error');
});
});
}
e.preventDefault();
return true;
});
captcha.onSuccess(function() {
$btn.triggerHandler('click');
});
... ...