登陆验证(ajax)

1. login.ftl

<form id="userLogonForm" method="post" name="Logon" action="loginSubmit.jhtml">
    <ul>
        <li>
            <label>個人郵箱</label>
            <input type="text" id="loginEmail" name="loginEmail"/>
       </li>
        <li>
            <label> 密码 </label> 
            <input type="password" id="loginPassword" name="loginPassword"/>        
       </li>
  </ul>
    <div class="actions">
         <button id="loginBtn" type="button" value="登陆">
                <span>登陆</span>
        </button>
    </div>
</form>

2.js

$loginBtn.click(function() {
    if (loginValidate()) {
                userLogin($loginPassword, $userLogonForm,$loginEmail, $itxLoading, request);
                         }
});
/**
 * 登录校验
 */
function loginValidate() {
    var flag = true;
    var $loginEmail = $("#loginEmail");
    var $loginPassword = $("#loginPassword");
    var regular = /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/;
    var illegalMsg = message('shop.validate.emailIllegal');
    if (!$loginEmail.val()) {
        $.message("warn", message('shop.login.username.notEmpty'));
        $loginEmail.focus();
        flag = false;
    } else if (!regular.test($loginEmail.val())) {
        $.message("warn", illegalMsg);
        $loginEmail.focus();
        flag = false;
    } else if (!$loginPassword.val()) {
        $.message("warn", message('shop.login.password.notEmpty'));
        $loginPassword.focus();
        flag = false;
    }
    return flag;
}
/**
 * 用户登录
 * 
 * @param $loginPassword
 * @param $userLogonForm
 * @param $loginEmail
 */
function userLogin($loginPassword, $userLogonForm, $loginEmail, $itxLoading,request) {
            $.ajax({
                url : moshop.base + "/common/public_key.jhtml",
                type : "GET",
                dataType : "json",
                cache : false,
                success : function(data) {
                    var rsaKey = new RSAKey();
                    rsaKey.setPublic(b64tohex(data.modulus),
                    b64tohex(data.exponent));
                    var enPassword = hex2b64(rsaKey.encrypt($loginPassword.val()));
                    $.ajax({
                                url : $userLogonForm.attr("action"),
                                type : "POST",
                                data : {
                                    username : $loginEmail.val(),
                                    enPassword : enPassword
                                },
                                dataType : "json",
                                cache : false,
                                beforeSend : function() {
                                    $itxLoading.show();
                                },
                                success : function(message) {
                                    if (message.type == "success") {
                                        headerMenuControl();
                                        closeDiv();
                                        if (getCookie('fromCart')) {
                                            var $accountingType = $('input[name="accountingType"]:checked').val();
                                            window.location.href = '/info.jhtml?accountingType=' + $accountingType;
                                        } else {
                                            if (request['redirectUrl']) {
                                                document.location.href = request['redirectUrl'];
                                            } else {
                                                document.location.href = moshop.base + '/common/default.jhtml';
                                            }
                                        }
                                    } else {
                                        $.message('warn', message.content);
                                        return;
                                    }
                                }
                            });
                }
            });
}

注意对于:

var $accountingType = $('input[name="accountingType"]:checked').val();

有:

 <input type="radio" class="in" name="accountingType" value="RMB" checked="checked">
 <input type="radio" class="in" name="accountingType" value="DOLLARS">

注意:对于headerMenuControl();

/**
 * header menu Control
 */
function headerMenuControl() {
    var $profile_name = $("#profile_name");
    var name = getCookie("name");
    $profile_name.text(name);
    $("#register").css({
        'display' : 'none'
    });
    $("#showlogin").css({
        'display' : 'none'
    });
    $("#logout").css({
        'display' : 'block'
    });
    $("#usercenter").css({
        'display' : 'block'
    });
}

对于:closeDiv();//关闭所有弹出层

function closeDiv() {
    hiddenMask();
    $("#loginPapal").fadeOut('normal');
    $("#registerUserPanel").fadeOut('normal');
    $("#changeCurrency").fadeOut('normal');
}
/**
 * 单击事件,Mask罩盖层被销毁
 */
function hiddenMask() {
    var $itxOverlay_header = $("#itxOverlay-header");
    $itxOverlay_header.fadeTo('slow', 0, function() {
        $itxOverlay_header.hide();
    });
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值