Blame view

public/js/passport/reset.page.js 2.8 KB
郭成尧 authored
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * @Author: Targaryen
 * @Date: 2017-04-13 14:43:19
 * @Last Modified by: Targaryen
 */

/* ***************
 * 密码重置
 *****************/

const $ = require('yoho-jquery');
郭成尧 authored
13
require('common');
郭成尧 authored
14 15 16 17 18 19 20

let validatePWD = require('./password-check');
let tip = require('plugin/tip');

let $resetForm = $('.reset-form');
let $oldPasswordInput = $('#oldPassword');
let $newPasswordInput = $('#newPassword');
郭成尧 authored
21 22
let $oldEye = $resetForm.find('#oldEye');
let $newEye = $resetForm.find('#newEye');
郭成尧 authored
23
let $sureResetBtn = $('#sureResetBtn');
郭成尧 authored
24
let $tipBottom = $('#tipBottom');
郭成尧 authored
25 26 27 28 29 30 31 32

// 登录按钮状态切换
function switchLoginBtnStatus() {
    let active = ($oldPasswordInput.val() && $newPasswordInput.val()) ? true : false;

    $sureResetBtn.toggleClass('active', active);
}
郭成尧 authored
33 34 35 36 37 38 39 40 41 42 43
/**
 * 是否显示 TIP
 */

$newPasswordInput.focus(function() {
    $tipBottom.addClass('show');
});

$newPasswordInput.blur(function() {
    $tipBottom.removeClass('show');
});
郭成尧 authored
44 45 46 47 48 49

$oldPasswordInput.bind('input', function() {
    switchLoginBtnStatus();
});

$newPasswordInput.bind('input', function() {
郭成尧 authored
50 51 52
    if (!$tipBottom.hasClass('show')) {
        $tipBottom.addClass('show');
    }
郭成尧 authored
53 54
    switchLoginBtnStatus();
});
郭成尧 authored
55
郭成尧 authored
56 57 58 59 60 61 62 63 64 65 66 67 68 69

/**
 * 旧密码显示隐藏
 */
$oldEye.on('click', function() {
    if ($oldEye.hasClass('close')) {
        $oldPasswordInput.attr('type', 'text');
        $oldEye.removeClass('close');
    } else {
        $oldPasswordInput.attr('type', 'password');
        $oldEye.addClass('close');
    }
});
郭成尧 authored
70
/**
郭成尧 authored
71
 * 新密码显示隐藏
郭成尧 authored
72
 */
郭成尧 authored
73 74
$newEye.on('click', function() {
    if ($newEye.hasClass('close')) {
郭成尧 authored
75
        $newPasswordInput.attr('type', 'text');
郭成尧 authored
76
        $newEye.removeClass('close');
郭成尧 authored
77 78
    } else {
        $newPasswordInput.attr('type', 'password');
郭成尧 authored
79
        $newEye.addClass('close');
郭成尧 authored
80 81 82 83 84 85 86
    }
});

/**
 * 提交密码重置
 */
$sureResetBtn.on('click', function() {
郭成尧 authored
87 88 89 90
    if (!$sureResetBtn.hasClass('active')) {
        return false;
    }
郭成尧 authored
91 92 93 94 95 96 97
    // 简单的密码校验
    if (!$oldPasswordInput.val() || !$newPasswordInput.val()) {
        tip.show('请输入旧密码和新密码');
        return false;
    }

    if (!validatePWD($newPasswordInput.val())) {
郭成尧 authored
98
        tip.show('密码应为6-20位字母、数字的组合');
郭成尧 authored
99 100 101 102 103 104 105
        return false;
    }

    $.ajax({
        type: 'post',
        url: '/passport/password/reset',
        data: {
郭成尧 authored
106 107
            oldPwd: $oldPasswordInput.val(),
            newPwd: $newPasswordInput.val()
郭成尧 authored
108 109 110
        },
        dataType: 'json',
        success: function(result) {
郭成尧 authored
111 112 113 114
            if (result.code === 200) {
                window.location.href = '/passport/password/resetsuccess';
                return false;
            }
郭成尧 authored
115
郭成尧 authored
116
            if (result.code === 402) {
郭成尧 authored
117
                window.location.href = '/signin.html';
郭成尧 authored
118 119 120 121 122 123 124
            }
        },
        error: function() {
            tip.show('系统异常!');
        }
    });
});