Exemplo n.º 1
0
 public IHttpActionResult ResetPassword(int id)
 {
     try
     {
         var user = UserInfo.GetOne(id);
         if (user == null)
         {
             return(Failure("未找到该用户"));
         }
         user.Password = AESAlgorithm.Encrypto("123456");
         UserInfo.Update(user);
         SystemLog.Add(new SystemLog
         {
             Action       = "Logout",
             LogContent   = user.Name + "-重置密码",
             CreateTime   = DateTime.Now,
             UserID       = user.ID,
             RoleID       = user.RoleID,
             DepartmentID = user.DepartmentID,
             ClientIP     = GetIP(),
             UserName     = user.Name,
             RealName     = user.RealName
         });
         return(Success());
     }
     catch (Exception ex)
     {
         logger.Error(ex);
         return(Failure("执行异常"));
     }
 }
Exemplo n.º 2
0
        public IHttpActionResult AddCabinet(Cabinet cabinet)
        {
            try
            {
                string valiate = ValiateCabinetModel(cabinet);
                if (!string.IsNullOrEmpty(valiate))
                {
                    return(Failure(valiate));
                }
                if (Cabinet.GetByName(cabinet.Name) != null)
                {
                    return(Failure("该名称已经被使用"));
                }
                if (Cabinet.GetByMac(cabinet.AndroidMac) != null)
                {
                    return(Failure("该硬件编码已经被使用"));
                }

                if (!UserController.LoginDictionary.ContainsKey(GetCookie("token")))
                {
                    return(Logout());
                }
                UserInfo userCookie = UserController.LoginDictionary[GetCookie("token")];
                if (userCookie == null)
                {
                    return(Logout());
                }
                SystemLog.Add(new SystemLog
                {
                    Action       = "AddCabinet",
                    LogContent   = userCookie.Name + "-新增保险柜-" + cabinet.Name,
                    CreateTime   = DateTime.Now,
                    UserID       = userCookie.ID,
                    RoleID       = userCookie.RoleID,
                    DepartmentID = userCookie.DepartmentID,
                    ClientIP     = GetIP(),
                    UserName     = userCookie.Name,
                    RealName     = userCookie.RealName
                });
                cabinet.CreateTime = DateTime.Now;
                cabinet.IsOnline   = false;
                if (!string.IsNullOrEmpty(cabinet.FirstContactPassword))
                {
                    cabinet.FirstContactPassword = AESAlgorithm.Encrypto(cabinet.FirstContactPassword);
                }
                if (!string.IsNullOrEmpty(cabinet.SecondContactPassword))
                {
                    cabinet.SecondContactPassword = AESAlgorithm.Encrypto(cabinet.SecondContactPassword);
                }
                Cabinet.Add(cabinet);
                return(Success(true));
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                return(Failure("新增失败"));
            }
        }
Exemplo n.º 3
0
 public IHttpActionResult ChangePassword(string password)
 {
     if (string.IsNullOrEmpty(password))
     {
         return(Failure("密码不为空"));
     }
     if (password?.Length <= 8)
     {
         return(Failure("密码必须是大于8位"));
     }
     if (!Regex.IsMatch(password[0].ToString(), @"^[A-Za-z]"))
     {
         return(Failure("密码必须字母开头"));
     }
     try
     {
         if (!UserController.LoginDictionary.ContainsKey(GetCookie("token")))
         {
             return(Logout());
         }
         UserInfo user = UserController.LoginDictionary[GetCookie("token")];
         if (user == null)
         {
             return(Logout());
         }
         var us = UserInfo.GetOne(user.ID);
         us.Password = AESAlgorithm.Encrypto(password);
         UserInfo.Update(us);
         SystemLog.Add(new SystemLog
         {
             Action       = "Logout",
             LogContent   = user.Name + "-更新密码",
             CreateTime   = DateTime.Now,
             UserID       = user.ID,
             RoleID       = user.RoleID,
             DepartmentID = user.DepartmentID,
             ClientIP     = GetIP(),
             UserName     = user.Name,
             RealName     = user.RealName
         });
         return(Success());
     }catch (Exception ex)
     {
         logger.Error(ex);
         return(Failure("修改失败"));
     }
 }
Exemplo n.º 4
0
        public IHttpActionResult EditCabinet(Cabinet cabinet)
        {
            try
            {
                string valiate = ValiateCabinetModel(cabinet);
                if (!string.IsNullOrEmpty(valiate))
                {
                    return(Failure(valiate));
                }
                if (!UserController.LoginDictionary.ContainsKey(GetCookie("token")))
                {
                    return(Logout());
                }
                UserInfo userCookie = UserController.LoginDictionary[GetCookie("token")];
                if (userCookie == null)
                {
                    return(Logout());
                }
                if (cabinet.ID == 0)
                {
                    return(Failure("未指定保险柜"));
                }
                var cab = Cabinet.GetOne(cabinet.ID);
                if (cab == null)
                {
                    return(Failure("未找到指定保险柜"));
                }
                var old = Cabinet.GetByName(cabinet.Name);
                if (old != null && old.ID != cabinet.ID)
                {
                    return(Failure("该名称已经被使用"));
                }

                old = Cabinet.GetByMac(cabinet.AndroidMac);
                if (old != null && old.ID != cabinet.ID)
                {
                    return(Failure("该硬件编码已经被使用"));
                }


                SystemLog.Add(new SystemLog
                {
                    Action       = "EditCabinet",
                    LogContent   = userCookie.Name + "-编辑保险柜-" + cabinet.ID,
                    CreateTime   = DateTime.Now,
                    UserID       = userCookie.ID,
                    RoleID       = userCookie.RoleID,
                    DepartmentID = userCookie.DepartmentID,
                    ClientIP     = GetIP(),
                    UserName     = userCookie.Name,
                    RealName     = userCookie.RealName
                });
                cab.Address              = cabinet.Address;
                cab.AndroidMac           = cabinet.AndroidMac;
                cab.Code                 = cabinet.Code;
                cab.DepartmentID         = cabinet.DepartmentID;
                cab.FirstContact         = cabinet.FirstContact;
                cab.FirstContactPassword = AESAlgorithm.Encrypto(cabinet.FirstContactPassword);
                cab.FirstContactPhone    = cabinet.FirstContactPhone;

                cab.IP            = cabinet.IP;
                cab.Name          = cabinet.Name;
                cab.NeedConfirm   = cabinet.NeedConfirm;
                cab.Remark        = cabinet.Remark;
                cab.SecondContact = cabinet.SecondContact;

                cab.SecondContactPassword = AESAlgorithm.Encrypto(cabinet.SecondContactPassword);
                cab.SecondContactPhone    = cabinet.SecondContactPhone;

                Cabinet.Update(cab);
                return(Success(true));
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                return(Failure("修改失败"));
            }
        }
Exemplo n.º 5
0
        public IHttpActionResult Login(LoginModel model)
        {
            if (model == null)
            {
                return(Failure("用户名不存在"));
            }
            if (string.IsNullOrEmpty(model.UserName) || string.IsNullOrEmpty(model.Password))
            {
                return(Failure("用户名或密码不得为空"));
            }

            //var serial = ConfigurationManager.AppSettings["SerialNumber"];
            //if (string.IsNullOrEmpty(serial))
            //{
            //    return Failure("请联系销售获取产品序列号");
            //}
            //DateTime dt = DateTime.Now;
            //if (!DateTime.TryParse(AESAlgorithm.Decrypto(serial),out dt)||dt < DateTime.Now)
            //{
            //    return Failure("序列号已经过期,请联系销售获取最新序列号");
            //}
            try
            {
                lock (ContinueErrorPassword)
                {
                    //校验5次密码错误
                    ContinueErrorPassword.RemoveAll(m => m.CreateTime.Day != DateTime.Now.Day);
                    if (ContinueErrorPassword.Count(m => m.UserName == model.UserName) > 5)
                    {
                        UserInfo u = UserInfo.GetOne(model.UserName);
                        if (u != null)
                        {
                            u.Status = 0;
                            UserInfo.Update(u);
                        }
                        return(Failure("连续输错5次密码并冻结"));
                    }
                }
                UserInfo user = UserInfo.GetOne(model.UserName);
                if (user == null)
                {
                    return(Failure("用户名不存在"));
                }
                if (user.Status == 0)
                {
                    return(Failure("此用户已禁用,请联系管理员"));
                }

                if (user.Password != AESAlgorithm.Encrypto(model.Password))
                {
                    model.CreateTime = DateTime.Now;
                    lock (ContinueErrorPassword)
                    {
                        ContinueErrorPassword.Add(model);
                    }
                    return(Failure("密码错误"));
                }
                var token = user.ID.ToString();



                SystemLog.Add(new SystemLog
                {
                    Action       = "Login",
                    LogContent   = user.Name + "-登录成功",
                    CreateTime   = DateTime.Now,
                    UserID       = user.ID,
                    RoleID       = user.RoleID,
                    DepartmentID = user.DepartmentID,
                    ClientIP     = GetIP(),
                    UserName     = user.Name,
                    RealName     = user.RealName
                });
                Department depart = Department.GetOne(user.DepartmentID);
                if (user.LastPasswordTime == null)
                {
                    user.LastPasswordTime = DateTime.Now;
                }
                var data = new
                {
                    UserID             = user.ID,
                    RoleName           = user.RoleID == 1 ? "admin" : "user",//1是超管,2是用户
                    RealName           = user.RealName,
                    DepartmentName     = depart?.Name,
                    NeedChangePassword = (user.LastPasswordTime.Value.AddDays(7) < DateTime.Now ? true : false), //是否需要提示修改密码
                    RoleModel          = Role_Module.Get(user.RoleID),                                           //返回所有模块
                };

                WriteCookie("token", token);
                user.LastLoginTime = DateTime.Now;
                if (!LoginDictionary.ContainsKey(token))
                {
                    LoginDictionary.Add(token, user);
                }

                _logger.Info(string.Join(",", LoginDictionary.Keys.ToList()));
                return(Success(data));//返回用户权限
            }catch (Exception e)
            {
                _logger.Error(e);
                return(Failure(e.Message));
            }
        }
Exemplo n.º 6
0
        public IHttpActionResult EditUser(UserInfo user)
        {
            try
            {
                string valiate = ValiateUserModel(user);
                if (!string.IsNullOrEmpty(valiate))
                {
                    return(Failure(valiate));
                }
                if (user.ID == 0)
                {
                    return(Failure("未指定用户"));
                }
                var us = UserInfo.GetOne(user.ID);
                if (us == null)
                {
                    return(Failure("未找到指定用户"));
                }

                var old = UserInfo.GetOne(user.Name);
                if (old != null && old.ID != user.ID)
                {
                    return(Failure("该用户名已经被使用"));
                }
                if (string.IsNullOrEmpty(user.Password))
                {
                    return(Failure("密码不为空"));
                }
                if (user.Password?.Length <= 8)
                {
                    return(Failure("密码必须是大于8位"));
                }
                if (!Regex.IsMatch(user.Password[0].ToString(), @"^[A-Za-z]"))
                {
                    return(Failure("密码必须字母开头"));
                }

                if (!UserController.LoginDictionary.ContainsKey(GetCookie("token")))
                {
                    return(Logout());
                }
                UserInfo userCookie = UserController.LoginDictionary[GetCookie("token")];
                if (userCookie == null)
                {
                    return(Logout());
                }
                SystemLog.Add(new SystemLog
                {
                    Action       = "EditUser",
                    LogContent   = userCookie.Name + "-编辑用户-" + user.Name,
                    CreateTime   = DateTime.Now,
                    UserID       = userCookie.ID,
                    RoleID       = userCookie.RoleID,
                    DepartmentID = userCookie.DepartmentID,
                    ClientIP     = GetIP(),
                    UserName     = userCookie.Name,
                    RealName     = userCookie.RealName
                });

                us.Name = user.Name;
                if (us.Password != AESAlgorithm.Encrypto(user.Password))
                {
                    us.LastPasswordTime = DateTime.Now;
                }
                us.Password     = AESAlgorithm.Encrypto(user.Password);
                us.DepartmentID = user.DepartmentID;
                us.RealName     = user.RealName;
                us.Status       = user.Status;
                us.Phone        = user.Phone;
                us.Email        = user.Email;
                UserInfo.Update(us);
                return(Success(true));
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(Failure("修改失败"));
            }
        }
Exemplo n.º 7
0
        public IHttpActionResult AddUser(UserInfo user)
        {
            try
            {
                string valiate = ValiateUserModel(user);
                if (!string.IsNullOrEmpty(valiate))
                {
                    return(Failure(valiate));
                }
                if (UserInfo.GetOne(user.Name) != null)
                {
                    return(Failure("该用户名已经存在"));
                }
                if (string.IsNullOrEmpty(user.Password))
                {
                    return(Failure("密码不为空"));
                }
                if (user.Password?.Length <= 8)
                {
                    return(Failure("密码必须是大于8位"));
                }
                if (!Regex.IsMatch(user.Password[0].ToString(), @"^[A-Za-z]"))
                {
                    return(Failure("密码必须字母开头"));
                }

                if (!UserController.LoginDictionary.ContainsKey(GetCookie("token")))
                {
                    return(Logout());
                }
                UserInfo userCookie = UserController.LoginDictionary[GetCookie("token")];
                if (userCookie == null)
                {
                    return(Logout());
                }
                SystemLog.Add(new SystemLog
                {
                    Action       = "AddUser",
                    LogContent   = userCookie.Name + "-新增用户-" + user.Name,
                    CreateTime   = DateTime.Now,
                    UserID       = userCookie.ID,
                    RoleID       = userCookie.RoleID,
                    DepartmentID = userCookie.DepartmentID,
                    ClientIP     = GetIP(),
                    UserName     = userCookie.Name,
                    RealName     = userCookie.RealName
                });

                user.CreateTime       = DateTime.Now;
                user.RoleID           = user.RoleID;
                user.Password         = AESAlgorithm.Encrypto(user.Password);
                user.LastPasswordTime = DateTime.Now;
                UserInfo.Add(user);
                return(Success(true));
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(Failure("新增失败"));
            }
        }