password.js 1.75 KB
/**
 * 注册-密码
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/10/8
 */
var $ = require('yoho.zepto');

var $pwd = $('#pwd'),
    $btnSure = $('#btn-sure');

var api = require('../api');
var tip = require('../../plugin/tip');

var trim = $.trim;
var showErrTip = tip.show;

api.bindEyesEvt({
    status: 'open' //默认眼睛打开
});

$pwd.bind('input', function() {
    if (trim($pwd.val()) === '') {
        $btnSure.addClass('disable');
    } else {
        $btnSure.removeClass('disable');
    }
});

$btnSure.on('tap', function() {
    var pwd = trim($pwd.val());

    if ($btnSure.hasClass('disable')) {
        return;
    }

    if (api.pwdValidate(pwd) === false) {
        showErrTip('密码6-20位,请重新输入');
    } else {
        $.ajax({
            type: 'POST',
            url: '/passport/reg/setpassword',
            data: {
                password: pwd,
                phoneNum: $('#phone-num').val(),
                areaCode: $('#area-code').val(),
                token: $('#token').val()
            },
            success: function(data) {
                if (data.code === 200) {
                    showErrTip('注册成功');

                    //1000ms后跳转页面
                    setTimeout(function() {
                        location.href = data.data;
                    }, 1000);
                } else {
                    if (data.code === 401 || data.code === 404 || data.code === 505) {
                        showErrTip(data.message);
                    } else {
                        showErrTip(data.message);
                        setTimeout(function() {
                            location.href = data.data;
                        }, 1000);
                    }
                }
            }
        });
    }
});