/// <summary> /// /// </summary> /// <param name="oldPassword">明文</param> /// <param name="newPassword">明文</param> public void ChangePassword(string userId, string oldPassword, string newPassword) { PasswordHelper.EnsurePasswordLegal(newPassword); SysUserLogOn userLogOn = this.DbContext.Query <SysUserLogOn>().Where(a => a.UserId == userId).First(); string encryptedOldPassword = PasswordHelper.Encrypt(oldPassword, userLogOn.UserSecretkey); if (encryptedOldPassword != userLogOn.UserPassword) { throw new InvalidInputException("旧密码不正确"); } string newUserSecretkey = UserHelper.GenUserSecretkey(); string newEncryptedPassword = PasswordHelper.Encrypt(newPassword, newUserSecretkey); this.DbContext.DoWithTransaction(() => { this.DbContext.Update <SysUserLogOn>(a => a.UserId == userId, a => new SysUserLogOn() { UserSecretkey = newUserSecretkey, UserPassword = newEncryptedPassword }); //this.Log(LogType.Update, "Account", true, "用户[{0}]修改密码".ToFormat(userId)); }); }
public void SubmitForm(SysUser userEntity, SysUserLogOn userLogOnEntity, string userId) { using (var db = base.BeginTransaction()) { try { if (!string.IsNullOrEmpty(userId)) { userEntity.Id = userId; this.Update(userEntity); } else { userEntity.Id = Guid.NewGuid().ToString(); userLogOnEntity.Id = userEntity.Id; userLogOnEntity.UserId = userEntity.Id; userLogOnEntity.UserSecretkey = Md5Hash.Md5(Common.CreateNo(), 16).ToLower(); userLogOnEntity.UserPassword = Md5Hash.Md5(DESEncrypt.Encrypt(Md5Hash.Md5(userLogOnEntity.UserPassword, 32).ToLower(), userLogOnEntity.UserSecretkey).ToLower(), 32).ToLower(); this.Insert(userEntity); SysUserLogOnRespository.Insert(userLogOnEntity); } this.Commit(); } catch (Exception ex) { this.Rollback(); throw ex; } } }
public void RevisePassword(string userPassword, string keyValue) { SysUserLogOn userLogOnEntity = new SysUserLogOn(); userLogOnEntity.Id = keyValue; userLogOnEntity.UserSecretkey = Md5Hash.Md5(Common.CreateNo(), 16).ToLower(); userLogOnEntity.UserPassword = Md5Hash.Md5(DESEncrypt.Encrypt(Md5Hash.Md5(userPassword, 32).ToLower(), userLogOnEntity.UserSecretkey).ToLower(), 32).ToLower(); _SysUserLogOnRespository.Update(userLogOnEntity); }
public ActionResult SubmitForm(SysUser sysUser, SysUserLogOn SysUserLogOn, string keyValue) { var isSysAdmin = UserApp.IsAdmin(keyValue); if (isSysAdmin && !sysUser.Account.ToLower().Equals("admin")) { return(Error("系统内置管理员账号不能修改!")); } UserApp.SubmitForm(sysUser, SysUserLogOn, keyValue); return(Success("操作成功。")); }
/// <summary> /// 修改密码 /// </summary> /// <param name="userLoginEntity"></param> /// <returns></returns> public int ModifyPwd(SysUserLogOn userLoginEntity) { using (var db = GetInstance()) { userLoginEntity.ChangePwdTime = DateTime.Now; return(db.Updateable <SysUserLogOn>(userLoginEntity).UpdateColumns(it => new { it.Password, it.ChangePwdTime, }).ExecuteCommand()); } }
/// <summary> /// 新增用户登录账号 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Insert(SysUserLogOn model) { using (var db = GetInstance()) { model.Id = Guid.NewGuid().ToString().Replace("-", ""); model.SecretKey = model.Id.DESEncrypt().Substring(0, 8); model.Password = model.Password.MD5Encrypt().DESEncrypt(model.SecretKey).MD5Encrypt(); model.LoginCount = 0; model.IsOnLine = "0"; return(db.Insertable <SysUserLogOn>(model).ExecuteCommand()); } }
public ActionResult Form(SysUserLogOn model) { if (model.Id.IsNullOrEmpty()) { int row = userLogOnLogic.Insert(model); return(row > 0 ? Success() : Error()); } else { var row = userLogOnLogic.UpdateInfo(model); return(row > 0 ? Success() : Error()); } }
/// <summary> /// 更新用户登录账号信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public int UpdateInfo(SysUserLogOn model) { using (var db = GetInstance()) { return(db.Updateable <SysUserLogOn>(model).UpdateColumns(it => new { it.AllowMultiUserOnline, it.Question, it.AnswerQuestion, it.CheckIPAddress, it.Language, it.Theme }).ExecuteCommand()); } }
/// <summary> /// 更新用户登录账号信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public int UpdateLogin(SysUserLogOn model) { using (var db = GetInstance()) { model.IsOnLine = "1"; model.LastVisitTime = DateTime.Now; model.PrevVisitTime = model.LastVisitTime; model.LoginCount += 1; return(db.Updateable <SysUserLogOn>(model).UpdateColumns(it => new { it.IsOnLine, it.PrevVisitTime, it.LastVisitTime, it.LoginCount, }).ExecuteCommand()); } }
public InvokeResult <bool> RevisePassword(string oldPassword, string userPassword, string keyValue) { var oldUserLogOn = _Respository.Get(keyValue); oldPassword = Md5Hash.Md5(DESEncrypt.Encrypt(Md5Hash.Md5(oldPassword, 32).ToLower(), oldUserLogOn.UserSecretkey).ToLower(), 32).ToLower(); if (oldUserLogOn.UserPassword != oldPassword) { return(RequestResult.Failed <bool>("原始密码错误")); } SysUserLogOn userLogOnEntity = new SysUserLogOn(); userLogOnEntity.Id = keyValue; userLogOnEntity.UserSecretkey = Md5Hash.Md5(Common.CreateNo(), 16).ToLower(); userLogOnEntity.UserPassword = Md5Hash.Md5(DESEncrypt.Encrypt(Md5Hash.Md5(userPassword, 32).ToLower(), userLogOnEntity.UserSecretkey).ToLower(), 32).ToLower(); var b = _Respository.Update(userLogOnEntity); return(RequestResult.Success(b)); }
/// <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 SysUser user, out string msg) { user = null; msg = null; loginName.NotNullOrEmpty(); password.NotNullOrEmpty(); var view = this.DbContext.JoinQuery <SysUser, SysUserLogOn>((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); } } SysUser userEntity = viewEntity.User; SysUserLogOn userLogOnEntity = viewEntity.UserLogOn; string dbPassword = PasswordHelper.EncryptMD5Password(password, userLogOnEntity.UserSecretkey); if (dbPassword != userLogOnEntity.UserPassword) { msg = "密码不正确,请重新输入"; return(false); } DateTime lastVisitTime = DateTime.Now; this.DbContext.Update <SysUserLogOn>(a => a.Id == userLogOnEntity.Id, a => new SysUserLogOn() { LogOnCount = a.LogOnCount + 1, PreviousVisitTime = userLogOnEntity.LastVisitTime, LastVisitTime = lastVisitTime }); user = userEntity; return(true); }
public int Insert(SysUser model, string password, string[] roleIds) { using (var db = GetInstance()) { try { db.Ado.BeginTran(); ////新增用户基本信息。 model.Id = Guid.NewGuid().ToString().Replace("-", ""); model.DeleteMark = "0"; model.CreateUser = OperatorProvider.Instance.Current.Account; model.CreateTime = DateTime.Now; model.ModifyUser = model.CreateUser; model.ModifyTime = model.CreateTime; model.Avatar = "/Content/framework/images/avatar.png"; int row = db.Insertable <SysUser>(model).ExecuteCommand(); if (row == 0) { db.Ado.RollbackTran(); return(row); } //新增新的角色 List <SysUserRoleRelation> list = new List <SysUserRoleRelation>(); foreach (string roleId in roleIds) { SysUserRoleRelation roleRelation = new SysUserRoleRelation { Id = Guid.NewGuid().ToString().Replace("-", ""), UserId = model.Id, RoleId = roleId, CreateUser = OperatorProvider.Instance.Current.Account, CreateTime = DateTime.Now }; list.Add(roleRelation); } row = db.Insertable <SysUserRoleRelation>(list).ExecuteCommand(); if (row == 0) { db.Ado.RollbackTran(); return(row); } //新增用户登陆信息。 SysUserLogOn userLogOnEntity = new SysUserLogOn(); userLogOnEntity.Id = Guid.NewGuid().ToString().Replace("-", ""); userLogOnEntity.UserId = model.Id; userLogOnEntity.SecretKey = userLogOnEntity.Id.DESEncrypt().Substring(0, 8); userLogOnEntity.Password = password.MD5Encrypt().DESEncrypt(userLogOnEntity.SecretKey).MD5Encrypt(); userLogOnEntity.LoginCount = 0; userLogOnEntity.IsOnLine = "0"; row = db.Insertable <SysUserLogOn>(userLogOnEntity).ExecuteCommand(); //初始化返点 SysRebateEntity rebateModel = new SysRebateEntity { ShopID = model.ShopID, UserID = model.Id, TipRebate = 0, HourRebate = 0, ModifiedBy = OperatorProvider.Instance.Current.Account, CreateTime = DateTime.Now, ModifiedTime = DateTime.Now }; row = db.Insertable <SysRebateEntity>(rebateModel).ExecuteCommand(); if (row == 0) { db.Ado.RollbackTran(); return(row); } db.Ado.CommitTran(); return(row); } catch (Exception ex) { db.Ado.RollbackTran(); new LogLogic().Write(Level.Error, "新增用户", ex.Message, ex.StackTrace); return(0); } } }
public ActionResult SubmitForm(SysUser SysUser, SysUserLogOn SysUserLogOn, string keyValue) { UserApp.SubmitForm(SysUser, SysUserLogOn, keyValue); return(Success("操作成功。")); }
public void SubmitForm(SysUser sysUser, SysUserLogOn userLogOnEntity, string userId) { _SysUserRespository.SubmitForm(sysUser, userLogOnEntity, userId); }
public void UpdateForm(SysUserLogOn userLogOnEntity) { _Respository.Update(userLogOnEntity); }
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 <SysUser>().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 <SysUser>().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 <SysUser>().Where(a => a.Email == email).Any(); if (exists) { throw new InvalidInputException("邮箱地址[{0}]已存在".ToFormat(input.Email)); } } SysUser user = this.CreateEntity <SysUser>(null, input.CreatorId); 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); SysUserLogOn logOnEntity = new SysUserLogOn(); logOnEntity.Id = IdHelper.CreateStringSnowflakeId(); logOnEntity.UserId = user.Id; logOnEntity.UserSecretkey = userSecretkey; logOnEntity.UserPassword = encryptedPassword; List <string> roleIds = input.GetRoles(); List <SysUserRole> userRoles = roleIds.Select(a => { return(new SysUserRole() { Id = IdHelper.CreateStringSnowflakeId(), UserId = user.Id, RoleId = a, }); }).ToList(); user.RoleIds = string.Join(",", roleIds); List <string> orgIds = input.GetOrgs(); List <SysUserOrg> userOrgs = orgIds.Select(a => { return(new SysUserOrg() { Id = IdHelper.CreateStringSnowflakeId(), UserId = user.Id, OrgId = a, DisablePermission = false }); }).ToList(); user.OrgIds = string.Join(",", orgIds); List <string> postIds = input.GetPosts(); List <SysUserPost> userPosts = postIds.Select(a => { return(new SysUserPost() { 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); }); }
public void UpdateForm(SysUserLogOn userLogOnEntity) { _SysUserLogOnRespository.UpdateFields(userLogOnEntity); }