protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "User", columns: table => new { ID = table.Column <Guid>(nullable: false), CreateTime = table.Column <DateTime>(nullable: false), UpdateTime = table.Column <DateTime>(nullable: false), Name = table.Column <string>(maxLength: 100, nullable: false), Account = table.Column <string>(maxLength: 100, nullable: false), Password = table.Column <string>(maxLength: 32, nullable: false) }, constraints: table => { table.PrimaryKey("PK_User", x => x.ID); }); var adminID = Guid.NewGuid(); string password = ApplicationConfig.EncodePassword(ApplicationConfig.DefaultPassword); migrationBuilder.Sql($@" Insert into [User] Values('{adminID.ToString().ToUpper()}', '0001-01-01 00:00:00', '0001-01-01 00:00:00', '管理员', 'Admin', '{password}') "); }
public async Task AddUserAsync(AddUserModel model) { if (await _userRepository.ExistedAsync(m => m.Account.Equals(model.Account))) { throw new MateralConDepException("账号已存在"); } var user = _mapper.Map <User>(model); user.ID = Guid.NewGuid(); user.Password = ApplicationConfig.EncodePassword(ApplicationConfig.DefaultPassword); _centerSqliteEFUnitOfWork.RegisterAdd(user); await _centerSqliteEFUnitOfWork.CommitAsync(); }
public async Task <UserDTO> LoginAsync(LoginModel model) { User userFromDB = await _userRepository.FirstOrDefaultAsync(m => m.Account.Equals(model.Account)); if (userFromDB == null) { throw new MateralConDepException("账号错误"); } if (!userFromDB.Password.Equals(ApplicationConfig.EncodePassword(model.Password))) { throw new MateralConDepException("密码错误"); } var result = _mapper.Map <UserDTO>(userFromDB); return(result); }
public async Task ChangePasswordAsync(ChangePasswordModel model) { User userFromDB = await _userRepository.FirstOrDefaultAsync(model.ID); if (userFromDB == null) { throw new MateralConDepException("用户不存在"); } if (!userFromDB.Password.Equals(ApplicationConfig.EncodePassword(model.OldPassword))) { throw new MateralConDepException("旧密码错误"); } userFromDB.Password = ApplicationConfig.EncodePassword(model.NewPassword); _centerSqliteEFUnitOfWork.RegisterEdit(userFromDB); await _centerSqliteEFUnitOfWork.CommitAsync(); }
public async Task <string> ResetPasswordAsync(Guid id) { User userFromDB = await _userRepository.FirstOrDefaultAsync(id); if (userFromDB == null) { throw new MateralConDepException("用户不存在"); } string password = ApplicationConfig.DefaultPassword; userFromDB.Password = ApplicationConfig.EncodePassword(password); _centerSqliteEFUnitOfWork.RegisterEdit(userFromDB); await _centerSqliteEFUnitOfWork.CommitAsync(); return(password); }