示例#1
0
 /// <summary>
 /// 用户集合操作完成后事件
 /// </summary>
 /// <param name="operateType">操作类型</param>
 /// <param name="ts">用户对象集合</param>
 /// <param name="result">操作结果</param>
 /// <param name="currUser">当前用户</param>
 /// <param name="otherParams">其他参数</param>
 public void OperateCompeletedHandles(ModelRecordOperateType operateType, List <Sys_User> ts, bool result, UserInfo currUser, object[] otherParams = null)
 {
     if (operateType == ModelRecordOperateType.Add && result)
     {
         //新增用户后初始化用户密码为 username+'_'+123456
         string errMsg = string.Empty;
         foreach (Sys_User t in ts)
         {
             if (string.IsNullOrEmpty(t.PasswordHash))
             {
                 string pwd = string.Format("{0}_123456", t.UserName);
                 bool   rs  = UserOperate.ModifyPassword(t.Id, pwd, out errMsg);
                 if (rs)
                 {
                     new UserOperateHandleFactory().AfterRegiterUser(t.UserName, pwd);
                 }
             }
         }
     }
     if (operateType == ModelRecordOperateType.Del && result)
     {
         foreach (Sys_User t in ts)
         {
             new UserOperateHandleFactory().AfterDeleteUser(t.UserName);
         }
     }
 }
示例#2
0
        /// <summary>
        /// 删除客户管理员
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public bool DeleteCustomerAdmin(UserOperate dto)
        {
            bool blResult = false;

            using (var tcdmse = new Entities.TCDMS_MasterDataEntities())
            {
                var pp = tcdmse.master_UserInfo.Where(p => p.UserID == dto.UserID).FirstOrDefault();
                if (pp == null)
                {
                    throw new Exception("此条信息不存在!");
                }
                pp.ModifyUser = dto.ModifyUser;
                pp.ModifyTime = dto.ModifyTime;
                var aui = pp.master_AreaInfo.Where(g => g.AreaID == dto.AreaID).ToList();
                if (aui.Count() > 0)
                {
                    aui.ForEach(g =>
                    {
                        pp.master_AreaInfo.Remove(g);
                    });
                }

                blResult = tcdmse.SaveChanges() > 0;
            }

            return(blResult);
        }
示例#3
0
        public HttpResponseMessage DeleteUser(string UserOperate)
        {
            ResultDTO <UserResultDTO> resultdto = new ResultDTO <UserResultDTO>();

            try
            {
                UserOperate dto = TransformHelper.ConvertBase64JsonStringToDTO <UserOperate>(UserOperate);
                resultdto.SubmitResult = _lUserAuthorityServices.DeleteUser(dto);
            }
            catch (DbUpdateException)
            {
                resultdto.SubmitResult = false;
                resultdto.Message      = "此条信息已使用不可删除!";
            }
            catch (Exception ex)
            {
                resultdto.SubmitResult = false;
                resultdto.Message      = ex.Message;
            }

            HttpResponseMessage result = new HttpResponseMessage
            {
                Content = new StringContent(JsonConvert.SerializeObject(resultdto),
                                            System.Text.Encoding.GetEncoding("UTF-8"),
                                            "application/json")
            };

            return(result);
        }
示例#4
0
 /// <summary>
 /// 员工操作完成
 /// </summary>
 /// <param name="operateType">操作类型</param>
 /// <param name="t">员工对象</param>
 /// <param name="result">操作结果</param>
 /// <param name="currUser">当前用户</param>
 /// <param name="otherParams"></param>
 public void OperateCompeletedHandle(ModelRecordOperateType operateType, OrgM_Emp t, bool result, UserInfo currUser, object[] otherParams = null)
 {
     if (result)
     {
         string errMsg   = string.Empty;
         string username = OrgMOperate.GetUserNameByEmp(t);
         if (operateType == ModelRecordOperateType.Add)
         {
             if (!string.IsNullOrEmpty(username))
             {
                 UserOperate.AddUser(out errMsg, username, string.Format("{0}_123456", username), null, t.Name);
             }
         }
         else if (operateType == ModelRecordOperateType.Edit)
         {
             if (!string.IsNullOrEmpty(username))
             {
                 UserOperate.UpdateUserAliasName(username, t.Name);
             }
         }
         else if (operateType == ModelRecordOperateType.Del)
         {
             if (!string.IsNullOrEmpty(username))
             {
                 UserOperate.DelUser(username); //删除账号
             }
         }
     }
 }
示例#5
0
        /// <summary>
        /// 用户信息删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public bool DeleteUser(UserOperate dto)
        {
            bool blResult = false;

            using (var tcdmse = new Entities.TCDMS_MasterDataEntities())
            {
                var pp = tcdmse.master_UserInfo.Where(p => p.UserID == dto.UserID).FirstOrDefault();
                if (pp == null)
                {
                    throw new Exception("此条信息不存在!");
                }
                //用户权限
                var ww = tcdmse.master_UserCustomerAuthority.Where(w => w.UserID == pp.UserID);
                tcdmse.master_UserCustomerAuthority.RemoveRange(ww);
                //用户角色
                pp.master_RoleInfo.Clear();
                //关联经销商
                pp.master_DistributorInfo.Clear();
                //用户
                tcdmse.master_UserInfo.Remove(pp);

                // 记录日志
                this.AddLog(tcdmse, new LogData
                {
                    CurrentLogType = LogType.DELETE,
                    LogDetails     = "删除用户" + pp.FullName,
                    OpratorName    = dto.ModifyUser
                });

                blResult = tcdmse.SaveChanges() > 0;
            }

            return(blResult);
        }
示例#6
0
 /// <summary>
 /// 操作完成后
 /// </summary>
 /// <param name="operateType"></param>
 /// <param name="t"></param>
 /// <param name="result"></param>
 /// <param name="currUser"></param>
 /// <param name="otherParams"></param>
 public void OperateCompeletedHandle(ModelRecordOperateType operateType, OrgM_EmpDeptDuty t, bool result, UserInfo currUser, object[] otherParams = null)
 {
     if (result)
     {
         string errMsg = string.Empty;
         if (operateType == ModelRecordOperateType.Add || operateType == ModelRecordOperateType.Edit)
         {
             if (t.OrgM_EmpId.HasValue && t.OrgM_EmpId.Value != Guid.Empty && t.OrgM_DeptId.HasValue && t.OrgM_DeptId.Value != Guid.Empty)
             {
                 OrgM_Dept dept     = OrgMOperate.GetDeptById(t.OrgM_DeptId.Value);
                 string    username = OrgMOperate.GetUserNameByEmpId(t.OrgM_EmpId.Value);
                 if (!string.IsNullOrEmpty(username) && dept != null)
                 {
                     Sys_User         user = UserOperate.GetUser(username);
                     Sys_Organization org  = UserOperate.GetAllOrgs(x => x.Name == dept.Name && x.Flag == dept.Id.ToString()).FirstOrDefault();
                     if (user != null && org != null && user.Sys_OrganizationId != org.Id)
                     {
                         user.Sys_OrganizationId = org.Id;
                         CommonOperate.OperateRecord <Sys_User>(user, ModelRecordOperateType.Edit, out errMsg, new List <string>()
                         {
                             "Sys_OrganizationId"
                         }, false);
                     }
                 }
             }
         }
     }
 }
示例#7
0
        /// <summary>
        /// 修改模块管理员邮箱
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public static ResultData <object> UpdateModularInfo(UserOperate dto)
        {
            ResultData <object> result = null;

            result = PutAPI <ResultData <object> >(WebConfiger.MasterDataServicesUrl + "UserManager", dto);

            return(result);
        }
示例#8
0
 /// <summary>
 /// 获取用户扩展信息
 /// </summary>
 /// <param name="o"></param>
 /// <param name="e"></param>
 /// <returns></returns>
 public static UserExtendBase GetUserExtendObject(object o, EventUserArgs e)
 {
     if (e.CurrUser != null)
     {
         return(UserOperate.GetUserExtend(e.CurrUser));
     }
     return(null);
 }
        public ActionResult ResetPwd()
        {
            Guid uid = _Request.QueryEx("uid").ObjToGuid();

            if (uid == Guid.Empty || string.IsNullOrEmpty(UserOperate.GetUserNameByUserId(uid)))
            {
                return(RedirectToAction("ForgetPwd"));
            }
            return(View());
        }
        public JsonResult UserReg(string username, string userpwd, string useralias)
        {
            string userTipDes = "用户名";

            if (GlobalSet.EmpUserNameConfigRule == UserNameAndEmpConfigRule.Email)
            {
                userTipDes = "邮箱";
            }
            else if (GlobalSet.EmpUserNameConfigRule == UserNameAndEmpConfigRule.Mobile)
            {
                userTipDes = "手机号";
            }
            if (string.IsNullOrEmpty(username))
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = string.Format("{0}不能为空!", userTipDes)
                }));
            }
            if (GlobalSet.EmpUserNameConfigRule == UserNameAndEmpConfigRule.Email && !Validator.IsEmail(username))
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "请输入正确的邮箱地址!"
                }));
            }
            if (GlobalSet.EmpUserNameConfigRule == UserNameAndEmpConfigRule.Mobile && !Validator.IsMobilePhoneNumber(username))
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "请输入正确的手机号码!"
                }));
            }
            if (string.IsNullOrEmpty(userpwd))
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "密码不能为空!"
                }));
            }
            if (!string.IsNullOrEmpty(useralias) && useralias.Length > 15)
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "用户别称不能超过15位!"
                }));
            }
            string errMsg = string.Empty;
            Guid   userId = UserOperate.AddUser(out errMsg, username, userpwd, null, useralias);

            return(Json(new ReturnResult()
            {
                Success = string.IsNullOrEmpty(errMsg), Message = errMsg
            }));
        }
示例#11
0
        /// <summary>
        /// 切换用户
        /// </summary>
        /// <returns></returns>
        public ActionResult ChangeUser()
        {
            if (_Request == null)
            {
                _Request = Request;
            }
            if (_Response == null)
            {
                _Response = Response;
            }
            if (_Session == null)
            {
                _Session = Session;
            }
            SetRequest(_Request);
            UserInfo currUser = GetCurrentUser(_Request);

            if (currUser == null)
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "非法操作"
                }));
            }
            string username = _Request["username"].ObjToStr();

            if (username == "admin")
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "没有权限"
                }));
            }
            Guid     userId   = UserOperate.GetUserIdByUserName(username);
            UserInfo userInfo = UserOperate.GetUserInfo(userId);

            if (userInfo == null)
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "用户不存在"
                }));
            }
            userInfo.ClientBrowserWidth  = currUser.ClientBrowserWidth;
            userInfo.ClientBrowserHeight = currUser.ClientBrowserHeight;
            CacheUserData(userInfo); //缓存cookie
            return(Json(new ReturnResult()
            {
                Success = true, Message = string.Empty
            }));
        }
        public JsonResult ChangePwdNoLogin()
        {
            if (_Request == null)
            {
                _Request = Request;
            }
            Guid uid = _Request.QueryEx("uid").ObjToGuid();

            if (uid == Guid.Empty || string.IsNullOrEmpty(UserOperate.GetUserNameByUserId(uid)))
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "用户ID不存在!"
                }));
            }
            string pwd1 = _Request.QueryEx("pwd1").ObjToStr();
            string pwd2 = _Request.QueryEx("pwd2").ObjToStr();

            if (string.IsNullOrEmpty(pwd1.Trim()))
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "新密码不能为空!"
                }));
            }
            if (pwd1.Length < 5 || pwd1.Length > 20)
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "密码长度为5-20个字符!"
                }));
            }
            if (pwd1 != pwd2)
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "两次密码输入不一致!"
                }));
            }
            string errMsg = string.Empty;
            bool   rs     = UserOperate.ModifyPassword(uid, pwd1, out errMsg);

            return(Json(new ReturnResult()
            {
                Success = rs, Message = errMsg
            }));
        }
 /// <summary>
 /// 登录前
 /// </summary>
 /// <param name="filterContext">过滤上下文</param>
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     try
     {
         UserInfo admin    = UserOperate.GetSuperAdmin(); //获取管理员信息
         string   username = filterContext.ActionArguments["username"].ObjToStr();
         loginLog.UserId         = UserOperate.GetUserIdByUserName(username).ObjToStr();
         loginLog.LoginName      = username;
         loginLog.LoginTime      = DateTime.Now;
         loginLog.LoginIp        = WebHelper.GetClientIP(filterContext.HttpContext.Request);
         loginLog.CreateUserId   = admin.UserId; //添加人默认为空
         loginLog.CreateDate     = DateTime.Now;
         loginLog.CreateUserName = admin.AliasName;
         loginLog.ModifyUserId   = admin.UserId; //修改人默认为空
         loginLog.ModifyDate     = DateTime.Now;
         loginLog.ModifyUserName = admin.AliasName;
     }
     catch { }
 }
示例#14
0
        public HttpResponseMessage UpdateStopEnableUser(UserOperate dto)
        {
            ResultDTO <object> resultdto = new ResultDTO <object>();

            try
            {
                if (dto.Uptype == 3)//新增客户管理员
                {
                    resultdto.SubmitResult = _lUserAuthorityServices.AddCustomerAdmin(dto);
                }
                else if (dto.Uptype == 4)//删除客户管理员
                {
                    resultdto.SubmitResult = _lUserAuthorityServices.DeleteCustomerAdmin(dto);
                }
                else if (dto.Uptype == 5) //修改模块管理员邮箱
                {
                    resultdto.SubmitResult = _lUserAuthorityServices.UpdateModularAdmin(dto);
                }
                else if (dto.IsActive == null)
                {
                    resultdto.SubmitResult = _lUserAuthorityServices.UpdateUser(dto);
                }
                else
                {
                    resultdto.SubmitResult = _lUserAuthorityServices.StopEnableUser(dto);
                }
            }
            catch (Exception ex)
            {
                resultdto.SubmitResult = false;
                resultdto.Message      = ex.Message;
            }

            HttpResponseMessage result = new HttpResponseMessage
            {
                Content = new StringContent(JsonConvert.SerializeObject(resultdto),
                                            System.Text.Encoding.GetEncoding("UTF-8"),
                                            "application/json")
            };

            return(result);
        }
示例#15
0
        /// <summary>
        /// 应用程序认证请求
        /// </summary>
        /// <param name="sender">发送对象</param>
        /// <param name="e">事件参数</param>
        public void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            HttpApplication app      = (HttpApplication)sender;
            string          username = string.Empty;

            if (app.Context.User != null && app.Context.User.Identity != null)
            {
                username = app.Context.User.Identity.Name;
            }
            int w = 0;
            int h = 0;

            if (app.Context.Request["nfm"].ObjToInt() == 1)
            {
                username = app.Context.Request["un"].ObjToStr(); //请求中自带的用户名
                w        = app.Context.Request["w"].ObjToInt();
                h        = app.Context.Request["h"].ObjToInt();
            }
            if (!string.IsNullOrEmpty(username))
            {
                UserInfo tempUserInfo = UserInfo.GetCurretnUser(app.Context);
                if (tempUserInfo == null || tempUserInfo.UserId == Guid.Empty || tempUserInfo.UserName.ToLower() != username.ToLower())
                {
                    Guid     userId   = UserOperate.GetUserIdByUserName(username);
                    UserInfo userInfo = UserOperate.GetUserInfo(userId);
                    if (w > 0 && h > 0)
                    {
                        userInfo.ClientBrowserWidth  = w;
                        userInfo.ClientBrowserHeight = h;
                    }
                    //缓存用户扩展信息
                    UserInfo.CacheUserExtendInfo(userInfo.UserName, userInfo.ExtendUserObject);
                    //保存票据
                    FormsPrincipal.Login(userInfo.UserName, userInfo, UserInfo.ACCOUNT_EXPIRATION_TIME, app.Context);
                }
                FormsPrincipal.TrySetUserInfo(app.Context);
            }
            else
            {
                FormsPrincipal.TrySetUserInfo(app.Context);
            }
        }
示例#16
0
        /// <summary>
        /// 模块管理员配置修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public ActionResult UpdateModularInfo(UserOperate dto)
        {
            ResultData <object> result = new ResultData <object>();
            UserLoginDTO        user   = (UserLoginDTO)Session["UserLoginInfo"];

            dto.ModifyUser = user.FullName;
            dto.ModifyTime = DateTime.Now;
            dto.Uptype     = 5;
            try
            {
                result = SystemProvider.UpdateModularInfo(dto);
            }
            catch (Exception ex)
            {
                result.SubmitResult = false;
                result.Message      = ex.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
示例#17
0
        /// <summary>
        /// 修改模块管理员邮箱
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public bool UpdateModularAdmin(UserOperate dto)
        {
            bool blResult = false;

            using (var tcdmse = new Entities.TCDMS_MasterDataEntities())
            {
                var pp = tcdmse.master_UserInfo.Where(p => p.UserID == dto.UserID).FirstOrDefault();
                if (pp == null)
                {
                    throw new Exception("此条信息不存在!");
                }
                pp.ModifyUser = dto.ModifyUser;
                pp.ModifyTime = dto.ModifyTime;
                pp.Email      = dto.Email;

                blResult = tcdmse.SaveChanges() > 0;
            }

            return(blResult);
        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <returns></returns>
        public JsonResult ChangePwd()
        {
            if (_Request == null)
            {
                _Request = Request;
            }
            SetRequest(_Request);
            UserInfo currUser = GetCurrentUser(_Request);

            if (currUser == null)
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "您未登录系统或登录时间过长,请重新登录系统后再修改密码!"
                }));
            }
            string   errMsg       = string.Empty;
            string   oldPwd       = _Request.QueryEx("oldPwd").ObjToStr();
            string   newPwd       = _Request.QueryEx("newPwd").ObjToStr();
            UserInfo tempUserInfo = UserOperate.GetUserInfo(currUser.UserName, oldPwd, out errMsg);

            if (tempUserInfo == null)
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "您当前登录密码输入不正确,请重新输入!"
                }));
            }
            bool rs = UserOperate.ModifyPassword(currUser.UserId, newPwd, out errMsg);

            if (rs)
            {
                CommonOperate.ExecuteUserOperateHandleMethod("AfterChangePwd", new object[] { currUser.UserName, oldPwd, newPwd });
            }
            return(Json(new ReturnResult()
            {
                Success = rs, Message = errMsg
            }));
        }
示例#19
0
        /// <summary>
        /// 用户信息删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public ActionResult DeleteUser(UserOperate dto)
        {
            ResultData <object> result = new ResultData <object>();
            UserLoginDTO        user   = (UserLoginDTO)Session["UserLoginInfo"];

            try
            {
                dto.ModifyUser = user.FullName;
                if (dto.UserID == 1)
                {
                    throw new Exception("系统初始化用户不予删除");
                }
                result = UserAuthorityProvider.DeleteUser(dto);
            }
            catch (Exception ex)
            {
                result.SubmitResult = false;
                result.Message      = ex.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public JsonResult UserLogin(string username, string userpwd, string valcode)
        {
            if (string.IsNullOrEmpty(username))
            {
                return(Json(new LoginReturnResult()
                {
                    Success = false, Message = "用户名不能为空", IsShowCode = false
                }));
            }
            if (_Request == null)
            {
                _Request = Request;
            }
            if (_Response == null)
            {
                _Response = Response;
            }
            string errMsg = string.Empty;
            //获取用户信息
            string   tempUserName = GetUserName(username);
            UserInfo userInfo     = UserOperate.GetUserInfo(tempUserName, userpwd, out errMsg);

            if (!string.IsNullOrEmpty(errMsg))
            {
                return(Json(new LoginReturnResult()
                {
                    Success = false, Message = errMsg, IsShowCode = false
                }));
            }
            CacheUserData(userInfo); //缓存cookie
            //执行登录成功后的操作
            CommonOperate.ExecuteUserOperateHandleMethod("AfterLoginSuccess", new object[] { _Request, _Response, username, userpwd, UserInfo.ACCOUNT_EXPIRATION_TIME });

            return(Json(new LoginReturnResult()
            {
                Success = true, Message = string.Empty, Url = string.Empty
            }));
        }
示例#21
0
        public HttpResponseMessage AddUser(UserOperate dto)
        {
            ResultDTO <object> resultdto = new ResultDTO <object>();

            try
            {
                resultdto.SubmitResult = _lUserAuthorityServices.AddUser(dto);
            }
            catch (Exception ex)
            {
                resultdto.SubmitResult = false;
                resultdto.Message      = ex.Message;
            }

            HttpResponseMessage result = new HttpResponseMessage
            {
                Content = new StringContent(JsonConvert.SerializeObject(resultdto),
                                            System.Text.Encoding.GetEncoding("UTF-8"),
                                            "application/json")
            };

            return(result);
        }
示例#22
0
        /// <summary>
        /// 用户信息停启用
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public bool StopEnableUser(UserOperate dto)
        {
            bool blResult = false;

            using (var tcdmse = new Entities.TCDMS_MasterDataEntities())
            {
                var pp = tcdmse.master_UserInfo.Where(p => p.UserID == dto.UserID).FirstOrDefault();
                if (pp == null)
                {
                    throw new Exception("此条信息不存在!");
                }
                if (dto.IsActive == true && pp.StopTime < DateTime.Now)
                {
                    throw new Exception("该用户已到期,启用无效");
                }
                pp.ModifyUser   = dto.ModifyUser;
                pp.ModifyTime   = dto.ModifyTime;
                pp.IsActive     = dto.IsActive;
                pp.NoActiveTime = dto.NoActiveTime;

                if (dto.IsActive == false)
                {
                    // 记录日志
                    this.AddLog(tcdmse, new LogData
                    {
                        CurrentLogType = LogType.UNENABLE,
                        LogDetails     = "停用用户" + pp.FullName,
                        OpratorName    = dto.ModifyUser
                    });
                }

                blResult = tcdmse.SaveChanges() > 0;
            }

            return(blResult);
        }
        /// <summary>
        /// 获取用户名
        /// </summary>
        /// <param name="username">用户名或工号或邮箱或手机号</param>
        /// <returns></returns>
        private string GetUserName(string username)
        {
            string tempUserName = username.Trim();
            string errMsg       = string.Empty;

            if (GlobalSet.IsAllowOtherConfigRuleLogin) //允许其他方式登录
            {
                //先检测默认登录规则账号是否存在
                bool rs = UserOperate.UserIsValid(tempUserName, out errMsg);
                if (rs)
                {
                    return(tempUserName);
                }
                //默认登录规则账号不存在时检测其他方式
                OrgM_Emp emp = null;
                switch (GlobalSet.EmpUserNameConfigRule)
                {
                case UserNameAndEmpConfigRule.EmpCode:
                {
                    emp = OrgMOperate.GetEmpByMobile(tempUserName);         //根据手机号获取员工
                    if (emp == null)
                    {
                        emp = OrgMOperate.GetEmpByEmail(tempUserName);         //根据邮箱获取员工
                        if (emp == null)
                        {
                            emp = OrgMOperate.GetEmpByEmailPrex(tempUserName);         //根据邮箱前缀获取员工
                        }
                    }
                }
                break;

                case UserNameAndEmpConfigRule.Mobile:
                {
                    emp = OrgMOperate.GetEmpByCode(tempUserName);         //根据工号获取员工
                    if (emp == null)
                    {
                        emp = OrgMOperate.GetEmpByEmail(tempUserName);         //根据邮箱获取员工
                        if (emp == null)
                        {
                            emp = OrgMOperate.GetEmpByEmailPrex(tempUserName);         //根据邮箱前缀获取员工
                        }
                    }
                }
                break;

                case UserNameAndEmpConfigRule.Email:
                {
                    emp = OrgMOperate.GetEmpByCode(tempUserName);         //根据工号获取员工
                    if (emp == null)
                    {
                        emp = OrgMOperate.GetEmpByMobile(tempUserName);         //根据手机号获取员工
                        if (emp == null)
                        {
                            emp = OrgMOperate.GetEmpByEmailPrex(tempUserName);         //根据邮箱前缀获取员工
                        }
                    }
                }
                break;

                case UserNameAndEmpConfigRule.EmailPre:
                {
                    emp = OrgMOperate.GetEmpByCode(tempUserName);         //根据工号获取员工
                    if (emp == null)
                    {
                        emp = OrgMOperate.GetEmpByMobile(tempUserName);         //根据手机号获取员工
                        if (emp == null)
                        {
                            emp = OrgMOperate.GetEmpByEmail(tempUserName);         //根据邮箱获取员工
                        }
                    }
                }
                break;
                }
                if (emp != null)
                {
                    return(OrgMOperate.GetUserNameByEmp(emp));
                }
            }
            return(tempUserName);
        }
示例#24
0
        /// <summary>
        /// 添加客户管理员
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public static ResultData <object> AddCustomerAdmin(UserOperate dto)
        {
            ResultData <object> result = PutAPI <ResultData <object> >(WebConfiger.MasterDataServicesUrl + "UserManager", dto);

            return(result);
        }
示例#25
0
        /// <summary>
        /// 用户信息新增
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public bool AddUser(UserOperate dto)
        {
            bool blResult = false;

            using (var tcdmse = new Entities.TCDMS_MasterDataEntities())
            {
                //判断手机号
                var pn = tcdmse.master_UserInfo.Where(p => p.PhoneNumber == dto.PhoneNumber).FirstOrDefault();
                if (pn != null)
                {
                    throw new Exception("该手机号已存在!");
                }
                //用户
                master_UserInfo user = new master_UserInfo();
                Mapper.Map <UserOperate, master_UserInfo>(dto, user);
                tcdmse.master_UserInfo.Add(user);
                tcdmse.SaveChanges();
                //用户权限
                if (dto.UserAuthority != null)
                {
                    foreach (var i in dto.UserAuthority)
                    {
                        if (i == null)
                        {
                            continue;
                        }
                        master_UserCustomerAuthority userauthority = new master_UserCustomerAuthority();
                        userauthority.UserID              = user.UserID;
                        userauthority.StructureID         = i.StructureID;
                        userauthority.UserButtonAuthority = i.UserButtonAuthority;

                        tcdmse.master_UserCustomerAuthority.Add(userauthority);
                    }
                }
                //用户角色
                if (dto.UserRole != null)
                {
                    var    ur      = tcdmse.master_RoleInfo.Where(r => dto.UserRole.Contains(r.RoleID)).ToList();
                    string rolestr = string.Join(",", ur.Select(s => s.RoleName).ToArray());//取得新增角色(日志)
                    foreach (var u in ur)
                    {
                        user.master_RoleInfo.Add(u);
                    }

                    // 记录日志
                    if (!string.IsNullOrEmpty(rolestr))
                    {
                        this.AddLog(tcdmse, new LogData
                        {
                            CurrentLogType = LogType.ADD,
                            LogDetails     = "新增用户角色:" + "用户:" + dto.FullName + "角色:" + rolestr,
                            OpratorName    = dto.CreateUser
                        });
                    }
                }
                //关联经销商
                if (dto.UserDistributor != null)
                {
                    var    ur     = tcdmse.master_DistributorInfo.Where(r => dto.UserDistributor.Contains(r.DistributorID)).ToList();
                    string disstr = string.Join(",", ur.Select(s => s.DistributorName).ToArray());//取得新增经销商(日志)
                    foreach (var u in ur)
                    {
                        user.master_DistributorInfo.Add(u);
                    }

                    // 记录日志
                    if (!string.IsNullOrEmpty(disstr))
                    {
                        this.AddLog(tcdmse, new LogData
                        {
                            CurrentLogType = LogType.ADD,
                            LogDetails     = "新增用户关联经销商:" + "用户:" + dto.FullName + "经销商:" + disstr,
                            OpratorName    = dto.CreateUser
                        });
                    }
                }

                // 记录日志
                this.AddLog(tcdmse, new LogData
                {
                    CurrentLogType = LogType.ADD,
                    LogDetails     = "新增用户" + dto.FullName,
                    OpratorName    = dto.CreateUser
                });

                blResult = tcdmse.SaveChanges() > 0;
                blResult = true;
            }

            return(blResult);
        }
        public JsonResult UserForgetPwd(string username)
        {
            string userTipDes = "用户名";

            if (GlobalSet.EmpUserNameConfigRule == UserNameAndEmpConfigRule.Email)
            {
                userTipDes = "邮箱";
            }
            else if (GlobalSet.EmpUserNameConfigRule == UserNameAndEmpConfigRule.Mobile)
            {
                userTipDes = "手机号";
            }
            if (string.IsNullOrEmpty(username))
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = string.Format("{0}不能为空!", userTipDes)
                }));
            }
            if (GlobalSet.EmpUserNameConfigRule == UserNameAndEmpConfigRule.Email && !Validator.IsEmail(username))
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "请输入正确的邮箱地址!"
                }));
            }
            if (GlobalSet.EmpUserNameConfigRule == UserNameAndEmpConfigRule.Mobile && !Validator.IsMobilePhoneNumber(username))
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "请输入正确的手机号码!"
                }));
            }
            string errMsg = string.Empty;
            bool   rs     = UserOperate.UserIsValid(username, out errMsg);

            if (!rs)
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = errMsg
                }));
            }
            string email = username;

            if (GlobalSet.EmpUserNameConfigRule != UserNameAndEmpConfigRule.Email)
            {
                OrgM_Emp emp = OrgMOperate.GetEmpByUserName(username);
                if (emp != null)
                {
                    email = OrgMOperate.GetEmployeeEmails(new List <Guid>()
                    {
                        emp.Id
                    }).Keys.FirstOrDefault();
                }
            }
            if (!email.Contains("@"))
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "获取用户邮箱失败!"
                }));
            }
            Dictionary <string, string> dicMail = new Dictionary <string, string>();

            dicMail.Add(email, email);
            string   subject = string.Format("重置您在{0}的密码", WebConfigHelper.GetCurrWebName());
            Sys_User user    = UserOperate.GetUser(username);
            string   content = GetForgetPwdSendContent(user);

            errMsg = SystemOperate.EmailSend(subject, content, dicMail, null, null, null, true);
            return(Json(new ReturnResult()
            {
                Success = string.IsNullOrEmpty(errMsg), Message = errMsg
            }));
        }
示例#27
0
        /// <summary>
        /// 用户信息修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public bool UpdateUser(UserOperate dto)
        {
            bool blResult = false;

            using (var tcdmse = new Entities.TCDMS_MasterDataEntities())
            {
                var pp = tcdmse.master_UserInfo.Where(p => p.UserID == dto.UserID).FirstOrDefault();
                if (pp == null)
                {
                    throw new Exception("此条信息不存在!");
                }

                var pn = tcdmse.master_UserInfo.Where(p => p.UserID != dto.UserID && p.PhoneNumber == dto.PhoneNumber).FirstOrDefault();
                if (pn != null)
                {
                    throw new Exception("该手机号已存在!");
                }
                //用户权限
                var ww = tcdmse.master_UserCustomerAuthority.Where(w => w.UserID == pp.UserID);
                tcdmse.master_UserCustomerAuthority.RemoveRange(ww);
                if (dto.UserAuthority != null)
                {
                    foreach (var i in dto.UserAuthority)
                    {
                        if (i == null)
                        {
                            continue;
                        }
                        master_UserCustomerAuthority userauthority = new master_UserCustomerAuthority();
                        userauthority.UserID              = pp.UserID;
                        userauthority.StructureID         = i.StructureID;
                        userauthority.UserButtonAuthority = i.UserButtonAuthority;

                        tcdmse.master_UserCustomerAuthority.Add(userauthority);
                    }
                }
                //用户角色
                if (pp.master_AreaInfo.Count > 0)
                {
                    if (dto.UserRole == null || dto.UserRole.Where(p => p.Value == 98).Count() == 0)
                    {
                        throw new Exception("已负责区域,无法去除客户管理员角色");
                    }
                }

                var OldRoleID = pp.master_RoleInfo.Select(q => q.RoleID).ToList();
                var llRoleID  = dto.UserRole != null?dto.UserRole.Select(p => p.Value).ToList() : new List <int>();

                var ChangeRoleID = OldRoleID.Except(llRoleID).Union(
                    llRoleID.Except(OldRoleID)
                    ).ToList();

                if (ChangeRoleID.Count > 0)
                {
                    //记录日志

                    string roledelstr = string.Join(",", pp.master_RoleInfo.Select(s => s.RoleName).ToArray());
                    if (!string.IsNullOrEmpty(roledelstr))
                    {
                        this.AddLog(tcdmse, new LogData
                        {
                            CurrentLogType = LogType.DELETE,
                            LogDetails     = "删除用户角色:" + "用户:" + dto.FullName + "角色:" + roledelstr,
                            OpratorName    = dto.ModifyUser
                        });
                    }

                    pp.master_RoleInfo.Clear();
                    if (dto.UserRole != null)
                    {
                        var ur = tcdmse.master_RoleInfo.Where(r => dto.UserRole.Contains(r.RoleID)).ToList();
                        foreach (var u in ur)
                        {
                            pp.master_RoleInfo.Add(u);
                        }

                        //记录日志
                        string rolestr = string.Join(",", pp.master_RoleInfo.Select(s => s.RoleName).ToArray());
                        this.AddLog(tcdmse, new LogData
                        {
                            CurrentLogType = LogType.ADD,
                            LogDetails     = "新增用户角色:" + "用户:" + dto.FullName + "角色:" + rolestr,
                            OpratorName    = dto.ModifyUser
                        });
                    }
                }


                var OldID = pp.master_DistributorInfo.Select(q => q.DistributorID).ToList();
                var llid  = dto.UserDistributor != null?dto.UserDistributor.Select(p => p.Value).ToList() : new List <Guid>();

                var Change = OldID.Except(llid).Union(
                    llid.Except(OldID)
                    ).ToList();
                if (Change.Count > 0)
                {
                    string disdelstr = string.Join(",", pp.master_DistributorInfo.Select(s => s.DistributorName).ToArray());
                    if (!string.IsNullOrEmpty(disdelstr))
                    {
                        this.AddLog(tcdmse, new LogData
                        {
                            CurrentLogType = LogType.DELETE,
                            LogDetails     = "删除用户关联经销商:" + "用户:" + dto.FullName + "经销商:" + disdelstr,
                            OpratorName    = dto.ModifyUser
                        });
                    }

                    //关联经销商
                    //记录日志
                    pp.master_DistributorInfo.Clear();
                    if (dto.UserDistributor != null)
                    {
                        var    ur     = tcdmse.master_DistributorInfo.Where(r => dto.UserDistributor.Contains(r.DistributorID)).ToList();
                        string disstr = string.Join(",", ur.Select(s => s.DistributorName).ToArray());//取得新增经销商(日志)
                        foreach (var u in ur)
                        {
                            pp.master_DistributorInfo.Add(u);
                        }

                        // 记录日志
                        this.AddLog(tcdmse, new LogData
                        {
                            CurrentLogType = LogType.ADD,
                            LogDetails     = "新增用户关联经销商:" + "用户:" + dto.FullName + "经销商:" + disstr,
                            OpratorName    = dto.ModifyUser
                        });
                    }
                }
                //用户
                pp.UserType    = dto.UserType;
                pp.UserCode    = dto.UserCode;
                pp.PhoneNumber = dto.PhoneNumber;
                pp.FullName    = dto.FullName;
                pp.Email       = dto.Email;
                pp.DepartID    = dto.DepartID;
                pp.StopTime    = dto.StopTime;
                pp.ModifyTime  = dto.ModifyTime;
                pp.ModifyUser  = dto.ModifyUser;

                blResult = tcdmse.SaveChanges() > 0;
                blResult = true;
            }

            return(blResult);
        }
示例#28
0
 public UserVM()
 {
     _UserOperate = new UserOperate();
 }
示例#29
0
        public ActionResult UserLogin(string username, string userpwd, string valcode)
        {
            if (_Request == null)
            {
                _Request = Request;
            }
            if (_Response == null)
            {
                _Response = Response;
            }
            if (_Session == null)
            {
                _Session = Session;
            }
            string errMsg = string.Empty;

            ViewBag.IsShowValidateCode = "false";
            bool isNoCode = _Request["isNoCode"].ObjToBool(); //是否不需要验证码

            if (!isNoCode && _Session[LOGINERROR].ObjToInt() >= 2)
            {
                bool validatecode = false;
                if (_TempData.ContainsKey(SecurityController.VALIDATECODE))
                {
                    string code = _TempData[SecurityController.VALIDATECODE].ToString();
                    validatecode = valcode.ToLower() == code.ToLower();
                }
                if (!validatecode)
                {
                    return(Json(new LoginReturnResult()
                    {
                        Success = false, Message = "验证码错误!", IsShowCode = true
                    }));
                }
            }
            //获取用户信息
            string   tempUserName = GetUserName(username);
            UserInfo userInfo     = UserOperate.GetUserInfo(tempUserName, userpwd, out errMsg);

            if (!string.IsNullOrEmpty(errMsg))
            {
                var isShowCode = false;
                _Session[LOGINERROR] = _Session[LOGINERROR] == null ? 0 : _Session[LOGINERROR].ObjToInt() + 1;
                if (!isNoCode && _Session[LOGINERROR].ObjToInt() >= 2)
                {
                    isShowCode = true;
                }
                return(Json(new LoginReturnResult()
                {
                    Success = false, Message = errMsg, IsShowCode = isShowCode
                }));
            }
            CacheUserData(userInfo); //缓存cookie
            //执行登录成功后的操作
            CommonOperate.ExecuteUserOperateHandleMethod("AfterLoginSuccess", new object[] { _Session, _Request, _Response, username, userpwd, UserInfo.ACCOUNT_EXPIRATION_TIME });

            return(Json(new LoginReturnResult()
            {
                Success = true, Message = string.Empty, Url = HttpUtility.UrlEncode(string.Empty)
            }));
        }
示例#30
0
 /// <summary>
 /// 员工操作完成
 /// </summary>
 /// <param name="operateType">操作类型</param>
 /// <param name="t">员工对象</param>
 /// <param name="result">操作结果</param>
 /// <param name="currUser">当前用户</param>
 /// <param name="otherParams"></param>
 public void OperateCompeletedHandle(ModelRecordOperateType operateType, OrgM_Emp t, bool result, UserInfo currUser, object[] otherParams = null)
 {
     if (result)
     {
         string errMsg      = string.Empty;
         string username    = OrgMOperate.GetUserNameByEmp(t);
         string userInitPwd = WebConfigHelper.GetAppSettingValue("UserInitPwd");
         if (string.IsNullOrEmpty(userInitPwd))
         {
             userInitPwd = "123456";
         }
         if (operateType == ModelRecordOperateType.Add)
         {
             if (!string.IsNullOrEmpty(username))
             {
                 UserOperate.AddUser(out errMsg, username, userInitPwd, null, t.Name);
             }
         }
         else if (operateType == ModelRecordOperateType.Edit)
         {
             if (!string.IsNullOrEmpty(username))
             {
                 Sys_User user = UserOperate.GetUser(username);
                 if (user != null) //用户已存在
                 {
                     UserOperate.UpdateUserAliasName(username, t.Name);
                 }
                 else //用户不存在
                 {
                     UserOperate.AddUser(out errMsg, username, userInitPwd, null, t.Name);
                 }
             }
         }
         else if (operateType == ModelRecordOperateType.Del)
         {
             if (!string.IsNullOrEmpty(username))
             {
                 UserOperate.DelUser(username); //删除账号
             }
             //删除员工同时删除员工岗位
             CommonOperate.DeleteRecordsByExpression <OrgM_EmpDeptDuty>(x => x.OrgM_EmpId == t.Id, out errMsg, t.IsDeleted);
         }
         if (operateType == ModelRecordOperateType.Add || operateType == ModelRecordOperateType.Edit)
         {
             //新增编辑时同时设置员工主职岗位
             if (t.DeptId.HasValue && t.DeptId.Value != Guid.Empty && t.DutyId.HasValue && t.DutyId.Value != Guid.Empty)
             {
                 OrgM_EmpDeptDuty empPosition = null;
                 if (operateType == ModelRecordOperateType.Edit)
                 {
                     empPosition = CommonOperate.GetEntity <OrgM_EmpDeptDuty>(x => x.OrgM_EmpId == t.Id && x.IsMainDuty == true, null, out errMsg);
                     if (empPosition != null)
                     {
                         empPosition.OrgM_DeptId    = t.DeptId.Value;
                         empPosition.OrgM_DutyId    = t.DutyId.Value;
                         empPosition.IsValid        = true;
                         empPosition.ModifyDate     = DateTime.Now;
                         empPosition.ModifyUserId   = currUser.UserId;
                         empPosition.ModifyUserName = currUser.EmpName;
                         CommonOperate.OperateRecord <OrgM_EmpDeptDuty>(empPosition, ModelRecordOperateType.Edit, out errMsg, null, false);
                         return;
                     }
                 }
                 Guid   moduleId = SystemOperate.GetModuleIdByModelType(typeof(OrgM_EmpDeptDuty));
                 string code     = SystemOperate.GetBillCode(moduleId);
                 empPosition = new OrgM_EmpDeptDuty()
                 {
                     Code           = code,
                     OrgM_DeptId    = t.DeptId.Value,
                     OrgM_DutyId    = t.DutyId.Value,
                     OrgM_EmpId     = t.Id,
                     IsMainDuty     = true,
                     IsValid        = true,
                     EffectiveDate  = DateTime.Now,
                     CreateDate     = DateTime.Now,
                     CreateUserId   = currUser.UserId,
                     CreateUserName = currUser.EmpName,
                     ModifyDate     = DateTime.Now,
                     ModifyUserId   = currUser.UserId,
                     ModifyUserName = currUser.EmpName
                 };
                 Guid rs = CommonOperate.OperateRecord <OrgM_EmpDeptDuty>(empPosition, ModelRecordOperateType.Add, out errMsg, null, false);
                 if (rs != Guid.Empty)
                 {
                     SystemOperate.UpdateBillCode(moduleId, code);
                 }
             }
         }
     }
 }