public ActionResult Form(Sys_User model, string password, string roleIds)
 {
     if (model.Id.IsNullOrEmpty())
     {
         //新增用户基本信息。
         var userId = _userService.Insert(model).ToString();
         //新增用户角色信息。
         _userRoleRelationService.SetRole(userId, roleIds.ToStrArray());
         //新增用户登陆信息。
         Sys_UserLogOn userLogOnEntity = new Sys_UserLogOn()
         {
             UserId   = userId,
             Password = password
         };
         var userLoginId = _userLogOnService.Insert(userLogOnEntity);
         return(userId != null && userLoginId != null?Success() : Error());
     }
     else
     {
         //更新用户基本信息。
         int row = _userService.Update(model);
         //更新用户角色信息。
         _userRoleRelationService.SetRole(model.Id, roleIds.ToStrArray());
         return(row > 0 ? Success() : Error());
     }
 }
Exemple #2
0
        public void SubmitForm(Sys_User userEntity, Sys_UserLogOn userLogOnEntity, string keyValue)
        {
            var role = _repository.FindEntity <Sys_Role>(p => p.F_Id == userEntity.F_RoleId);

            if (!string.IsNullOrEmpty(keyValue))
            {
                //userEntity.Modify(keyValue);
                userEntity.F_Id               = keyValue;
                userEntity.F_LastModifyTime   = DateTime.Now;
                userEntity.F_LastModifyUserId = OperatorProvider.Provider.GetCurrent().UserId;
                var op = OperatorProvider.Provider.GetCurrent();
                LogHelper.Info("用户信息:【" + keyValue + "】修改!操作人账号:" + op.UserCode + ",操作人名称:" + op.UserName + ",操作时间" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Code.Enum.OpType.System, null, "", "", ViewLevel.Admin);
            }
            else
            {
                #region Sys_User表
                //userEntity.Create();
                userEntity.F_Id             = Common.GuId();
                userEntity.F_CreatorUserId  = OperatorProvider.Provider.GetCurrent().UserId;
                userEntity.F_CreatorTime    = DateTime.Now;
                userEntity.F_LastModifyTime = DateTime.Now;
                var op = OperatorProvider.Provider.GetCurrent();
                LogHelper.Info("用户信息:【" + keyValue + "】新增!操作人账号:" + op.UserCode + ",操作人名称:" + op.UserName + ",操作时间" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Code.Enum.OpType.System, null, "", "", ViewLevel.Admin);
                #endregion
            }
            service.SubmitForm(userEntity, userLogOnEntity, keyValue);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="oldPassword">明文</param>
        /// <param name="newPassword">明文</param>
        public void ChangePassword(string oldPassword, string newPassword)
        {
            PasswordHelper.EnsurePasswordLegal(newPassword);

            AdminSession session = this.Session;

            Sys_UserLogOn userLogOn = this.DbContext.Query <Sys_UserLogOn>().Where(a => a.UserId == session.UserId).First();

            string encryptedOldPassword = PasswordHelper.Encrypt(oldPassword, userLogOn.UserSecretkey);

            if (encryptedOldPassword != userLogOn.UserPassword)
            {
                throw new Ace.Exceptions.InvalidDataException("旧密码不正确");
            }

            string newUserSecretkey     = UserHelper.GenUserSecretkey();
            string newEncryptedPassword = PasswordHelper.Encrypt(newPassword, newUserSecretkey);

            this.DbContext.DoWithTransaction(() =>
            {
                this.DbContext.Update <Sys_UserLogOn>(a => a.UserId == session.UserId, a => new Sys_UserLogOn()
                {
                    UserSecretkey = newUserSecretkey, UserPassword = newEncryptedPassword
                });
                this.Log(LogType.Update, "Account", true, "用户[{0}]修改密码".ToFormat(session.UserId));
            });
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="oldPassword">明文</param>
        /// <param name="newPassword">明文</param>
        public void ChangePassword(string userID, string oldPassword, string newPassword)
        {
            //EncryptHelper.DesEncrypt(newPassword);



            Sys_UserLogOn userLogOn = this.DbContext.Query <Sys_UserLogOn>().Where(a => a.UserId == userID).First();

            string encryptedOldPassword = EncryptHelper.DesEncrypt(oldPassword, userLogOn.UserSecretkey);

            if (encryptedOldPassword != userLogOn.UserPassword)
            {
                throw new InvalidInputException("旧密码不正确");
            }

            string newUserSecretkey     = KeyTool.GetEncryptKey();
            string newEncryptedPassword = EncryptHelper.DesEncrypt(newPassword, newUserSecretkey);

            this.DbContext.DoWithTransaction(() =>
            {
                this.DbContext.Update <Sys_UserLogOn>(a => a.UserId == userID, a => new Sys_UserLogOn()
                {
                    UserSecretkey = newUserSecretkey, UserPassword = newEncryptedPassword
                });
            });
        }
Exemple #5
0
 public void RevisePassword(Sys_UserLogOn userLogOnEntity, string account)
 {
     using (var db = new RepositoryBase().BeginTrans())
     {
         db.Update(userLogOnEntity);
         db.Commit();
     }
 }
Exemple #6
0
        public void RevisePassword(string userPassword, string keyValue)
        {
            Sys_UserLogOn userLogOnEntity = new Sys_UserLogOn();

            userLogOnEntity.F_Id            = keyValue;
            userLogOnEntity.F_UserSecretkey = Md5.md5(Common.CreateNo(), 16).ToLower();
            userLogOnEntity.F_UserPassword  = Md5.md5(DESEncrypt.Encrypt(Md5.md5(userPassword, 32).ToLower(), userLogOnEntity.F_UserSecretkey).ToLower(), 32).ToLower();
            service.Update(userLogOnEntity);
        }
Exemple #7
0
        public void RevisePassword(string userPassword, string keyValue, string account)
        {
            OperatorModel op = OperatorProvider.Provider.GetCurrent();
            Sys_UserLogOn userLogOnEntity = new Sys_UserLogOn();

            userLogOnEntity.F_Id            = keyValue;
            userLogOnEntity.F_UserSecretkey = Md5.md5(Common.CreateNo(), 16).ToLower();
            userLogOnEntity.F_UserPassword  = Md5.md5(DESEncrypt.Encrypt(Md5.md5(userPassword, 32).ToLower(), userLogOnEntity.F_UserSecretkey).ToLower(), 32).ToLower();
            service.Update(userLogOnEntity);
            LogHelper.Info("用户ID:【" + keyValue + "】密码重置!编辑人账号:" + op.UserCode + ",编辑人名称:" + op.UserName + ",编辑时间" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Code.Enum.OpType.System, null, "", "", ViewLevel.Admin);
            //service.RevisePassword(userLogOnEntity, account);
        }
Exemple #8
0
        public ActionResult GetToken(string account, string Pwd)
        {
            //account = "admin";
            //Pwd = "4a7d1ed414474e4033ac29ccb8653d9b";
            Sys_User    user = UserService.GetEntity(u => u.F_Account == account).FirstOrDefault();
            LoginResult loginResult;

            if (user == null)
            {
                loginResult = new LoginResult()
                {
                    Message    = "用户不存在",
                    Status     = false,
                    ResultCode = ResultCode.Error
                };
                return(Json(loginResult));
            }
            Sys_UserLogOn userLogOn = UserLogService.GetEntityByUserId(user.F_Id);

            if (userLogOn == null)
            {
                loginResult = new LoginResult()
                {
                    Message    = "查询不到密码信息",
                    Status     = false,
                    ResultCode = ResultCode.Error
                };
                return(Json(loginResult));
            }
            string key = userLogOn.F_UserSecretkey;
            string pwd = DESEncrypt.Encrypt(Pwd, key).ToLower().ToMd5().ToLower();

            if (userLogOn.F_UserPassword == pwd) //登录成功
            {
                Payload payload = new Payload()
                {
                    Account = account,
                    Exp     = DateTime.Now.AddDays(7),
                    Issuer  = "IServer",
                    IMEI    = "0000"
                };
                //创建一个token
                string token = JwtUtils.EncodingToken(payload);
                Cache.AddCache(token, payload, payload.Exp);

                return(Content(token));
            }
            loginResult = new LoginResult()
            {
                Message = "用户名密码错误", Status = false, ResultCode = ResultCode.Error
            };
            return(Json(loginResult));
        }
Exemple #9
0
 public ActionResult Form(Sys_UserLogOn model)
 {
     if (model.Id == null)
     {
         var primaryKey = _userLogOnService.Insert(model);
         return(primaryKey != null?Success() : Error());
     }
     else
     {
         var row = _userLogOnService.UpdateInfo(model);
         return(row > 0 ? Success() : Error());
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password">前端传过来的是经过md5加密后的密码</param>
        /// <param name="user"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool CheckLogin(string userName, string password, out Sys_User user, out string msg)
        {
            userName.NotNullOrEmpty();
            password.NotNullOrEmpty();

            user = null;
            msg  = null;

            var view = this.DbContext.JoinQuery <Sys_User, Sys_UserLogOn>((u, userLogOn) => new object[]
            {
                JoinType.InnerJoin, u.Id == userLogOn.UserId
            })
                       .Select((u, userLogOn) => new { User = u, UserLogOn = userLogOn });

            view = view.Where(a => a.User.IsDeleted == false);

            var viewEntity = view.FirstOrDefault(a => a.User.UserName == userName);

            if (viewEntity == null)
            {
                msg = "账户不存在,请重新输入";
                return(false);
            }

            if (viewEntity.User.IsEnabled == false)
            {
                msg = "账户被系统锁定,请联系管理员";
                return(false);
            }

            Sys_User      userEntity      = viewEntity.User;
            Sys_UserLogOn userLogOnEntity = viewEntity.UserLogOn;

            string dbPassword = PasswordHelper.EncryptMD5Password(password, userLogOnEntity.UserSecretkey);

            if (dbPassword != userLogOnEntity.UserPassword)
            {
                msg = "密码不正确,请重新输入";
                return(false);
            }

            DateTime lastVisitTime = DateTime.Now;

            this.DbContext.Update <Sys_UserLogOn>(a => a.Id == userLogOnEntity.Id, a => new Sys_UserLogOn()
            {
                LogOnCount = a.LogOnCount + 1, PreviousVisitTime = userLogOnEntity.LastVisitTime, LastVisitTime = lastVisitTime
            });
            user = userEntity;
            return(true);
        }
Exemple #11
0
        public void AddUser(AddUserInput input)
        {
            input.Validate();

            string userName = input.UserName.ToLower();

            bool exists = this.DbContext.GetSys_Users().Where(a => a.UserName == userName).Any();

            if (exists)
            {
                throw new InvalidDataException("用户名[{0}]已存在".ToFormat(input.UserName));
            }

            Sys_User user = this.CreateEntity <Sys_User>();

            user.UserName     = userName;
            user.DepartmentId = input.DepartmentId;
            user.RoleId       = input.RoleId;
            user.DutyId       = input.DutyId;
            user.RealName     = input.RealName;
            user.Gender       = input.Gender;
            user.MobilePhone  = input.MobilePhone;
            user.Birthday     = input.Birthday;
            user.WeChat       = input.WeChat;
            user.Email        = input.Email;
            user.IsEnabled    = input.IsEnabled;
            user.Description  = input.Description;

            string userSecretkey     = UserHelper.GenUserSecretkey();
            string encryptedPassword = PasswordHelper.Encrypt(input.Password, userSecretkey);

            Sys_UserLogOn logOnEntity = new Sys_UserLogOn();

            logOnEntity.Id            = IdHelper.CreateGuid();
            logOnEntity.UserId        = user.Id;
            logOnEntity.UserSecretkey = userSecretkey;
            logOnEntity.UserPassword  = encryptedPassword;

            this.DbContext.DoWithTransaction(() =>
            {
                this.DbContext.Insert(user);
                this.DbContext.Insert(logOnEntity);
            });
        }
Exemple #12
0
 public void SubmitForm(Sys_User userEntity, Sys_UserLogOn userLogOnEntity, string keyValue)
 {
     using (var db = new RepositoryBase().BeginTrans())
     {
         if (!string.IsNullOrEmpty(keyValue))
         {
             db.Update(userEntity);
         }
         else
         {
             userLogOnEntity.F_Id            = userEntity.F_Id;
             userLogOnEntity.F_UserId        = userEntity.F_Id;
             userLogOnEntity.F_UserSecretkey = Md5.md5(Common.CreateNo(), 16).ToLower();
             userLogOnEntity.F_UserPassword  = Md5.md5(DESEncrypt.Encrypt(Md5.md5(userLogOnEntity.F_UserPassword, 32).ToLower(), userLogOnEntity.F_UserSecretkey).ToLower(), 32).ToLower();
             db.Insert(userEntity);
             db.Insert(userLogOnEntity);
         }
         db.Commit();
     }
 }
Exemple #13
0
        public Sys_User CheckLogin(string username, string password)
        {
            Sys_User userEntity = service.FindEntity(t => t.F_Account == username);

            if (userEntity != null)
            {
                if (userEntity.F_EnabledMark == true)
                {
                    Sys_UserLogOn userLogOnEntity = userLogOnApp.GetForm(userEntity.F_Id);
                    string        dbPassword      = Md5.md5(DESEncrypt.Encrypt(password.ToLower(), userLogOnEntity.F_UserSecretkey).ToLower(), 32).ToLower();
                    if (dbPassword == userLogOnEntity.F_UserPassword)
                    {
                        DateTime lastVisitTime = DateTime.Now;
                        int      LogOnCount    = (userLogOnEntity.F_LogOnCount).ToInt() + 1;
                        if (userLogOnEntity.F_LastVisitTime != null)
                        {
                            userLogOnEntity.F_PreviousVisitTime = userLogOnEntity.F_LastVisitTime.ToDate();
                        }
                        userLogOnEntity.F_LastVisitTime = lastVisitTime;
                        userLogOnEntity.F_LogOnCount    = LogOnCount;
                        userLogOnApp.UpdateForm(userLogOnEntity);
                        return(userEntity);
                    }
                    else
                    {
                        throw new Exception("密码不正确,请重新输入");
                    }
                }
                else
                {
                    throw new Exception("账户被系统锁定,请联系管理员");
                }
            }
            else
            {
                throw new Exception("账户不存在,请重新输入");
            }
        }
Exemple #14
0
 public void SubmitForm(Sys_User entity, Sys_UserLogOn userLogOnEntity, string keyValue)
 {
     if (!string.IsNullOrEmpty(keyValue))
     {
         entity.F_Id = keyValue;
         var LoginInfo = OperatorProvider.Provider.GetCurrent();
         if (LoginInfo != null)
         {
             entity.F_LastModifyUserId = LoginInfo.UserId;
         }
         entity.F_LastModifyTime = DateTime.Now;
     }
     else
     {
         entity.F_Id = Common.GuId();
         var LoginInfo = OperatorProvider.Provider.GetCurrent();
         if (LoginInfo != null)
         {
             entity.F_CreatorUserId = LoginInfo.UserId;
         }
         entity.F_CreatorTime = DateTime.Now;
     }
     service.SubmitForm(entity, userLogOnEntity, keyValue);
 }
Exemple #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="loginName"></param>
        /// <param name="password">前端传过来的是经过md5加密后的密码</param>
        /// <param name="user"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool CheckLogin(string loginName, string password, out Sys_User user, out string msg)
        {
            user = null;
            msg  = null;

            loginName.NotNullOrEmpty();
            password.NotNullOrEmpty();

            var view = this.DbContext.JoinQuery <Sys_User, Sys_UserLogOn>((u, userLogOn) => new object[]
            {
                JoinType.InnerJoin, u.Id == userLogOn.UserId
            })
                       .Select((u, userLogOn) => new { User = u, UserLogOn = userLogOn });

            loginName = loginName.ToLower();
            if (AceUtils.IsMobilePhone(loginName))
            {
                view = view.Where(a => a.User.MobilePhone == loginName);
            }
            else if (AceUtils.IsEmail(loginName))
            {
                view = view.Where(a => a.User.Email == loginName);
            }
            else
            {
                view = view.Where(a => a.User.AccountName == loginName);
            }

            view = view.Where(a => a.User.State != AccountState.Closed);

            var viewEntity = view.FirstOrDefault();

            if (viewEntity == null)
            {
                msg = "账户不存在,请重新输入";
                return(false);
            }
            if (!viewEntity.User.IsAdmin())
            {
                if (viewEntity.User.State == AccountState.Disabled)
                {
                    msg = "账户被禁用,请联系管理员";
                    return(false);
                }
            }

            Sys_User      userEntity      = viewEntity.User;
            Sys_UserLogOn userLogOnEntity = viewEntity.UserLogOn;

            string dbPassword = PasswordHelper.EncryptMD5Password(password, userLogOnEntity.UserSecretkey);

            if (dbPassword != userLogOnEntity.UserPassword)
            {
                msg = "密码不正确,请重新输入";
                return(false);
            }

            DateTime lastVisitTime = DateTime.Now;

            this.DbContext.Update <Sys_UserLogOn>(a => a.Id == userLogOnEntity.Id, a => new Sys_UserLogOn()
            {
                LogOnCount = a.LogOnCount + 1, PreviousVisitTime = userLogOnEntity.LastVisitTime, LastVisitTime = lastVisitTime
            });
            user = userEntity;
            return(true);
        }
        public HttpResponseMessage CheckLogin(string userAccount, string password, string code)
        {
            password = "******";
            ResultModel         result = new ResultModel();
            HttpResponseMessage httpResponseMessage = new HttpResponseMessage();

            try
            {
                if (string.IsNullOrWhiteSpace(userAccount))
                {
                    throw new Exception("用户名错误,请重新输入");
                }
                if (string.IsNullOrWhiteSpace(password))
                {
                    throw new Exception("密码错误,请重新输入");
                }
                if (HttpContext.Current.Session["ubif_session_verifycode"].IsEmpty() || Md5.md5(code.ToLower(), 16) != HttpContext.Current.Session["ubif_session_verifycode"].ToString())
                {
                    throw new Exception("验证码错误,请重新输入");
                }
                using (UbifBaseEntities context = new UbifBaseEntities())
                {
                    Sys_User userModel = context.Sys_User.Where(t => t.F_Account == userAccount).FirstOrDefault();//这个表存的用户名
                    if (userModel != null)
                    {
                        if (userModel.F_EnabledMark == true)
                        {
                            Sys_UserLogOn UserLogOnModel = context.Sys_UserLogOn.Where(t => t.F_UserId == userModel.F_Id).FirstOrDefault();//这个表存的登录密码
                            //string pw = Md5.md5(password.ToLower(), 16);//这个要前端加密,传过来,这句是前端写的
                            //UserLogOnModel.F_UserSecretkey  这个是什么意思?
                            string dbPassword = Md5.md5(DESEncrypt.Encrypt(password.ToLower(), UserLogOnModel.F_UserSecretkey).ToLower(), 32).ToLower();
                            if (dbPassword == UserLogOnModel.F_UserPassword)
                            {
                                DateTime lastVisitTime = DateTime.Now;
                                int      LogOnCount    = (UserLogOnModel.F_LogOnCount).ToInt() + 1;
                                if (UserLogOnModel.F_LastVisitTime != null)
                                {
                                    UserLogOnModel.F_PreviousVisitTime = UserLogOnModel.F_LastVisitTime.ToDate();
                                }
                                UserLogOnModel.F_LastVisitTime = lastVisitTime;
                                UserLogOnModel.F_LogOnCount    = LogOnCount;
                                //通过反射,遍历出值是空的字段,空的值不修改
                                PropertyInfo[] props = UserLogOnModel.GetType().GetProperties();
                                foreach (PropertyInfo prop in props)
                                {
                                    if (prop.GetValue(UserLogOnModel, null) != null)
                                    {
                                        if (prop.GetValue(UserLogOnModel, null).ToString() == "&nbsp;")
                                        {
                                            context.Entry(UserLogOnModel).Property(prop.Name).CurrentValue = null;
                                        }
                                        context.Entry(UserLogOnModel).Property(prop.Name).IsModified = true;
                                    }
                                }
                                context.SaveChanges();
                                // result.status = ResultType.success.ToString();
                            }
                            else
                            {
                                throw new Exception("密码不正确,请重新输入");
                            }
                        }
                        else
                        {
                            throw new Exception("账户被系统锁定,请联系管理员");
                        }
                    }
                    else
                    {
                        throw new Exception("账户不存在,请重新输入");
                    }

                    Sys_Log sys_Log = new Sys_Log();
                    sys_Log.F_ModuleName = "系统登录";
                    sys_Log.F_Type       = DbLogType.Login.ToString();
                }
            }
            catch (Exception e)
            {
            }
            result.status  = "1";
            result.message = "Api调用成功";
            httpResponseMessage.StatusCode = HttpStatusCode.OK;
            httpResponseMessage.Content    = new StringContent(result.ToJson(), System.Text.Encoding.UTF8, "application/json");;
            return(httpResponseMessage);
        }
Exemple #17
0
 public ActionResult SubmitForm(Sys_User userEntity, Sys_UserLogOn userLogOnEntity, string keyValue)
 {
     userApp.SubmitForm(userEntity, userLogOnEntity, keyValue);
     return(Success("操作成功。"));
 }
Exemple #18
0
        public ActionResult Logon(string account, string Pwd, string imei = "0000")
        {
            //TODO 最终上线要删除
            //测试初始化登录-begin
            //account = "admin";
            //Pwd = "4a7d1ed414474e4033ac29ccb8653d9b";
            Sys_User    user = UserService.GetEntity(u => u.F_Account == account).FirstOrDefault();
            LoginResult loginResult;

            if (user == null)
            {
                loginResult = new LoginResult()
                {
                    Message    = "用户不存在",
                    Status     = false,
                    ResultCode = ResultCode.Error
                };

                return(Json(loginResult));
            }
            Sys_UserLogOn userLogOn = UserLogService.GetEntityByUserId(user.F_Id);

            if (userLogOn == null)
            {
                loginResult = new LoginResult()
                {
                    Message    = "查询不到密码信息",
                    Status     = false,
                    ResultCode = ResultCode.Error
                };
                return(Json(loginResult));
            }
            string key = userLogOn.F_UserSecretkey;
            string pwd = DESEncrypt.Encrypt(Pwd, key).ToLower().ToMd5().ToLower();

            if (userLogOn.F_UserPassword == pwd) //登录成功
            {
                if (userLogOn.F_LastVisitTime != null)
                {
                    userLogOn.F_PreviousVisitTime = userLogOn.F_LastVisitTime;
                }
                userLogOn.F_LastVisitTime = DateTime.Now;
                userLogOn.F_LogOnCount    = userLogOn.F_LogOnCount + 1;
                UserLogService.UpdateEntityInfo(userLogOn);
                Payload payload = new Payload()
                {
                    Account = account,
                    Exp     = DateTime.Now.AddDays(7),
                    IMEI    = imei,
                    Issuer  = "IServer"
                };
                //创建一个token
                string token = JwtUtils.EncodingToken(payload);
                Cache.AddCache(token, payload, DateTime.Now.AddDays(7));
                loginResult = new LoginResult
                {
                    Message    = "登录成功",
                    Status     = true,
                    AppendData = token,
                    ResultCode = ResultCode.Ok
                };
                return(Json(loginResult));
            }
            loginResult = new LoginResult()
            {
                Message = "用户名密码错误", Status = false, ResultCode = ResultCode.Error
            };
            return(Json(loginResult));
        }
Exemple #19
0
        public void Add(AddUserInput input)
        {
            this.Trim(input);

            input.Validate();

            if (input.AccountName.IsNullOrEmpty() && input.MobilePhone.IsNullOrEmpty() && input.Email.IsNullOrEmpty())
            {
                throw new InvalidInputException("用户名/手机号码/邮箱至少填一个");
            }

            string accountName = null;

            if (input.AccountName.IsNotNullOrEmpty())
            {
                accountName = input.AccountName.ToLower();
                AceUtils.EnsureAccountNameLegal(accountName);
                bool exists = this.DbContext.Query <Sys_User>().Where(a => a.AccountName == accountName).Any();
                if (exists)
                {
                    throw new InvalidInputException("用户名[{0}]已存在".ToFormat(input.AccountName));
                }
            }

            string mobilePhone = null;

            if (input.MobilePhone.IsNotNullOrEmpty())
            {
                mobilePhone = input.MobilePhone;
                if (AceUtils.IsMobilePhone(mobilePhone) == false)
                {
                    throw new InvalidInputException("请输入正确的手机号码");
                }

                bool exists = this.DbContext.Query <Sys_User>().Where(a => a.MobilePhone == mobilePhone).Any();
                if (exists)
                {
                    throw new InvalidInputException("手机号码[{0}]已存在".ToFormat(mobilePhone));
                }
            }

            string email = null;

            if (input.Email.IsNotNullOrEmpty())
            {
                email = input.Email.ToLower();
                if (AceUtils.IsEmail(email) == false)
                {
                    throw new InvalidInputException("请输入正确的邮箱地址");
                }

                bool exists = this.DbContext.Query <Sys_User>().Where(a => a.Email == email).Any();
                if (exists)
                {
                    throw new InvalidInputException("邮箱地址[{0}]已存在".ToFormat(input.Email));
                }
            }

            Sys_User user = this.CreateEntity <Sys_User>();

            user.AccountName = accountName;
            user.Name        = input.Name;
            user.Gender      = input.Gender;
            user.MobilePhone = mobilePhone;
            user.Birthday    = input.Birthday;
            user.WeChat      = input.WeChat;
            user.Email       = email;
            user.Description = input.Description;
            user.State       = AccountState.Normal;

            string userSecretkey     = UserHelper.GenUserSecretkey();
            string encryptedPassword = PasswordHelper.Encrypt(input.Password, userSecretkey);

            Sys_UserLogOn logOnEntity = new Sys_UserLogOn();

            logOnEntity.Id            = IdHelper.CreateStringSnowflakeId();
            logOnEntity.UserId        = user.Id;
            logOnEntity.UserSecretkey = userSecretkey;
            logOnEntity.UserPassword  = encryptedPassword;

            List <string>       roleIds   = input.GetRoles();
            List <Sys_UserRole> userRoles = roleIds.Select(a =>
            {
                return(new Sys_UserRole()
                {
                    Id = IdHelper.CreateStringSnowflakeId(),
                    UserId = user.Id,
                    RoleId = a,
                });
            }).ToList();

            user.RoleIds = string.Join(",", roleIds);

            List <string>      orgIds   = input.GetOrgs();
            List <Sys_UserOrg> userOrgs = orgIds.Select(a =>
            {
                return(new Sys_UserOrg()
                {
                    Id = IdHelper.CreateStringSnowflakeId(),
                    UserId = user.Id,
                    OrgId = a,
                    DisablePermission = false
                });
            }).ToList();

            user.OrgIds = string.Join(",", orgIds);

            List <string>       postIds   = input.GetPosts();
            List <Sys_UserPost> userPosts = postIds.Select(a =>
            {
                return(new Sys_UserPost()
                {
                    Id = IdHelper.CreateStringSnowflakeId(),
                    UserId = user.Id,
                    PostId = a
                });
            }).ToList();

            user.PostIds = string.Join(",", postIds);

            this.DbContext.DoWithTransaction(() =>
            {
                this.DbContext.Insert(user);
                this.DbContext.Insert(logOnEntity);
                this.DbContext.InsertRange(userRoles);
                this.DbContext.InsertRange(userOrgs);
                this.DbContext.InsertRange(userPosts);
            });
        }
Exemple #20
0
 public void UpdateForm(Sys_UserLogOn userLogOnEntity)
 {
     service.Update(userLogOnEntity);
 }
 public int UpdateForm(Sys_UserLogOn sys_UserLogOn)
 {
     return(service.Update(sys_UserLogOn));
 }