Authored by 郝肖肖

重置密码接口绑定

... ... @@ -420,6 +420,8 @@ const validateMobileInSession = (req, res, next) => {
};
const weakPasswordPage = (req, res, next) => {
let refer = req.query.refer || helpers.urlFormat('/');
passportHelper.getLeftBannerAsync().then(result => {
res.render('back/weak-pwd', Object.assign({
module: 'passport',
... ... @@ -429,7 +431,8 @@ const weakPasswordPage = (req, res, next) => {
}, {
resetPwd: {
coverHref: result.url,
coverImg: result.img
coverImg: result.img,
refer: refer
}
}));
}).catch(next);
... ... @@ -457,10 +460,10 @@ const modPwdByCodeAPI = (req, res, next) => {
let body = req.body;
service.modPwdByCodeAsync({
uid: req.use.uid,
uid: req.user.uid,
oldPwd: body.oldPwd,
newPwd: body.newPwd,
token: req.cookies.CSToken,
token: req.cookies.CSToken
}).then(d => {
res.json(d);
}).catch(next);
... ...
... ... @@ -4,7 +4,7 @@
<div class="content">
<h2 class="title3">重置登录密码</h2>
<p class="title-tip">您的账号密码过于简单请重置登陆密码</p>
<form id="reset-pwd-form" class="reset-pwd-form" method="POST" action="/passport/back/update">
<form>
<ul>
<li class="input-container-li po-re">
<input id="pwd" class="input va pwd" type="password" name="pwd" placeholder="原密码"
... ... @@ -17,7 +17,7 @@
<li class="input-container-li clearfix po-re">
<input id="re-input" class="input va re-input repwd" type="password" name="re-input"
placeholder="6-20位新密码" maxlength="20">
<div class="pwd-intensity-container">
<div class="pwd-intensity-container hide">
<span class="pwd-intensity low"></span>
<span class="pwd-intensity mid"></span>
<span class="pwd-intensity high"></span>
... ... @@ -38,15 +38,10 @@
</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="">
<input id="reset-pwd-btn" class="btn reset-pwd-btn disable" type="button" value="重新登录" disabled="true">
</li>
<li class="input-container-li">
<a class="weak-pwd-pass">跳过<i class="iconfont right-icon"></i></a>
<a class="weak-pwd-pass" href="{{refer}}" data-url="{{refer}}">跳过<i class="iconfont right-icon"></i></a>
</li>
</ul>
</form>
... ...
... ... @@ -6,205 +6,106 @@
var $ = require('yoho-jquery');
var regx = require('../common/mail-phone-regx');
var $pwd = $('#pwd'),
$repwd = $('#re-input'),
$next = $('#reset-pwd-btn'),
$pwdErr = $('#pwd-err'),
$repwdErr = $('#repwd-err'),
$titleTip = $('.title-tip'),
$weakPwdPass = $('.weak-pwd-pass');
var Captcha = require('../../plugins/captcha');
var pwdRegx = require('../common/mail-phone-regx').pwdValidateRegx;
var emailAc = require('../common/ac-email'); // 邮箱自动完成
require('yoho-jquery-placeholder');
require('../../simple-header');
var emailReg = regx.emailRegx,
phoneRegx = regx.phoneRegx;
// IE8 placeholder
$('input').placeholder();
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();
$('.va').keyup(function() {
var pass = true;
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 = '账户名不能为空';
if ($(this).val() === '') {
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');
if (pass && !$pwdErr.is(':hidden')) {
pass = false;
}
return pnVa.pass;
}
emailAc($phoneNum, function() {
validatePhone();
});
$ca.attr('maxlength', caCount);
// IE8 placeholder
$('input').placeholder();
if (pass && !$repwdErr.is(':hidden')) {
pass = false;
}
$cc.on('click', function(e) {
e.stopPropagation();
if ($ccList.css('style') === 'block') {
$ccList.slideUp('fast');
if (pass) {
$next.removeClass('disable').prop('disabled', false);
} else {
$ccList.slideDown('fast');
$next.addClass('disable').prop('disabled', true);
}
});
$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');
}).blur(function() {
var $this = $(this),
v = $this.val();
if ($this.hasClass('pwd')) {
if (v === '') {
$this.addClass('error');
$pwdErr.removeClass('hide').find('em').text('请输入密码');
} else if (v.length < 6 || v.length > 20) {
$this.addClass('error');
$pwdErr.removeClass('hide').find('em').text('密码只支持6-20位');
}
} else {
if (v === '') {
$this.addClass('error');
$repwdErr.removeClass('hide').find('em').text('请输入密码确认');
} else if (v.length < 6 || v.length > 20) {
$this.addClass('error');
$repwdErr.removeClass('hide').find('em').text('密码只支持6-20位');
} else if (!pwdRegx.test(v)) {
$this.addClass('error');
$repwdErr.removeClass('hide').find('em').text('密码须字母和数字组合');
}
}
$ccList.slideUp('fast');
});
$(document).click(function() {
if ($ccList.css('display') === 'block') {
$ccList.slideUp();
}
});
$phoneNum.keyup(function() {
vaPn($.trim($(this).val()));
$(this).trigger('keyup');
}).focus(function() {
$(this).removeClass('error');
// focus隐藏错误提示
$accErr.addClass('hide');
// focus后错误提示隐藏
if ($(this).hasClass('pwd')) {
$pwdErr.addClass('hide');
} else {
$repwdErr.addClass('hide');
}
});
// 下一步
$btn.click(function(e) {
if (!validatePhone()) {
return;
}
$('#pwd, #repwd').keydown(function(e) {
var code = e.keyCode || e.which;
if (!captcha.getResults()) {
captcha.showTip();
// 空格输入过滤
if (code === 32) {
e.preventDefault();
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');
$next.on('click', function() {
var refer = $weakPwdPass.data('href') || '/';
$.post('/passport/back/modPwdByCodeAPI', {
oldPwd: $pwd.val(),
newPwd: $repwd.val()
}, function(d) {
if (d.code === 200) {
document.location.href = '//www.yohobuy.com/passport/back/weakSuccess?refer=' + refer;
return true;
} else if (d.code === 402) {
// token is error
document.location.href = '//www.yohobuy.com/reg.html?refer=' + refer;
return true;
}
$titleTip.html(d.message);
});
});
... ...