コード例 #1
0
        public static bool CheckLogin(out string msg)
        {
            msg = "";
            object session = System.Web.HttpContext.Current.Session[Utility.Keys.SessionKeys.UserID.ToString()];
            Guid   uid;

            if (session == null || !session.ToString().IsGuid(out uid) || uid == Guid.Empty)
            {
                return(false);
            }

            #if DEBUG
            return(true); //正式使用时请注释掉这一行
            #endif

            string uniqueIDSessionKey = Utility.Keys.SessionKeys.UserUniqueID.ToString();
            var    user = new Business.Platform.OnlineUsers().Get(uid);
            if (user == null)
            {
                return(false);
            }
            else if (System.Web.HttpContext.Current.Session[uniqueIDSessionKey] == null)
            {
                return(false);
            }
            else if (string.Compare(System.Web.HttpContext.Current.Session[uniqueIDSessionKey].ToString(), user.UniqueID.ToString(), true) != 0)
            {
                msg = string.Format("<script type='text/javascript'>alert('您的帐号在{0}登录,您被迫下线!');top.location=top.rootdir+'/Login';</script>", user.IP);
                return(false);
            }
            return(true);
        }
コード例 #2
0
        private ActionResult query(FormCollection collection)
        {
            Business.Platform.OnlineUsers bou = new Business.Platform.OnlineUsers();
            string name = string.Empty;

            if (collection != null)
            {
                name = Request.Form["Name"];
            }
            else
            {
                name = Request.QueryString["Name"];
            }
            ViewBag.Name = name;
            var userList = bou.GetAll();

            if (!name.IsNullOrEmpty())
            {
                userList = userList.Where(p => p.UserName.IndexOf(name) >= 0).ToList();
            }

            return(View(userList));
        }
コード例 #3
0
        public ActionResult Index(FormCollection collection)
        {
            Business.Platform.OnlineUsers bou = new Business.Platform.OnlineUsers();
            if (!Request.Form["ClearAll"].IsNullOrEmpty())
            {
                bou.RemoveAll();
            }

            if (!Request.Form["ClearSelect"].IsNullOrEmpty())
            {
                string userids = Request.Form["checkbox_app"];
                foreach (string userid in userids.Split(','))
                {
                    Guid uid;
                    if (userid.IsGuid(out uid))
                    {
                        bou.Remove(uid);
                    }
                }
            }

            return(query(collection));
        }
コード例 #4
0
ファイル: LoginController.cs プロジェクト: uming45/RoadFlow
        public ActionResult Login(FormCollection collection)
        {
            string isVcodeSessionKey = Utility.Keys.SessionKeys.IsValidateCode.ToString();
            string vcodeSessionKey   = 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"];

            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";
                Business.Platform.Log.Add("用户登录失败", string.Concat("用户:", account, "登录失败,帐号或密码为空"), Business.Platform.Log.Types.用户登录);
                ViewBag.ErrMsg = "alert('帐号或密码不能为空!');";
            }
            else
            {
                Business.Platform.Users busers = new Business.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";
                    Business.Platform.Log.Add("用户登录失败", string.Concat("用户:", account, "登录失败,帐号或密码错误"), Business.Platform.Log.Types.用户登录);
                    ViewBag.ErrMsg = "alert('帐号或密码错误!');";
                }
                else if (user.Status == 1)
                {
                    System.Web.HttpContext.Current.Session[isVcodeSessionKey] = "1";
                    Business.Platform.Log.Add("用户登录失败", string.Concat("用户:", account, "登录失败,帐号已被冻结"), Business.Platform.Log.Types.用户登录);
                    ViewBag.ErrMsg = "alert('帐号已被冻结!');";
                }
                else
                {
                    Business.Platform.OnlineUsers bou = new Business.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[Utility.Keys.SessionKeys.UserID.ToString()]       = user.ID;
                        System.Web.HttpContext.Current.Session[Utility.Keys.SessionKeys.UserUniqueID.ToString()] = uniqueID;
                        System.Web.HttpContext.Current.Session[Utility.Keys.SessionKeys.BaseUrl.ToString()]      = Url.Content("~/");
                        bou.Add(user, uniqueID);
                        System.Web.HttpContext.Current.Session.Remove(isVcodeSessionKey);
                        Business.Platform.Log.Add("用户登录成功", string.Concat("用户:", user.Name, "(", user.ID, ")登录成功"), Business.Platform.Log.Types.用户登录);
                        ViewBag.Forcescript = "top.location='" + Url.Content("~/Home") + "';";
                    }
                }
            }
            return(View());
        }