Example #1
0
        /// <summary>
        /// FormsAuthentication
        /// </summary>
        /// <param name="userAccountEntity">用户信息</param>
        public static string SetFormsAuthentication(UserAccountEntity userAccountEntity)
        {
            Int32  timeout  = 14400;
            string userData = userAccountEntity.ToString();
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(2, userAccountEntity.Account, DateTime.Now, DateTime.Now.AddMinutes(timeout), false,
                                                                             userData, FormsAuthentication.FormsCookiePath);
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName);

            cookie.Value   = FormsAuthentication.Encrypt(ticket);
            cookie.Expires = ticket.Expiration;
            HttpContext.Current.Response.Cookies.Add(cookie);

            HttpContext.Current.User =
                new System.Security.Principal.GenericPrincipal(
                    new System.Security.Principal.GenericIdentity(userAccountEntity.Account), new string[0]);
            return(cookie.Value);
        }
Example #2
0
 private bool doLogin()
 {
     try
     {
         var platformId = ddlPlatform.SelectedValue;
         var user       = NbUserMgr.GetByAccount(UserName, Request.UserHostAddress, DateTime.Today.AddDays(-1),
                                                 DateTime.Today, 0);
         var sessionId = ShareUtil.GenerateComb().ToString();
         if (user != null)
         {
             UserAccountEntity userAccountEntity = new UserAccountEntity(user.Account, Guid.Empty, "", 1,
                                                                         platformId, sessionId);
             userAccountEntity.ExtraData = "d|pengyou|f";
             FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.Account,
                                                                              DateTime.Now,
                                                                              DateTime.Now.AddDays(10),
                                                                              false, userAccountEntity.ToString(),
                                                                              FormsAuthentication
                                                                              .FormsCookiePath);
             var cookie = FormsAuthentication.Encrypt(ticket);
             Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, cookie));
             // OnlineMgr.LoginSession(info.Data.ManagerInfo.Manager.Idx, sessionId);
             return(true);
         }
         else
         {
             ResponseMessage("用户名不存在");
             return(false);
         }
     }
     catch (Exception ex)
     {
         LogHelper.Insert(ex);
         ResponseMessage(ex.Message);
         return(false);
     }
 }
Example #3
0
        private bool doLoginNew(ref string cookie)
        {
            try
            {
                TxLogininfoEntity tLoginInfo = null;
                var platformId = GetParam("platform");
                var userName   = GetParam("openid");
                if (ShareUtil.IsQunHei)
                {
                    userName = GetParam("username");
                }
                //if (userName.Length>0 && userName.Contains("h5_zhiqu"))
                //    return false;
                var user = NbUserMgr.GetByAccount(userName, GetIp(), DateTime.Today.AddDays(-1),
                                                  DateTime.Today, 0);
                var sessionId = ShareUtil.GenerateComb().ToString();
                if (user != null)
                {
                    UserAccountEntity userAccountEntity = new UserAccountEntity(user.Account, Guid.Empty, "", 1,
                                                                                platformId, sessionId);
                    userAccountEntity.ExtraData = "d|pengyou|f";


                    var info = reader.GetManagerInfoByAccount(userAccountEntity.Account, GetIp(),
                                                              UAFactory.Instance.IsTx);
                    if (info.Code == (int)MessageCode.Success)
                    {
                        if (info.Data.NeedSelect == false)
                        {
                            if (ShareUtil.IsTx)
                            {
                                string openKey = GetParam("openkey");
                                string pf      = GetParam("pf");
                                if (string.IsNullOrEmpty(pf))
                                {
                                    pf = "wanba_ts";
                                }
                                string platform = GetParam("platform");
                                //userip
                                //sig
                                int    appId  = UAFactory.Instance.TxAppId;
                                string appKey = UAFactory.Instance.TxAppKey;
                                var    result = WbUserInfo(userName, openKey, pf, platform, appId, appKey);
                                if (result != 0)
                                {
                                    OutputHelper.Output(result);
                                }
                                tLoginInfo = new TxLogininfoEntity(userName, openKey, pf, platform, "",
                                                                   "", DateTime.Now, DateTime.Now);
                            }
                            if (info.Data.ManagerInfo == null)
                            {
                                string playerName = "";
                                string logo       = "1";
                                int    templateId = 1;
                                var    createData = reader.CreateManager(UserAccount.Account, playerName, logo, templateId,
                                                                         UAHelper.GetRealIP());
                                if (createData.Code != (int)MessageCode.Success)
                                {
                                    info.Code = createData.Code;
                                    OutputHelper.Output(info);
                                }
                                info = reader.GetManagerInfoByAccount(UserAccount.Account, GetIp(),
                                                                      UAFactory.Instance.IsTx);;
                            }
                            try
                            {
                                if (ShareUtil.IsH5A8)
                                {
                                    UA_A8.UserAction("entergame", info.Data.ManagerInfo.Manager.Account, "", "",
                                                     info.Data.ManagerInfo.Manager);
                                }
                            }
                            catch (Exception)
                            {
                            }
                            if (CheckLockState(info.Data.ManagerInfo.Manager.Idx))
                            {
                                OutputHelper.Output(MessageCode.LoginOnlineLock);
                            }
                            //写入登录信息
                            cookie = UAHelper.SetFormsAuthentication(userAccountEntity.Account,
                                                                     info.Data.ManagerInfo.Manager.Idx,
                                                                     info.Data.ManagerInfo.Manager.Name, 1, sessionId);
                            OnlineMgr.LoginSession(info.Data.ManagerInfo.Manager.Idx, sessionId);
                            onlineClient.RiseOnlineTime(info.Data.ManagerInfo.Manager.Idx);
                            info.Data.Cookie = cookie;
                            Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, cookie));
                            var isSubscribe = GetParamBool("isSubscribe");
                            if (isSubscribe)//关注
                            {
                                activityClient.DoShare(info.Data.ManagerInfo.Manager.Idx, 4);
                            }
                            if (ShareUtil.IsTx)
                            {
                                TxLogininfoMgr.InsertUpdate(tLoginInfo);
                            }
                            return(true);
                        }
                        return(true);
                    }
                    else
                    {
                        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.Account,
                                                                                         DateTime.Now,
                                                                                         DateTime.Now.AddDays(10),
                                                                                         false, userAccountEntity.ToString(),
                                                                                         FormsAuthentication
                                                                                         .FormsCookiePath);
                        cookie = FormsAuthentication.Encrypt(ticket);
                        Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, cookie));
                        return(false);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                cookie = ex.ToString();
                return(true);
            }
        }
Example #4
0
        private bool doLogin(ref string cookie)
        {
            try
            {
                var platformId = GetParam("platform");
                var userName   = GetParamNOUrlDecode("username");
                //if (userName.Length > 0 && userName.Contains("h5_zhiqu"))
                //    return false;
                var user = NbUserMgr.GetByAccount(userName, GetIp(), DateTime.Today.AddDays(-1),
                                                  DateTime.Today, 0);
                var sessionId = ShareUtil.GenerateComb().ToString();
                if (user != null)
                {
                    UserAccountEntity userAccountEntity = new UserAccountEntity(user.Account, Guid.Empty, "", 1,
                                                                                platformId, sessionId);
                    userAccountEntity.ExtraData = "d|pengyou|f";


                    var info = reader.GetManagerInfoByAccount(userAccountEntity.Account, GetIp(),
                                                              UAFactory.Instance.IsTx);
                    if (info.Code == (int)MessageCode.Success)
                    {
                        if (info.Data.NeedSelect == false)
                        {
                            if (info.Data.ManagerInfo == null)
                            {
                                string playerName = "";
                                string logo       = "1";
                                int    templateId = 1;
                                var    createData = reader.CreateManager(UserAccount.Account, playerName, logo, templateId,
                                                                         UAHelper.GetRealIP());
                                if (createData.Code != (int)MessageCode.Success)
                                {
                                    info.Code = createData.Code;
                                    OutputHelper.Output(info);
                                }
                                info = reader.GetManagerInfoByAccount(UserAccount.Account, GetIp(),
                                                                      UAFactory.Instance.IsTx);;
                            }

                            if (CheckLockState(info.Data.ManagerInfo.Manager.Idx))
                            {
                                OutputHelper.Output(MessageCode.LoginOnlineLock);
                            }
                            //写入登录信息
                            cookie = UAHelper.SetFormsAuthentication(userAccountEntity.Account,
                                                                     info.Data.ManagerInfo.Manager.Idx,
                                                                     info.Data.ManagerInfo.Manager.Name, 1, sessionId);
                            OnlineMgr.LoginSession(info.Data.ManagerInfo.Manager.Idx, sessionId);
                            onlineClient.RiseOnlineTime(info.Data.ManagerInfo.Manager.Idx);
                            info.Data.Cookie = cookie;
                            Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, cookie));

                            return(true);
                        }
                        return(true);
                    }
                    else
                    {
                        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.Account,
                                                                                         DateTime.Now,
                                                                                         DateTime.Now.AddDays(10),
                                                                                         false, userAccountEntity.ToString(),
                                                                                         FormsAuthentication
                                                                                         .FormsCookiePath);
                        cookie = FormsAuthentication.Encrypt(ticket);
                        Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, cookie));
                        return(false);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                cookie = ex.ToString();
                return(true);
            }
        }