Пример #1
0
        /// <summary>
        /// 统一登录处理
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password">SHA1加密后的密码</param>
        /// <returns></returns>
        public static string LoginDeal(HttpContextBase context, string userName, string password)
        {
            if (userName == "")
                return "用户名不能为空";
            if (password == "")
                return "密码不能为空";

            string ip = Public.CommonHelper.GetIPAddress();
            bizUsers b = new bizUsers();
            bizUserPwdLog bul = new bizUserPwdLog();
            int testLoginNum = bul.GetNum(ip);
            if (testLoginNum >= 5)
            {
                return "请稍后再试";
            }
            Users model = b.Get(userName);
            if (model == null || MyText.GetEncrypt(model.Password) != password)
            {
                bul.Add(MyText.SafeStr(userName), password, ip);
                return "用户名或密码错误,你还有" + (5 - testLoginNum) + "次机会";
            }
            if ((new bizForbidIP()).Exist(ip))
            {
                return "你的IP已被封";
            }

            //设置Session
            SessionInfo modelSession = new SessionInfo();
            modelSession.UserID = model.UserID;
            modelSession.UserName = model.UserName;
            modelSession.AdminType = model.AdminType;
            modelSession.ShowAllQM = UserCommon.ShowAllQM(model.UserConfig);
            modelSession.ShowSelfQM = UserCommon.ShowSelfQM(model.UserConfig);
            modelSession.ShowPopup = UserCommon.ShowPopup(model.UserConfig);
            modelSession.MaxBBSNoticeID = MyCache.BBSCache.maxBBSNoticeID;
            modelSession.FactionID = model.FactionID;
            modelSession.FactionDeID = model.FactionDeID;

            SessionOper.SessionSet(context, model.UserID, modelSession, true);

            b.LoginDeal(model.UserID, ip);
            SZXX.Common.Untilies.OnlineUsers.Instance.AddUser(model.UserID, model.UserName, model.UserColor, model.AdminType);

            //设置Cookie
            HttpCookie myc = new HttpCookie("MyInfo");
            myc["Name"] = HttpUtility.UrlEncode(model.UserName);
            myc["Code"] = MyText.GetEncrypt(model.Password);
            myc.Expires = DateTime.Now.AddYears(1);
            myc.Domain = ConfigurationManager.AppSettings["RootDomain"];
            HttpContext.Current.Response.AppendCookie(myc);

            return "";
        }