/// <summary> /// /// </summary> /// <param name="oldPassword">明文</param> /// <param name="newPassword">明文</param> public void ChangePassword(string oldPassword, string newPassword) { PasswordHelper.EnsurePasswordLegal(newPassword); AdminSession session = this.Session; MALU_Users userLogOn = this.DbContext.Query <MALU_Users>().Where(a => a.Id == session.UserId).First(); string encryptedOldPassword = PasswordHelper.Encrypt(oldPassword, "invtax"); if (encryptedOldPassword != userLogOn.password) { throw new Ace.Exceptions.InvalidDataException("旧密码不正确"); } string newEncryptedPassword = PasswordHelper.Encrypt(newPassword, "invtax"); this.DbContext.DoWithTransaction(() => { this.DbContext.Update <MALU_Users>(a => a.Id == session.UserId, a => new MALU_Users() { password = newEncryptedPassword }); // this.Log(Entities.Enums.LogType.Update, "Account", true, "用户[{0}]修改密码".ToFormat(session.UserId)); }); }
public ActionResult Index() { var service = this.CreateService <IEntityAppService>(); MALU_Users user = service.GetByKey <MALU_Users>(this.CurrentSession.UserId); Sys_Duty duty = string.IsNullOrEmpty(user.DutyId) ? null : service.GetByKey <Sys_Duty>(user.DutyId); Sys_Role role = string.IsNullOrEmpty(user.RoleId) ? null : service.GetByKey <Sys_Role>(user.RoleId); UserModel model = new UserModel(); model.User = user; model.DutyName = duty == null ? null : duty.Name; model.RoleName = role == null ? null : role.Name; this.ViewBag.UserInfo = model; this.ViewBag.CompanyName = this.CurrentSession.CompanyName; return(View()); }
public void AddUser(AddUserInput input) { input.Validate(); string userName = input.UserName.ToLower(); bool exists = this.DbContext.GetInv_users().Where(a => a.username == userName).Any(); if (exists) { throw new InvalidDataException("用户名[{0}]已存在".ToFormat(input.UserName)); } MALU_Users user = this.CreateEntity <MALU_Users>(); user.username = userName; 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.IsEnabled = 1; user.companyguid = input.companyguid; user.IsFirst = 1; string userSecretkey = UserHelper.GenUserSecretkey(); string encryptedPassword = PasswordHelper.Encrypt(input.Password, "invtax"); user.password = encryptedPassword; //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); }); }
/// <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 MALU_Users user, out Sys_Role role, out string msg) { userName.NotNullOrEmpty(); password.NotNullOrEmpty(); user = null; msg = null; role = null; var Role = this.DbContext.GetSys_Role(); var users = this.DbContext.GetInv_users().LeftJoin(Role, (u, r) => u.RoleId == r.Id); var view = users.Select((u, r) => new { User = u, Role = r }); var viewEntity = view.FirstOrDefault(a => a.User.username == userName); if (viewEntity == null) { msg = "账户不存在,请重新输入"; return(false); } //if (viewEntity.User.IsEnabled == 0) //{ // msg = "账户被系统锁定,请联系管理员"; // return false; //} MALU_Users userEntity = viewEntity.User; string dbPassword = PasswordHelper.EncryptMD5Password(password, "invtax"); if (dbPassword != userEntity.password) { msg = "密码不正确,请重新输入"; return(false); } user = userEntity; role = viewEntity.Role; return(true); }