登陆验证(ajax)

来源:互联网 发布:海南省最新网络诈骗案 编辑:程序博客网 时间:2024/05/17 03:55

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
原创粉丝点击