Authored by 郝肖肖

弱密码页面

@@ -419,6 +419,22 @@ const validateMobileInSession = (req, res, next) => { @@ -419,6 +419,22 @@ const validateMobileInSession = (req, res, next) => {
419 next(); 419 next();
420 }; 420 };
421 421
  422 +const weakPasswordPage = (req, res, next) => {
  423 + passportHelper.getLeftBannerAsync().then(result => {
  424 + res.render('back/weak-pwd', Object.assign({
  425 + module: 'passport',
  426 + page: 'back-weak-pwd',
  427 + simpleHeader: simpleHeaderModel.setSimpleHeaderData(),
  428 + title: '重置密码'
  429 + }, {
  430 + resetPwd: {
  431 + coverHref: result.url,
  432 + coverImg: result.img,
  433 + }
  434 + }));
  435 + }).catch(next);
  436 +};
  437 +
422 module.exports = { 438 module.exports = {
423 index, // 首页 439 index, // 首页
424 fakeGetUserInfoAPI, // 通过邮箱或手机号获得用户信息 440 fakeGetUserInfoAPI, // 通过邮箱或手机号获得用户信息
@@ -449,6 +465,8 @@ module.exports = { @@ -449,6 +465,8 @@ module.exports = {
449 validateSuccessStatusPage, // 验证重设密码状态 465 validateSuccessStatusPage, // 验证重设密码状态
450 validateExistCodePage, // 验证参数是否存在code 466 validateExistCodePage, // 验证参数是否存在code
451 467
452 - validatePwdPage // 验证密码是否合法 468 + validatePwdPage, // 验证密码是否合法
  469 +
  470 + weakPasswordPage // 弱密码页面
453 }; 471 };
454 472
@@ -185,4 +185,6 @@ router.get('/passport/back/resetSuccess', @@ -185,4 +185,6 @@ router.get('/passport/back/resetSuccess',
185 router.get('/passport/images.png', captcha.generate); 185 router.get('/passport/images.png', captcha.generate);
186 router.post('/passport/captcha/img', captcha.checkAPI); 186 router.post('/passport/captcha/img', captcha.checkAPI);
187 187
  188 +router.get('/passport/back/weak', back.weakPasswordPage);
  189 +
188 module.exports = router; 190 module.exports = router;
  1 +<div class="reset-pwd-page back-page passport-page yoho-page clearfix">
  2 + {{# resetPwd}}
  3 + {{> back/cover}}
  4 + <div class="content">
  5 + <h2 class="title2">重置密码</h2>
  6 + <form id="reset-pwd-form" class="reset-pwd-form" method="POST" action="/passport/back/update">
  7 + <ul>
  8 + <li class="input-container-li po-re">
  9 + <input id="pwd" class="input va pwd" type="password" name="pwd" placeholder="新密码"
  10 + maxlength="20">
  11 + <div class="pwd-intensity-container">
  12 + <span class="pwd-intensity low"></span>
  13 + <span class="pwd-intensity mid"></span>
  14 + <span class="pwd-intensity high"></span>
  15 + </div>
  16 + <div id="pwd-tips" class="pwd-tips hide">
  17 + <div class="default" id="pwd-tip1">
  18 + <i></i>
  19 + 密码只支持6-20位字符
  20 + </div>
  21 + <div class="default" id="pwd-tip2">
  22 + <i></i>
  23 + 由字母、 数字组合,不能包含特殊符号
  24 + </div>
  25 + </div>
  26 + <span id="pwd-err" class="err-tip hide">
  27 + <i></i>
  28 + <em>请输入密码</em>
  29 + </span>
  30 + </li>
  31 + <li class="input-container-li clearfix po-re">
  32 + <input id="re-input" class="input va re-input repwd" type="password" name="re-input"
  33 + placeholder="再次输入" maxlength="20">
  34 + <span id="repwd-err" class="err-tip hide">
  35 + <i></i>
  36 + <em>请输入密码确认</em>
  37 + </span>
  38 + </li>
  39 + <li class="input-container-li clearfix">
  40 + <input type="hidden" name="code" value="{{code}}">
  41 + <input type="hidden" name="mobile" value="{{mobile}}">
  42 + <input type="hidden" name="area" value="{{area}}">
  43 + <input type="hidden" name="token" value="{{token}}">
  44 + <input type="hidden" name="createdAt" value="{{createdAt}}">
  45 + <input id="reset-pwd-btn" class="btn reset-pwd-btn" type="submit" value="提交" disabled="">
  46 + </li>
  47 + </ul>
  48 + </form>
  49 + </div>
  50 + {{/ resetPwd}}
  51 +</div>
  1 +/**
  2 + * 找回密码
  3 + * @author: xuqi<qi.xu@yoho.cn>
  4 + * @date: 2015/12/14
  5 + */
  6 +
  7 +var $ = require('yoho-jquery');
  8 +
  9 +var regx = require('../common/mail-phone-regx');
  10 +
  11 +var Captcha = require('../../plugins/captcha');
  12 +
  13 +var emailAc = require('../common/ac-email'); // 邮箱自动完成
  14 +
  15 +var emailReg = regx.emailRegx,
  16 + phoneRegx = regx.phoneRegx;
  17 +
  18 +var $cr = $('#country-code-hide'),
  19 + $phoneNum = $('#phone-num'),
  20 + $ca = $('#captcha'),
  21 + $ccList = $('#country-code-list'),
  22 + $cc = $('#country-code'),
  23 + $btn = $('#find-btn'),
  24 + $accErr = $('#account-err'),
  25 + caCount = 4, // 验证码位数
  26 + hasPh = false,
  27 + captcha = new Captcha('#captcha-img').init();
  28 +
  29 +require('../../simple-header');
  30 +require('yoho-jquery-placeholder');
  31 +require('../../common/promise');
  32 +require('../../common');
  33 +
  34 +function authcode() {
  35 + return $.ajax({
  36 + type: 'POST',
  37 + url: '/passport/back/authcode',
  38 + data: {
  39 + verifyCode: captcha.getResults(),
  40 + phoneNum: $phoneNum.val(),
  41 + area: $cr.val()
  42 + }
  43 +
  44 + }).then(function(data) {
  45 + if (data.code === 200) {
  46 + $('#captcha-value').val(captcha.getResults());
  47 + return $.Deferred().resolve().promise(); //eslint-disable-line
  48 + } else if (data.code === 402) {
  49 + $accErr.removeClass('hide').find('em').text('该账号不存在');
  50 + $phoneNum.addClass('error');
  51 + captcha.refresh();
  52 + return $.Deferred().reject().promise();//eslint-disable-line
  53 + } else if (data.code === 405) {
  54 + captcha.showTip(data.message);
  55 + return $.Deferred().reject().promise();//eslint-disable-line
  56 + }
  57 + });
  58 +}
  59 +
  60 +function vaPn(v) {
  61 + var pass = true,
  62 + errTxt = '';
  63 +
  64 + v = $.trim(v);
  65 + if (v !== '') {
  66 + if (/^[0-9]+$/.test(v)) {
  67 + if (phoneRegx[$cr.val()].test(v)) {
  68 + pass = true;
  69 + } else {
  70 + errTxt = '手机号码格式不正确, 请重新输入';
  71 + pass = false;
  72 + }
  73 + } else {
  74 + if (emailReg.test(v)) {
  75 + pass = true;
  76 + } else {
  77 + errTxt = '邮箱格式不正确, 请重新输入';
  78 + pass = false;
  79 + }
  80 + }
  81 + } else {
  82 + errTxt = '账户名不能为空';
  83 + pass = false;
  84 + }
  85 + hasPh = pass;
  86 +
  87 + return {
  88 + pass: pass,
  89 + errTxt: errTxt
  90 + };
  91 +}
  92 +
  93 +function validatePhone() {
  94 + var pnVa = vaPn($phoneNum.val());
  95 +
  96 + if (pnVa.pass) {
  97 + $accErr.addClass('hide');
  98 + $phoneNum.removeClass('error');
  99 + } else {
  100 + $accErr.removeClass('hide').find('em').text(pnVa.errTxt);
  101 + $phoneNum.addClass('error');
  102 + }
  103 +
  104 + return pnVa.pass;
  105 +}
  106 +
  107 +emailAc($phoneNum, function() {
  108 + validatePhone();
  109 +});
  110 +
  111 +$ca.attr('maxlength', caCount);
  112 +
  113 +// IE8 placeholder
  114 +$('input').placeholder();
  115 +
  116 +$cc.on('click', function(e) {
  117 + e.stopPropagation();
  118 + if ($ccList.css('style') === 'block') {
  119 + $ccList.slideUp('fast');
  120 + } else {
  121 + $ccList.slideDown('fast');
  122 + }
  123 +});
  124 +
  125 +$ccList.delegate('li', 'click', function(e) {
  126 + var $cur = $(this),
  127 + code = $cur.data('cc'),
  128 + pnVa;
  129 +
  130 + e.stopPropagation();
  131 + $cr.val(code);
  132 + $cc.find('em').html($cur.text());
  133 +
  134 + // 切换后验证手机号码
  135 + if ($.trim($phoneNum.val()) !== '') {
  136 + pnVa = vaPn($phoneNum.val());
  137 + if (hasPh) {
  138 + $accErr.addClass('hide');
  139 + $phoneNum.removeClass('error');
  140 + } else {
  141 + $accErr.removeClass('hide').text(pnVa.errTxt);
  142 + $phoneNum.addClass('error');
  143 + }
  144 + }
  145 + $ccList.slideUp('fast');
  146 +});
  147 +
  148 +$(document).click(function() {
  149 + if ($ccList.css('display') === 'block') {
  150 + $ccList.slideUp();
  151 + }
  152 +});
  153 +
  154 +$phoneNum.keyup(function() {
  155 + vaPn($.trim($(this).val()));
  156 +}).focus(function() {
  157 + $(this).removeClass('error');
  158 +
  159 + // focus隐藏错误提示
  160 + $accErr.addClass('hide');
  161 +});
  162 +
  163 +// 下一步
  164 +$btn.click(function(e) {
  165 + if (!validatePhone()) {
  166 + return;
  167 + }
  168 +
  169 + if (!captcha.getResults()) {
  170 + captcha.showTip();
  171 + return;
  172 + }
  173 +
  174 + if (/^[0-9]+$/.test($.trim($phoneNum.val()))) {
  175 + $('#find-form').attr('action', '/passport/back/mobile');
  176 + }
  177 +
  178 + $('#captcha-value').val(captcha.getResults());
  179 +
  180 + if (hasPh) {
  181 + authcode().then(function() {
  182 + $.post($('#back-form').attr('action'), {
  183 + phoneNum: $('#phone-num').val(),
  184 + area: $('#country-code-hide').val()
  185 + }).then(function(result) {
  186 + if (result.code === 200) {
  187 + window.jumpUrl(result.data.refer);
  188 + return;
  189 + }
  190 +
  191 + if (result.code === 405) {
  192 + captcha.showTip(result.message);
  193 + $accErr.addClass('hide');
  194 + $phoneNum.removeClass('error');
  195 + return;
  196 + }
  197 +
  198 + $accErr.removeClass('hide').find('em').text(result.message);
  199 + $phoneNum.addClass('error');
  200 + });
  201 + });
  202 + }
  203 +
  204 + e.preventDefault();
  205 + return true;
  206 +});
  207 +
  208 +captcha.onSuccess(function() {
  209 + $btn.triggerHandler('click');
  210 +});