Example #1
0
        //#endregion
        /// <summary>
        /// 获取指定ID的数据
        /// </summary>
        public ActionResult GetDetail()
        {
            int id   = Request.Form["id"] != "" ? int.Parse(Request.Form["id"]) : 0;
            var item = SysUserDao.Instance.QueryOne(id);

            item.RoleIDs = SysUserServices.GetRoleIDs(item.ID);
            return(Json(item));
        }
Example #2
0
 /// <summary>
 /// 获得车场所有用户
 /// </summary>
 /// <returns></returns>
 public string GetUserByParkingID(string pkid)
 {
     try
     {
         return(JsonHelper.GetJsonString(SysUserServices.QuerySysUserByParkingId(pkid)));
     }
     catch
     {
         return("");
     }
 }
Example #3
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            try
            {
                SysUser user = null;
                if (filterContext.HttpContext.Session["SmartSystem_SystemLoginUser"] == null)
                {
                    var userAccountCookie = filterContext.HttpContext.Request.Cookies["SmartSystem_Current_Login_UserAccount"];
                    var passwordCookie    = filterContext.HttpContext.Request.Cookies["SmartSystem_Current_Login_Password"];
                    if (userAccountCookie != null && passwordCookie != null)
                    {
                        string  account = userAccountCookie.Value;
                        string  pwd     = DES.DESDeCode(passwordCookie.Value, "Password");
                        SysUser sysUser = SysUserServices.QuerySysUserByUserAccount(account);
                        if (sysUser != null && sysUser.Password.Equals(MD5.Encrypt(pwd)))
                        {
                            user = sysUser;
                            filterContext.HttpContext.Session["SmartSystem_SystemLoginUser"] = user;
                        }
                    }

                    if (user == null)
                    {
                        string response_js = "<script>window.parent.location.href='/ErrorPrompt/Index?message=登录超时,请重新登录&returnUrl=/AdminLogin/Index';</script>";
                        filterContext.HttpContext.Response.Write(response_js);
                        return;
                    }
                }
                user = (SysUser)filterContext.HttpContext.Session["SmartSystem_SystemLoginUser"];
                if (user != null && (filterContext.HttpContext.Session["SmartSystem_LoginUser_ValidVillage"] == null ||
                                     filterContext.HttpContext.Session["SmartSystem_LoginUser_ValidCompany"] == null ||
                                     filterContext.HttpContext.Session["SmartSystem_SystemLoginUser_Role"] == null ||
                                     filterContext.HttpContext.Session["SmartSystem_LoginUser_SysRoleAuthorize"] == null))
                {
                    CacheData.CacheUserLoginData(user);
                }

                HttpContext.Current.Session["SmartSystem_LogFrom"] = LogFrom.WeiXin;
                if (user == null)
                {
                    string response_js = "<script>window.parent.location.href='/AdminLogin/Index';</script>";
                    filterContext.HttpContext.Response.Write(response_js);
                    return;
                }
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "验证微信管理员是否登录失败");
                string response_js = "<script>window.parent.location.href='/ErrorPrompt/Index?message=验证微信管理员是否登录失败&returnUrl=/AdminLogin/Index';</script>";
                filterContext.HttpContext.Response.Write(response_js);
                return;
            }
        }
Example #4
0
        /// <summary>
        /// 当班人
        /// </summary>
        /// <returns></returns>
        public JsonResult GetOnDutys()
        {
            string     parkingid = Request.Params["parkingid"];
            JsonResult json      = new JsonResult();

            try
            {
                json.Data = SysUserServices.QuerySysUserByParkingId(parkingid);
            }
            catch
            { }
            return(json);
        }
Example #5
0
        public ActionResult Index(string userAccount, string password, bool rememberPassWord = false)
        {
            UserLoginModel model = new UserLoginModel();

            model.UserAccount      = userAccount;
            model.Password         = password;
            model.RememberPassword = rememberPassWord;

            try
            {
                SysUser user = SysUserServices.QuerySysUserByUserAccount(userAccount);
                if (user == null)
                {
                    model.ErrorMessage = "用户名或密码错误";
                    return(View(model));
                }
                if (!user.Password.Equals(MD5.Encrypt(model.Password)))
                {
                    model.ErrorMessage = "用户名或密码错误";
                    SysUserServices.LoginError(user.RecordID);
                    return(View(model));
                }

                if (user.DataStatus == DataStatus.Delete)
                {
                    model.ErrorMessage = "用户不存在";
                    return(View(model));
                }
                if (user.DataStatus != DataStatus.Normal)
                {
                    model.ErrorMessage = "账号不是有效状态,请联系系统管理员";
                    SysUserServices.LoginError(user.RecordID);
                    return(View(model));
                }
                LoginSuccess(model, user);
                CacheData.CacheUserLoginData(user);
                Session["SmartSystem_OperatorUserAccount"] = user.UserAccount;
                Session["SmartSystem_LogFrom"]             = LogFrom.OmnipotentCard;
                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception ex)
            {
                model.ErrorMessage = "登录异常";
                ExceptionsServices.AddExceptions(ex, "登录异常");
                return(View(model));
            }
        }
Example #6
0
        private bool CheckUserRole(AuthorizationContext filterContext, UserInfoDto user)
        {
            string          controller      = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
            string          action          = filterContext.ActionDescriptor.ActionName;
            SysUserServices sysUserServices = new SysUserServices();
            var             sysAccesses     = sysUserServices.GetRoleOfUser(null);

            foreach (var item in sysAccesses)
            {
                var result = item.URL.Equals(string.Format("{0}/{1}", controller, action));
                if (result)
                {
                    return(result);
                }
            }
            return(false);
        }
Example #7
0
        public ActionResult QueryData()
        {
            int     page    = Request.Form["page"] != "" ? Convert.ToInt32(Request.Form["page"]) : 0;
            int     size    = Request.Form["rows"] != "" ? Convert.ToInt32(Request.Form["rows"]) : 0;
            string  sort    = Request.Form["sort"] != "" ? Request.Form["sort"] : "";
            string  order   = Request.Form["order"] != "" ? Request.Form["order"] : "";
            string  Name    = Request.Form["Name"] != null ? Request.Form["Name"] : "";
            string  Tel     = Request.Form["Tel"] != null ? Request.Form["Tel"] : "";
            SysUser sysUser = new SysUser()
            {
                Name = Name, Tel = Tel
            };

            if (page < 1)
            {
                return(Content(""));
            }
            var lstSysUser = SysUserDao.Instance.LoadPageList(page, size, sysUser).ToList();

            JsonHelper json    = new JsonHelper();
            string     strJson = string.Empty;

            foreach (SysUser item in lstSysUser)
            {
                json.AddItem("ID", item.ID.ToString());
                json.AddItem("LoginName", item.LoginName);
                json.AddItem("Password", item.Password);
                json.AddItem("Name", item.Name);
                json.AddItem("Tel", item.Tel);
                item.RoleNames = SysUserServices.GetRoleNames(item.ID);
                json.AddItem("RoleNames", item.RoleNames);
                json.ItemOk();
            }

            json.totlalCount = SysUserDao.Instance.GetTotalCount(sysUser);
            if (json.totlalCount > 0)
            {
                strJson = json.ToEasyuiGridJsonString();
            }
            else
            {
                strJson = @"[]";
            }
            return(Content(strJson));
        }
Example #8
0
 public JsonResult Delete(string recordId)
 {
     try
     {
         bool result = SysUserServices.Delete(recordId);
         if (!result)
         {
             throw new MyException("删除失败");
         }
         return(Json(MyResult.Success()));
     }
     catch (MyException ex) {
         return(Json(MyResult.Error(ex.Message)));
     }
     catch (Exception ex)
     {
         ExceptionsServices.AddExceptions(ex, "删除用户失败");
         return(Json(MyResult.Error("删除失败")));
     }
 }
Example #9
0
 public int CheckLoginStatus()
 {
     if (Session["SmartSystem_SystemLoginUser"] == null)
     {
         var userAccountCookie = Request.Cookies["SmartSystem_Current_Login_UserAccount"];
         var passwordCookie    = Request.Cookies["SmartSystem_Current_Login_Password"];
         if (userAccountCookie == null || passwordCookie == null)
         {
             return(0);
         }
         string  account = userAccountCookie.Value;
         string  pwd     = DES.DESDeCode(passwordCookie.Value, "Password");
         SysUser sysUser = SysUserServices.QuerySysUserByUserAccount(account);
         if (sysUser == null || !sysUser.Password.Equals(MD5.Encrypt(pwd)))
         {
             return(0);
         }
     }
     return(1);
 }
Example #10
0
        public string GetUserTreeData()
        {
            StringBuilder sb = new StringBuilder();

            try
            {
                string queryUserAccount = Request.Params["queryUserAccount"];

                int page       = string.IsNullOrEmpty(Request.Params["page"]) ? 0 : int.Parse(Request.Params["page"]);
                int rows       = string.IsNullOrEmpty(Request.Params["rows"]) ? 0 : int.Parse(Request.Params["rows"]);
                int totalCount = 0;

                List <SysUser> users   = SysUserServices.QuerySysUserPage(GetCurrentUserCompanyId, queryUserAccount, rows, page, out totalCount);
                var            currObj = from p in users
                                         select new
                {
                    ID               = p.ID,
                    RecordID         = p.RecordID,
                    UserAccount      = p.UserAccount,
                    UserName         = p.UserName,
                    IsDefaultUser    = (int)p.IsDefaultUser,
                    RoleDescription  = GetUserRoleDescription(p),
                    ScopeDescription = GetScopeDescription(p)
                };

                sb.Append("{");
                sb.Append("\"total\":" + totalCount + ",");
                sb.Append("\"rows\":" + JsonHelper.GetJsonString(currObj) + ",");
                sb.Append("\"index\":" + page);
                sb.Append("}");
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "获取用户信息失败[用户管理]");
            }

            return(sb.ToString());
        }
Example #11
0
        public JsonResult UpdateCurrLoginPwd(string oldPwd, string newPwd1, string newPwd2)
        {
            try
            {
                if (newPwd1 != newPwd2)
                {
                    throw new MyException("两次输入密码不匹配");
                }

                SysUser user = SysUserServices.QuerySysUserByUserAccount(GetLoginUser.UserAccount);
                if (user == null)
                {
                    throw new MyException("用户不存在");
                }

                if (!user.Password.Equals(MD5.Encrypt(oldPwd)))
                {
                    throw new MyException("原始密码不正确");
                }
                bool result = SysUserServices.ResetPassword(user.UserAccount, MD5.Encrypt(newPwd1));
                if (!result)
                {
                    throw new MyException("修改密码失败");
                }

                return(Json(MyResult.Success()));
            }
            catch (MyException ex)
            {
                return(Json(MyResult.Error(ex.Message)));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "修改登录密码失败");
                return(Json(MyResult.Error("修改密码失败")));
            }
        }
Example #12
0
        public JsonResult SaveUser()
        {
            try
            {
                string userId = !string.IsNullOrWhiteSpace(Request.Params["RecordID"])?Request.Params["RecordID"].ToString():GuidGenerator.GetGuidString();

                SysUser smusers = GetSmUsers(userId);
                List <SysUserRolesMapping> rolesMappings = GetSysUserRolesMappings(userId);
                List <SysUserScopeMapping> scopeMappings = GetSysUserScopeMappings(userId);
                bool result = false;
                if (string.IsNullOrWhiteSpace(Request.Params["RecordID"]))
                {
                    result = SysUserServices.Add(smusers, rolesMappings, scopeMappings);
                }
                else
                {
                    result = SysUserServices.Update(smusers, rolesMappings, scopeMappings);
                }
                if (!result)
                {
                    throw new MyException("保存失败");
                }

                CacheData.UpdateCacheUserLoginData(GetLoginUser.RecordID);
                return(Json(MyResult.Success()));
            }
            catch (MyException ex)
            {
                return(Json(MyResult.Error(ex.Message)));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "保存用户失败");
                return(Json(MyResult.Error("保存失败")));
            }
        }
Example #13
0
        public string GetScopeTreeData()
        {
            StringBuilder strTree = new StringBuilder();

            try
            {
                List <SysUserScopeMapping> scpoes = new List <SysUserScopeMapping>();
                if (!string.IsNullOrWhiteSpace(Request.Params["userId"]))
                {
                    scpoes = SysUserServices.QuerySysUserScopeMappingByUserId(Request.Params["userId"]);
                }

                strTree.Append("[{\"id\":\"0\",");
                strTree.Append("\"attributes\":{\"type\":0},");
                strTree.Append("\"text\":\"用户作用域\"");
                GetScopeChildTreeData(scpoes, strTree);
                strTree.Append("}]");
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "获取用户作用域失败[用户管理]");
            }
            return(strTree.ToString());
        }
Example #14
0
 private void LoginSuccess(UserLoginModel model, SysUser user)
 {
     SetLoginCookie(model);
     SaveLoginLog(user);
     SysUserServices.LoginSuccess(user.RecordID);
 }
Example #15
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            try
            {
                SysUser user = null;
                if (filterContext.HttpContext.Session["SmartSystem_SystemLoginUser"] == null)
                {
                    var userAccountCookie = filterContext.HttpContext.Request.Cookies["SmartSystem_Current_Login_UserAccount"];
                    var passwordCookie    = filterContext.HttpContext.Request.Cookies["SmartSystem_Current_Login_Password"];
                    if (userAccountCookie != null && passwordCookie != null)
                    {
                        string  account = userAccountCookie.Value;
                        string  pwd     = DES.DESDeCode(passwordCookie.Value, "Password");
                        SysUser sysUser = SysUserServices.QuerySysUserByUserAccount(account);
                        if (sysUser != null && sysUser.Password.Equals(MD5.Encrypt(pwd)))
                        {
                            user = sysUser;
                            filterContext.HttpContext.Session["SmartSystem_SystemLoginUser"] = user;
                        }
                    }

                    if (user == null)
                    {
                        string response_js = "<script>window.parent.location.href='/RedirectPage/LoginTimeOut';</script>";
                        filterContext.HttpContext.Response.Write(response_js);
                        return;
                    }
                }
                user = (SysUser)filterContext.HttpContext.Session["SmartSystem_SystemLoginUser"];

                if (user != null && (filterContext.HttpContext.Session["SmartSystem_LoginUser_ValidVillage"] == null ||
                                     filterContext.HttpContext.Session["SmartSystem_LoginUser_ValidCompany"] == null ||
                                     filterContext.HttpContext.Session["SmartSystem_SystemLoginUser_Role"] == null ||
                                     filterContext.HttpContext.Session["SmartSystem_LoginUser_SysRoleAuthorize"] == null))
                {
                    CacheData.CacheUserLoginData(user);
                }
                HttpContext.Current.Session["SmartSystem_LogFrom"] = LogFrom.OmnipotentCard;
                if (user != null)
                {
                    filterContext.HttpContext.Session["SmartSystem_OperatorUserAccount"] = user.UserAccount;
                }
                if (filterContext.HttpContext.Session["SmartSystem_LoginUser_SysRoleAuthorize"] == null)
                {
                    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { area = "", controller = "RedirectPage", action = "NotPurview" }));
                    return;
                }
                List <SysRoleAuthorize> roleAuthorizes = (List <SysRoleAuthorize>)filterContext.HttpContext.Session["SmartSystem_LoginUser_SysRoleAuthorize"];
                if (!string.IsNullOrWhiteSpace(Roles))
                {
                    List <string> strRoles = Roles.Split(',').ToList();
                    if (!roleAuthorizes.Exists(p => strRoles.Contains(p.ModuleID)))
                    {
                        filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { area = "", controller = "RedirectPage", action = "NotPurview" }));
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "验证访问权限异常");
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { area = "", controller = "RedirectPage", action = "Error" }));
                return;
            }
        }
Example #16
0
        public static void UpdateCacheUserLoginData(string userId)
        {
            SysUser user = SysUserServices.QuerySysUserByRecordId(userId);

            CacheUserLoginData(user);
        }