Exemplo n.º 1
0
 /// <summary>
 /// 重新基类在Action执行之前的事情
 /// </summary>
 /// <param name="filterContext">重写方法的参数</param>
 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     base.OnActionExecuting(filterContext);
     //得到用户登录的信息
     CurrentUserInfo = Session["UserInfo"] as BaseUser;
     //判断用户是否为空
     if (CurrentUserInfo == null)
     {
         Response.Redirect("/Login/Index");
     }
 }
 /// <summary>
 /// 添加用户信息
 /// </summary>
 /// <param name="userInfo">实体类(用户)</param>
 /// <returns>用户是否添加成功的标志</returns>
 public ActionResult RegisterUser(BaseUser userInfo)
 {
     //首先保存一些需要录入数据库的信息
     userInfo.Code = Guid.NewGuid().ToString();  //随机产生的一些数据
     userInfo.QuickQuery = userInfo.UserName;   //获取数据的查询码
     userInfo.UserFrom = "添加";               //用户来源
     userInfo.Lang = "汉语";                   //默认系统识别的是汉语
     userInfo.IsStaff = (Int32?)StaffEnum.OK;         //默认是职员
     userInfo.IsVisible = (Int32?)VisibleEnum.OK;     //默认显示信息
     userInfo.Enabled = (Int32?)EnabledEnum.OK;       //默认用户有效
     userInfo.AuditStatus = "已审核";         //默认添加的用户已经经过审核
     userInfo.DeletionStateCode = (Int32?)DeletionStateCodeEnum.Normal;    //默认没有伪删除
     userInfo.CreateOn = DateTime.Parse(DateTime.Now.ToString());     //默认创建用户日期
     BaseUser user = Session["UserInfo"] as BaseUser;
     userInfo.CreateUserID = user.Code;   //获取添加此用户的管理者的ID
     userInfo.CreateBy = user.UserName;//获取添加此用户的管理者的名称
     //执行添加用户的代码
     _userInfoService.AddEntity(userInfo);
     return Content("OK");
 }
        /// <summary>
        /// 根据用户ID信息修改用户的信息
        /// </summary>
        /// <param name="userInfo">用户的实体类</param>
        /// <returns>返回是否修改成功的标志</returns>
        public ActionResult UpdateUserInfo(BaseUser userInfo)
        {
            //首先根据传递过来的参数查询出要修改的信息
            var editUserInfo = _userInfoService.LoadEntities(c => c.ID == userInfo.ID).FirstOrDefault();
            if (editUserInfo == null)
            {
                return Content("错误信息,请您检查");
            }
            //对用户的信息进行修改
            editUserInfo.UserName = userInfo.UserName;
            editUserInfo.RealName = userInfo.RealName;
            editUserInfo.QuickQuery = userInfo.UserName;
            editUserInfo.Email = userInfo.Email;
            editUserInfo.SecurityLevel = userInfo.SecurityLevel;
            editUserInfo.Gender = userInfo.Gender;
            editUserInfo.Birthday = userInfo.Birthday;
            editUserInfo.Mobile = userInfo.Mobile;
            editUserInfo.Telephone = userInfo.Telephone;
            editUserInfo.QICQ = userInfo.QICQ;
            editUserInfo.SortCode = userInfo.SortCode;
            editUserInfo.IsStaff = userInfo.IsStaff;
            editUserInfo.IsVisible = userInfo.IsVisible;
            editUserInfo.Enabled = userInfo.Enabled;
            editUserInfo.AuditStatus = userInfo.AuditStatus;
            editUserInfo.Description = userInfo.Description;
            editUserInfo.ModifirdOn = DateTime.Parse(DateTime.Now.ToString());
            BaseUser user = Session["UserInfo"] as BaseUser;
            editUserInfo.ModifiedUserID = user.Code;  //获取修改信息的ID
            editUserInfo.ModifiedBy = user.UserName;//获取修改此用户的用户名

            if (_userInfoService.UpdateEntity() > 0)
            {
                return Content("OK");
            }
            return Content("Error");
        }
 /// <summary>
 /// 直接删除用户的信息
 /// </summary>
 /// <param name="userInfo">实体类</param>
 /// <param name="ID">主键ID</param>
 /// <param name="UserName">用户名</param>
 /// <param name="Not">标志是否伪删除还有还原</param>
 /// <returns>返回执行成功的标志</returns>
 public ActionResult DeleteUsers(BaseUser userInfo, string ID, string UserName, string Not)
 {
     //首先判断是那个用户登录进入的,如果此用户正在使用这个系统,则不允许用户删除
     userInfo = Session["UserInfo"] as BaseUser;
     var userName = userInfo.UserName; //登录用户的信息
     var uIDsName = UserName.Split(',');  //将传递过来的用户名分割成一个一个的显示
     List<string> listUserInfo = new List<string>();
     foreach (var Name in uIDsName)
     {
         listUserInfo.Add(Name);
     }
     if (listUserInfo.Contains(userName))
     {
         return Content("含有正在使用的用户,禁止删除");
     }
     //下面我们开始删除用户的信息
     //首先判断确认是否从前台传递过来了信息
     if (string.IsNullOrEmpty(ID))
     {
         return Content("请选择需要删除的数据");
     }
     var idStrs = ID.Split(',');  //截取传递过来的字符串
     List<int> deleteIDList = new List<int>();
     foreach (var idStr in idStrs)
     {
         deleteIDList.Add(int.Parse(idStr));
     }
     if (Not == "not")
     {
         //伪删除,也就是根据用户的ID修改信息,首先查询出实体信息
         foreach (var deleteId in deleteIDList)
         {
             var EditUserDeleteIsNot = _userInfoService.LoadEntities(c => c.ID == deleteId).FirstOrDefault();
             EditUserDeleteIsNot.DeletionStateCode = 1;
             _userInfoService.UpdateEntity(userInfo);
         }
         return Content("OK");
     }
     else if (Not == "back")
     {
         foreach (var deleteID in deleteIDList)
         {
             var BackUserDelete = _userInfoService.LoadEntities(c => c.ID == deleteID).FirstOrDefault();
             BackUserDelete.DeletionStateCode = 0;
             _userInfoService.UpdateEntity(userInfo);
         }
         return Content("OK");
     }
     else
     {
         //最后执行批量删除数据的方法
         if (_userInfoService.DeleteUsers(deleteIDList) > 0)
         {
             return Content("OK");
         }
     }
     return Content("删除失败,请您检查");
 }
Exemplo n.º 5
0
        /// <summary>
        /// 判断用户输入的信息是否正确,[HttpPost]
        /// </summary>
        /// <param name="UserName">用户名</param>
        /// <param name="userInfo">用户的实体类</param>
        /// <param name="Code">验证码</param>
        /// <returns>返回是否执行成功的标志</returns>
        public ActionResult CheckUserInfo(string UserName, BaseUser userInfo, string Code)
        {
            //如果用户信息存在的话讲用户信息保存到session中
            if (UserName != null)
            {
                //首先根据用户名的信息获取到用户详细的信息
                BaseUser userInfoShow = _userInfoService.LoadEntities(c => c.UserName == UserName).FirstOrDefault();
                Session["UserInfo"] = userInfoShow;
            }

            //首先我们拿到系统的验证码
            string sessionCode = this.TempData["ValidateCode"] == null
                                     ? new Guid().ToString()
                                     : this.TempData["ValidateCode"].ToString();
            //然后我们就将验证码去掉,避免了暴力破解
            this.TempData["ValidateCode"] = new Guid();
            //判断用户输入的验证码是否正确
            if (sessionCode != Code)
            {
                return Content("验证码输入不正确");
            }

            //调用业务逻辑层(BLL)去校验用户是否正确,,,定义变量存取获取到的用户的错误信息
            string UserInfoError = "";
            var loginUserInfo = _userInfoService.CheckUserInfo(userInfo);
            switch (loginUserInfo)
            {
                case LoginResult.PwdError:
                    UserInfoError = "密码输入错误";
                    break;
                case LoginResult.UserNotExist:
                    UserInfoError = "用户名输入错误或者您已经被禁用";
                    break;
                case LoginResult.UserIsNull:
                    UserInfoError = "用户名不能为空";
                    break;
                case LoginResult.PwdIsNUll:
                    UserInfoError = "密码不能为空";
                    break;
                case LoginResult.OK:
                    UserInfoError = "OK";
                    break;
                default:
                    UserInfoError = "未知错误,请您检查您的数据库";
                    break;
            }

            #region ----使用if else来判断信息----
            //if (loginUserInfo == LoginResult.UserIsNull)
            //{
            //    UserInfoError = "用户名不能为空";
            //}
            //else if (loginUserInfo == LoginResult.PwdIsNUll)
            //{
            //    UserInfoError = "密码不能为空";
            //}
            //else if (loginUserInfo == LoginResult.UserNotExist)
            //{
            //    UserInfoError = "用户名输入错误";
            //}
            //else if (loginUserInfo == LoginResult.PwdError)
            //{
            //    UserInfoError = "密码输入错误";
            //}
            //else if (loginUserInfo == LoginResult.OK)
            //{
            //    UserInfoError = "OK";
            //}
            //else
            //{
            //    UserInfoError = "未知错误,请您检查您的数据库";
            //} 
            #endregion

            return Content(UserInfoError);
        }