javascript 实现用户登录、注册Panel

这个是我在单点登录时,用到的用javascrpit实现的用户登录、注册Panel,其中为了避免命名上的部突,参照了ext 实现namespace的做法,我实现了一把,不过很做得很简单。如下

 //从Ext借来的命名空间
var TWJavascript =
         {
             namespace: function() {
                 var a = arguments, o = null, i, j, d, rt;
                 for (i = 0; i < a.length; ++i) {
                     d = a[i].split(".");
                     rt = d[0];
                     eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = ' + rt + ';');
                     for (j = 1; j < d.length; ++j) {
                         o[d[j]] = o[d[j]] || {};
                         o = o[d[j]];
                     }
                 }
             }
         }


TWJavascript.namespace("appPath_UserCenter");
appPath_UserCenter.getAppPath = function() {
    var root = ConfigUrl.Url.UserCenterUrl;
    return root;
}

var returnUrl = window.location.href;
var appPathOfUserCenter = appPath_UserCenter.getAppPath();
var registUrl = String.format("{0}/MembershipRegist/Regist.aspx?returnUrl={1}", appPathOfUserCenter, returnUrl);
var loginUrl = String.format("{0}/SignIn.aspx?returnUrl={1}", appPathOfUserCenter, returnUrl);
var signOutUrl = String.format("{0}/SignOut.aspx", appPathOfUserCenter);
var centerUrl = String.format("{0}/ShoppingCart/CartProductList.aspx", appPathOfUserCenter);

var UserCenter = {

    Paramers:
    {
        userName: GetCookieByName("TW_User", "TWUserName"),
        dataTime: GetCookieByName("TW_User", "TWDataTime"),
        userID: GetCookieByName("TW_User", "TWUserID"),
        token: GetCookieByName("TW_User", "TWEncryptToken")
    },

    LoginPanel: function() {
        var stringBuilder = "";
        if (UserCenter.Paramers.userName.length > 0) {
            stringBuilder = String.format("<span style=\"float:right\">您好,{0},欢迎您。<a href=\"{1}\" target=\"_blank\">会员中心</a>&nbsp;&nbsp;<a href=\"{2}\" style=color:red><u>注销</u></a></span>", UserCenter.Paramers.userName, centerUrl, signOutUrl);
        }
        else {
            stringBuilder = String.format("<span><a href=\"{0}\" class=gb1>免费注册</a></span>&nbsp|&nbsp;&nbsp;", registUrl);
            stringBuilder += String.format("<span><a href=\"{0}\" class=gb1>登录</a></span>", loginUrl);
        }
        stringBuilder = String.format("<div  style=\"float:right\">{0}</div>", stringBuilder);
        document.getElementById("loginstatus").innerHTML = stringBuilder;
    }
}

 

转载于:https://www.cnblogs.com/Breaker/archive/2010/01/06/1640806.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值