reset.page.js 1.88 KB
/*
 * @Author: Targaryen
 * @Date: 2017-04-13 14:43:19
 * @Last Modified by: Targaryen
 * @Last Modified time: 2017-04-14 17:53:47
 */

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

const $ = require('yoho-jquery');

require('common');

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

let $resetForm = $('.reset-form');
let $oldPasswordInput = $('#oldPassword');
let $newPasswordInput = $('#newPassword');
let $eye = $resetForm.find('.eye');
let $sureResetBtn = $('#sureResetBtn');
let $ignoreBtn = $('#ignoreBtn');

/**
 * 密码显示隐藏
 */
$eye.on('click', function() {
    if ($eye.hasClass('close')) {
        $newPasswordInput.attr('type', 'text');
        $eye.removeClass('close');
    } else {
        $newPasswordInput.attr('type', 'password');
        $eye.addClass('close');
    }
});

/**
 * 提交密码重置
 */
$sureResetBtn.on('click', function() {
    // 简单的密码校验
    if (!$oldPasswordInput.val() || !$newPasswordInput.val()) {
        tip.show('请输入旧密码和新密码');
        return false;
    }

    if (!validatePWD($newPasswordInput.val())) {
        tip.show('密码应为6-20位字母、数字的组合');
        return false;
    }

    $.ajax({
        type: 'post',
        url: '/passport/password/reset',
        data: {
            oldPwd: $oldPasswordInput.val(),
            newPwd: $newPasswordInput.val()
        },
        dataType: 'json',
        success: function(result) {
            tip.show(result.message);

            if (result.code === 200) {
                setTimeout(function() {
                    window.location.href = '/passport/login';
                }, 500);
            }
        },
        error: function() {
            tip.show('系统异常!');
        }
    });
});

/**
 * 跳过弱密码校验
 */
$ignoreBtn.on('click', function() {
    location.href = '/passport/login?isskip=Y';
});