Пример #1
0
        /// <summary>
        /// 添加系统用户执行方法
        /// </summary>
        /// <param name="request">
        /// 数据源请求信息对象
        /// </param>
        /// <param name="user">
        /// 系统用户模型对象
        /// </param>
        /// <returns>
        /// 执行方法结果
        /// </returns>
        /// <exception cref="Exception">
        /// 执行方法异常
        /// </exception>
        public ActionResult AddUser([DataSourceRequest] DataSourceRequest request, UserModel user)
        {
            try
            {
                if (user != null)
                {
                    this.systemUserService = new SystemUserService();

                    user.Status = 1;
                    user.CreateTime = DateTime.Now;

                    var sysUser = DataTransfer.Transfer<System_User>(user, typeof(UserModel));
                    sysUser.LoginPassword = Encrypt.HashBySHA1(sysUser.LoginName + sysUser.LoginPassword);
                    sysUser.ID = this.systemUserService.AddUser(sysUser);

                    if (sysUser.ID > 0)
                    {
                        return this.Json(new[] { sysUser }.ToDataSourceResult(request, this.ModelState));
                    }
                }
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message, exception);
            }

            return this.View();
        }
Пример #2
0
        public ActionResult Index(string loginName, string loginPassword, string securityCode, string remember)
        {
            this.systemMenus = new SystemMenuService().QueryAll();
            try
            {
                var user = this.GetUserByLogin(loginName);
                if (user == null)
                {
                    return this.Content("2");
                }

                if (user.LoginPassword != Encrypt.HashBySHA1(loginName + loginPassword))
                {
                    if (user.LoginPassword == Encrypt.HashBySHA1(loginPassword))
                    {
                        var recevieid = new SystemUserService().UpdatePassWord(user.ID, Encrypt.HashBySHA1(loginName + loginPassword));
                        if (recevieid > 0)
                        {
                            Response.Write("<script type='text/javascript'>alert('用户密码升级完毕,请重新登录');</script>");
                            return this.Content("1");
                        }
                    }
                    else
                    {
                        return this.Content("2");
                    }
                }

                if (this.TempData[this.Session.SessionID] == null || this.TempData[this.Session.SessionID].ToString() != securityCode)
                {
                    return this.Content("1");
                }

                this.TempData[this.Session.SessionID] = null; // 重置验证码为空

                if (!string.IsNullOrEmpty(remember) && remember == "checked")
                {
                    var httpCookie = new HttpCookie("LoginName")
                                         {
                                             Value = loginName,
                                             Expires = DateTime.Now.AddDays(30)
                                         };

                    HttpContext.Response.Cookies.Add(httpCookie);
                }
                else
                {
                    if (HttpContext.Response.Cookies["LoginName"] != null)
                    {
                        HttpContext.Response.Cookies["LoginName"].Expires = DateTime.Now.AddDays(-30);
                    }
                }

                this.SetupSession(user);

                return this.Content("success");
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message, exception);
            }
        }
Пример #3
0
        /// <summary>
        /// 根据输入的登录信息获取用户对象
        /// </summary>
        /// <param name="loginName">
        /// 登录名
        /// </param>
        /// <returns>
        /// 系统用户对象
        /// </returns>
        private System_User GetUserByLogin(string loginName)
        {
            //日志
            LogUtils.Log("用户“" + loginName + "”登录", "GetUserByLogin", Category.Info, Session.SessionID);

            this.systemUserService = new SystemUserService();
            return this.systemUserService.QueryByLoginName(loginName);
        }
Пример #4
0
        public ActionResult RemoveUser(int id)
        {
            try
            {
                this.systemUserService = new SystemUserService();

                this.systemUserService.RemoveUserByID(id);

                return this.RedirectToAction("Index");
            }
            catch
            {
                return this.View();
            }
        }
Пример #5
0
        /// <summary>
        /// 查询系统用户列表执行方法
        /// </summary>
        /// <param name="request">
        /// 数据源请求信息对象
        /// </param>
        /// <returns>
        /// 执行方法结果
        /// </returns>
        public ActionResult QueryUser([DataSourceRequest] DataSourceRequest request)
        {
            this.systemUserService = new SystemUserService();

            int pageCount;
            int totalCount;

            if (request.Page <= 0)
            {
                request.Page = 1;
            }

            var paging = new Paging("[System_User]", null, "ID", null, request.Page, request.PageSize);

            var list = this.systemUserService.Query(paging, out pageCount, out totalCount);
            if (list == null)
            {
                return this.View();
            }

            var modelList = new List<UserModel>();
            foreach (var systemRole in list)
            {
                modelList.Add(DataTransfer.Transfer<UserModel>(systemRole, typeof(System_User)));
            }

            var result = new DataSourceResult { Data = modelList, Total = totalCount };
            return this.Json(result, JsonRequestBehavior.AllowGet);
        }
Пример #6
0
        public ActionResult ModifyUser([DataSourceRequest] DataSourceRequest request, UserModel user)
        {
            if (user != null && this.ModelState.IsValid)
            {
                this.systemUserService = new SystemUserService();

                var systemUser = DataTransfer.Transfer<System_User>(
                    user,
                    typeof(UserModel));

                this.systemUserService.ModifyUser(systemUser);

                //判断用户密码是否被修改过
                var userModel = this.systemUserService.QueryByLoginName(systemUser.LoginName);
                if (userModel != null && userModel.LoginPassword != systemUser.LoginPassword)
                {
                    var loginPassword = Encrypt.HashBySHA1(systemUser.LoginName + systemUser.LoginPassword);
                    LogUtils.Log("用户“" + systemUser.LoginName + "”修改密码", "ModifyUser", Category.Info, Session.SessionID);
                    this.systemUserService.UpdatePassWord(systemUser.ID, loginPassword);
                }
            }

            return this.Json(new[] { user }.ToDataSourceResult(request, this.ModelState));
        }