Пример #1
0
        public static bool IsAdminLogin()
        {
            //如果Session为Null
            if (System.Web.HttpContext.Current.Session[KeyWordsHelper.SessionManager] != null)
            {
                return(true);
            }
            //检查Cookies
            var adminname = CookieHelper.Get("AdminName");
            var adminpwd  = CookieHelper.Get("AdminPwd");

            if (!string.IsNullOrEmpty(adminname) && !string.IsNullOrEmpty(adminpwd))
            {
                var model = new Dal.Manager().QueryToEnetity(p => p.Username == adminname && p.Password == adminpwd);
                if (model == null)
                {
                    return(false);
                }

                CookieHelper.Set("AdminName", model.Username, 1200);
                CookieHelper.Set("AdminPwd", model.Password, 1200);

                System.Web.HttpContext.Current.Session[KeyWordsHelper.SessionManager] = model;
                System.Web.HttpContext.Current.Session.Timeout = 20;
                return(true);
            }
            return(false);
        }
Пример #2
0
        public ActionResult LoginMin(Manager model)
        {
            var jm = new JsonWithUIcallback();

            try
            {
                var bll = new Dal.Manager();
                if (string.IsNullOrEmpty(model.Username) || string.IsNullOrEmpty(model.Password))
                {
                    jm.message = "请输入用户名和密码!";
                    return(Json(jm));
                }
                var md5Pwd  = ToolsHelper.Md5(model.Password);
                var manager = bll.QueryToEnetity(p => p.Username == model.Username && p.Password == md5Pwd);
                if (manager == null)
                {
                    jm.message = "账户密码错误!";
                    return(Json(jm));
                }
                //写入数据库日志
                var mlog = new ManagerLog
                {
                    UserId     = manager.Id,
                    UserName   = manager.Username,
                    ActionType = "Login",
                    AddTime    = DateTime.Now,
                    Remark     = "后台管理登录",
                    UserIp     = RequestHelper.GetIp()
                };
                new Dal.ManagerLog().Insert(mlog);

                //修改登录时间
                manager.LastLoginTime = DateTime.Now;
                bll.Update(manager);

                //写入session
                System.Web.HttpContext.Current.Session.Timeout = 20;
                System.Web.HttpContext.Current.Session[KeyWordsHelper.SessionManager] = manager;


                //写入cookie
                CookieHelper.Set("AdminName", model.Username, 1200);
                CookieHelper.Set("AdminPwd", md5Pwd, 1200);

                jm.statusCode = 200;
                jm.message    = "登录成功!";
                //jm.forward = "/Admins/Panel/";
                jm.closeCurrent = true;
                return(Json(jm));
            }
            catch (Exception ex)
            {
                ComToolsController.AddtxtLog(ex, model.Username + "登录", "Login");
                jm.message = "数据异常";
            }
            return(Json(jm));
        }
Пример #3
0
        public ActionResult ChangePwd(string password)
        {
            var jm      = new JsonWithUIcallback();
            var manager = GetAdminsInfo();

            manager.Password = ToolsHelper.Md5(password);
            var bl = new Dal.Manager().Update(manager) > 0;

            jm.statusCode   = bl ? 200 : 300;
            jm.message      = "修改成功";
            jm.closeCurrent = bl;

            //重置账户密码
            Session[KeyWordsHelper.SessionManager] = null;
            CookieHelper.Remove("AdminName");
            CookieHelper.Remove("AdminPwd");

            return(Json(jm));
        }
Пример #4
0
        public ActionResult VerifyUserName()
        {
            var ok       = new JsonWithNiceValidaorOk();
            var error    = new JsonWithNiceValidaorError();
            var username = RequestHelper.GetFormString("Username");

            if (string.IsNullOrEmpty(username))
            {
                error.error = "请填写用户名";
                return(Json(error));
            }
            var bll = new Dal.Manager().Exists(p => p.Username == username);

            if (bll)
            {
                error.error = "用户名已存在,请重新输入";
                return(Json(error));
            }
            return(Json(ok));
        }