コード例 #1
0
        public string ValidateLogin()
        {
            string str1 = this.Request.Form["Account"];
            string str2 = this.Request.Form["Password"];

            if (str1.IsNullOrEmpty() || str2.IsNullOrEmpty())
            {
                return("{\"id\":\"\",\"status\":0,\"msg\":\"帐号或密码不能为空\"}");
            }
            RoadFlow.Platform.Users   users     = new RoadFlow.Platform.Users();
            RoadFlow.Data.Model.Users byAccount = users.GetByAccount(str1.Trim());
            if (byAccount == null || string.Compare(byAccount.Password, users.GetUserEncryptionPassword(byAccount.ID.ToString(), str2.Trim()), false) != 0)
            {
                return("{\"id\":\"\",\"status\":0,\"msg\":\"帐号或密码错误\"}");
            }
            if (byAccount.Status == 1)
            {
                return("{\"id\":\"\",\"status\":0,\"msg\":\"帐号已被冻结\"}");
            }
            this.Session[Keys.SessionKeys.UserID.ToString()]   = (object)byAccount.ID;
            this.Session[Keys.SessionKeys.BaseUrl.ToString()]  = (object)this.Url.Content("~/");
            this.Session[Keys.SessionKeys.UserName.ToString()] = (object)byAccount.Name;
            this.Response.Cookies.Add(new HttpCookie(Keys.SessionKeys.UserID.ToString(), byAccount.ID.ToString())
            {
                Expires = MyController.CurrentDateTime.AddDays(7.0)
            });
            RoadFlow.Platform.Log.Add("用户登录成功-test(帐号:" + str1 + ")", "", RoadFlow.Platform.Log.Types.用户登录, "", "", (RoadFlow.Data.Model.Users)null);
            return("{\"id\":\"" + byAccount.ID.ToString() + "\",\"token\":\"" + RoadFlow.Utility.Config.GetTokenByUserId(byAccount.ID) + "\",\"status\":1,\"msg\":\"用户登录成功\"}");
        }
コード例 #2
0
ファイル: Login1.aspx.cs プロジェクト: zhibinyu/RoadFlow-2
        private void check()
        {
            string isVcodeSessionKey = RoadFlow.Utility.Keys.SessionKeys.IsValidateCode.ToString();
            string vcodeSessionKey   = RoadFlow.Utility.Keys.SessionKeys.ValidateCode.ToString();

            string account       = Request.Form["Account"];
            string password      = Request.Form["Password"];
            string force         = Request.Form["Force"];
            string vcode         = Request.Form["VCode"];
            bool   isSessionLost = "1" == Request.QueryString["session"];//是否是超时后再登录

            if (Session[isVcodeSessionKey] != null &&
                "1" == Session[isVcodeSessionKey].ToString() &&
                (Session[vcodeSessionKey] == null ||
                 string.Compare(Session[vcodeSessionKey].ToString(), vcode.Trim(), true) != 0))
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "error", "alert('验证码错误!');", true);
            }
            else if (account.IsNullOrEmpty() || password.IsNullOrEmpty())
            {
                Session[isVcodeSessionKey] = "1";
                RoadFlow.Platform.Log.Add("用户登录失败", string.Concat("用户:", account, "登录失败,帐号或密码为空"), RoadFlow.Platform.Log.Types.用户登录);
                Script = "alert('帐号或密码不能为空!');";
            }
            else
            {
                RoadFlow.Platform.Users busers = new RoadFlow.Platform.Users();
                var user = busers.GetByAccount(account.Trim());
                if (user == null || string.Compare(user.Password, busers.GetUserEncryptionPassword(user.ID.ToString(), password.Trim()), false) != 0)
                {
                    Session[isVcodeSessionKey] = "1";
                    RoadFlow.Platform.Log.Add("用户登录失败", string.Concat("用户:", account, "登录失败,帐号或密码错误"), RoadFlow.Platform.Log.Types.用户登录);
                    Script = "alert('帐号或密码错误!');";
                }
                else if (user.Status == 1)
                {
                    Session[isVcodeSessionKey] = "1";
                    RoadFlow.Platform.Log.Add("用户登录失败", string.Concat("用户:", account, "登录失败,帐号已被冻结"), RoadFlow.Platform.Log.Types.用户登录);
                    Script = "alert('帐号已被冻结!');";
                }
                else
                {
                    RoadFlow.Platform.OnlineUsers bou = new RoadFlow.Platform.OnlineUsers();
                    var onUser = bou.Get(user.ID);
                    if (onUser != null && "1" != force)
                    {
                        string ip = onUser.IP;
                        Session.Remove(isVcodeSessionKey);
                        Script = "if(confirm('当前帐号已经在" + ip + "登录,您要强行登录吗?')){$('#Account').val('" + account + "');$('#Password').val('" + password + "');$('#Force').val('1');$('#form1').submit();}";
                    }
                    else
                    {
                        Guid uniqueID = Guid.NewGuid();
                        Session[RoadFlow.Utility.Keys.SessionKeys.UserID.ToString()]       = user.ID;
                        Session[RoadFlow.Utility.Keys.SessionKeys.UserUniqueID.ToString()] = uniqueID;
                        bou.Add(user, uniqueID);
                        Session.Remove(isVcodeSessionKey);
                        RoadFlow.Platform.Log.Add("用户登录成功", string.Concat("用户:", user.Name, "(", user.ID, ")登录成功"), RoadFlow.Platform.Log.Types.用户登录);
                        if (isSessionLost)
                        {
                            Script = "alert('登录成功!');new RoadUI.Window().close();";
                        }
                        else
                        {
                            Script = "top.location='" + Common.Tools.BaseUrl + "Default.aspx';";
                        }
                    }
                }
            }
        }
コード例 #3
0
        public ActionResult Login(FormCollection collection)
        {
            string isVcodeSessionKey = RoadFlow.Utility.Keys.SessionKeys.IsValidateCode.ToString();
            string vcodeSessionKey   = RoadFlow.Utility.Keys.SessionKeys.ValidateCode.ToString();

            ViewBag.Forcescript       = "";
            ViewBag.IsVcodeSessionKey = isVcodeSessionKey;
            ViewBag.ErrMsg            = "";
            string account       = collection["Account"];
            string password      = collection["Password"];
            string force         = collection["Force"];
            string vcode         = collection["VCode"];
            bool   isSessionLost = "1" == Request.QueryString["session"];//是否是超时后再登录

            if (System.Web.HttpContext.Current.Session[isVcodeSessionKey] != null &&
                "1" == System.Web.HttpContext.Current.Session[isVcodeSessionKey].ToString() &&
                (System.Web.HttpContext.Current.Session[vcodeSessionKey] == null ||
                 string.Compare(System.Web.HttpContext.Current.Session[vcodeSessionKey].ToString(), vcode.Trim(), true) != 0))
            {
                ViewBag.ErrMsg = "alert('验证码错误!');";
            }
            else if (account.IsNullOrEmpty() || password.IsNullOrEmpty())
            {
                Session[isVcodeSessionKey] = "1";
                RoadFlow.Platform.Log.Add("用户登录失败", string.Concat("用户:", account, "登录失败,帐号或密码为空"), RoadFlow.Platform.Log.Types.用户登录);
                ViewBag.ErrMsg = "alert('帐号或密码不能为空!');";
            }
            else
            {
                RoadFlow.Platform.Users busers = new RoadFlow.Platform.Users();
                var user = busers.GetByAccount(account.Trim());
                if (user == null || string.Compare(user.Password, busers.GetUserEncryptionPassword(user.ID.ToString(), password.Trim()), false) != 0)
                {
                    System.Web.HttpContext.Current.Session[isVcodeSessionKey] = "1";
                    RoadFlow.Platform.Log.Add("用户登录失败", string.Concat("用户:", account, "登录失败,帐号或密码错误"), RoadFlow.Platform.Log.Types.用户登录);
                    ViewBag.ErrMsg = "alert('帐号或密码错误!');";
                }
                else if (user.Status == 1)
                {
                    System.Web.HttpContext.Current.Session[isVcodeSessionKey] = "1";
                    RoadFlow.Platform.Log.Add("用户登录失败", string.Concat("用户:", account, "登录失败,帐号已被冻结"), RoadFlow.Platform.Log.Types.用户登录);
                    ViewBag.ErrMsg = "alert('帐号已被冻结!');";
                }
                else
                {
                    RoadFlow.Platform.OnlineUsers bou = new RoadFlow.Platform.OnlineUsers();
                    var onUser = bou.Get(user.ID);
                    if (onUser != null && "1" != force)
                    {
                        string ip = onUser.IP;
                        System.Web.HttpContext.Current.Session.Remove(isVcodeSessionKey);
                        ViewBag.Forcescript = "if(confirm('当前帐号已经在" + ip + "登录,您要强行登录吗?')){$('#Account').val('" + account + "');$('#Password').val('" + password + "');$('#Force').val('1');$('#form1').submit();}";
                    }
                    else
                    {
                        Guid uniqueID = Guid.NewGuid();
                        System.Web.HttpContext.Current.Session[RoadFlow.Utility.Keys.SessionKeys.UserID.ToString()]       = user.ID;
                        System.Web.HttpContext.Current.Session[RoadFlow.Utility.Keys.SessionKeys.UserUniqueID.ToString()] = uniqueID;
                        System.Web.HttpContext.Current.Session[RoadFlow.Utility.Keys.SessionKeys.BaseUrl.ToString()]      = Url.Content("~/");
                        bou.Add(user, uniqueID);
                        System.Web.HttpContext.Current.Session.Remove(isVcodeSessionKey);
                        RoadFlow.Platform.Log.Add("用户登录成功", string.Concat("用户:", user.Name, "(", user.ID, ")登录成功"), RoadFlow.Platform.Log.Types.用户登录);
                        if (isSessionLost)
                        {
                            ViewBag.Forcescript = "alert('登录成功!');new RoadUI.Window().close();";
                        }
                        else
                        {
                            ViewBag.Forcescript = "top.location='" + Url.Content("~/Home") + "';";
                        }
                    }
                }
            }
            return(View());
        }
コード例 #4
0
        public string CheckLogin()
        {
            string name1  = Keys.SessionKeys.IsValidateCode.ToString();
            string index1 = Keys.SessionKeys.ValidateCode.ToString();
            string str1   = this.Request.Form["Account"];
            string str2   = this.Request.Form["Password"];
            string str3   = this.Request.Form["VCode"];
            string str4   = this.Request.Form["Force"];
            string str5   = "(帐号:" + str1 + " 密码:" + str2 + " 验证码:" + str3 + ")";

            if (str1.IsNullOrEmpty() || str2.IsNullOrEmpty())
            {
                RoadFlow.Platform.Log.Add("用户登录失败(帐号或密码为空)" + str5, "", RoadFlow.Platform.Log.Types.用户登录, "", "", (RoadFlow.Data.Model.Users)null);
                return("{\"status\":0,\"msg\":\"帐号或密码不能为空!\"}");
            }
            if (this.Session[name1] != null && "1" == this.Session[name1].ToString() && (this.Session[index1] == null || string.Compare(this.Session[index1].ToString(), str3.Trim1(), true) != 0))
            {
                RoadFlow.Platform.Log.Add("用户登录失败(验证码错误)" + str5, "", RoadFlow.Platform.Log.Types.用户登录, "", "", (RoadFlow.Data.Model.Users)null);
                return("{\"status\":0,\"msg\":\"验证码错误!\"}");
            }
            RoadFlow.Platform.Users   users     = new RoadFlow.Platform.Users();
            RoadFlow.Data.Model.Users byAccount = users.GetByAccount(str1.Trim());
            if (byAccount == null || string.Compare(byAccount.Password, users.GetUserEncryptionPassword(byAccount.ID.ToString(), str2.Trim()), false) != 0)
            {
                this.Session[name1] = (object)"1";
                RoadFlow.Platform.Log.Add("用户登录失败(帐号或密码错误)" + str5, "", RoadFlow.Platform.Log.Types.用户登录, "", "", (RoadFlow.Data.Model.Users)null);
                return("{\"status\":0,\"msg\":\"帐号或密码错误!\"}");
            }
            if (byAccount.Status == 1)
            {
                this.Session[name1] = (object)"1";
                RoadFlow.Platform.Log.Add("用户登录失败(帐号已被冻结)" + str5, "", RoadFlow.Platform.Log.Types.用户登录, "", "", (RoadFlow.Data.Model.Users)null);
                return("{\"status\":0,\"msg\":\"帐号已被冻结!\"}");
            }
            RoadFlow.Platform.OnlineUsers   onlineUsers1 = new RoadFlow.Platform.OnlineUsers();
            RoadFlow.Data.Model.OnlineUsers onlineUsers2 = onlineUsers1.Get(byAccount.ID);
            if (onlineUsers2 != null && "1" != str4)
            {
                string ip = onlineUsers2.IP;
                this.Session.Remove(name1);
                return("{\"status\":2,\"msg\":\"当前帐号已经在" + ip + "登录,您要强行登录吗?\"}");
            }
            Guid uniqueID = Guid.NewGuid();

            this.Session[Keys.SessionKeys.UserID.ToString()] = (object)byAccount.ID;
            HttpSessionStateBase session1 = this.Session;

            Keys.SessionKeys sessionKeys = Keys.SessionKeys.UserUniqueID;
            string           index2      = sessionKeys.ToString();
            // ISSUE: variable of a boxed type
            __Boxed <Guid> local = (ValueType)uniqueID;

            session1[index2] = (object)local;
            HttpSessionStateBase session2 = this.Session;

            sessionKeys = Keys.SessionKeys.BaseUrl;
            string index3 = sessionKeys.ToString();
            string str6   = this.Url.Content("~/");

            session2[index3] = (object)str6;
            HttpSessionStateBase session3 = this.Session;

            sessionKeys = Keys.SessionKeys.UserName;
            string index4 = sessionKeys.ToString();
            string name2  = byAccount.Name;

            session3[index4] = (object)name2;
            HttpCookieCollection cookies = this.Response.Cookies;

            sessionKeys = Keys.SessionKeys.UserID;
            cookies.Add(new HttpCookie(sessionKeys.ToString(), byAccount.ID.ToString())
            {
                Expires = MyController.CurrentDateTime.AddDays(7.0)
            });
            onlineUsers1.Add(byAccount, uniqueID);
            this.Session.Remove(name1);
            RoadFlow.Platform.Log.Add("用户登录成功(帐号:" + str1 + ")", "", RoadFlow.Platform.Log.Types.用户登录, "", "", (RoadFlow.Data.Model.Users)null);
            return("{\"status\":1,\"msg\":\"成功!\"}");
        }