public async Task ChangePasswordAsync(int id, UpdateAccount command) { var account = await GetAsync(id); _passwordManager.CalculatePasswordHash(command.NewPassword, out byte[] passwordHash, account.Salt); account.Update(account.Name, account.Surname, passwordHash); await _context.SaveChangesAsync(); }
public async Task AddAsync(CreateAccount command) { if (await _context.Users.ExistsInDatabaseAsync(command.Login, command.Email)) { throw new CorruptedOperationException("User already exists."); } _passwordManager.CalculatePasswordHash(command.Password, out byte[] passwordHash, out byte[] salt); var user = new User(command.Name, command.Surname, command.Login, command.Email, salt, passwordHash); await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); }
public async Task RegisterUserAsync(CreateUserCommand command) { var user = await GetUserAsync(command.Login); if (user != null) { throw new InternalSystemException($"Login '{command.Login}' is not available. Try another one."); } byte[] passwordHash, passwordSalt; _passwordManager.CalculatePasswordHash(command.Password, out passwordHash, out passwordSalt); _context.Users.Add(new User(passwordHash, passwordSalt, command.Login)); await _context.SaveChangesAsync(); }
public async Task AddWIthTeamAsync(CreateCaptainWithTeam command) { byte[] salt, passwordHash; var team = await _teamService.AddAsync(command.Team); if (await _context.Captains.ExistsInDatabaseAsync(command.Login, command.Email)) { throw new CorruptedOperationException("Captain already exists."); } _passwordManager.CalculatePasswordHash(command.Password, out passwordHash, out salt); var captain = new Captain(command.Name, command.Surname, command.Login, command.Email, salt, passwordHash); team.Captain = captain; await _context.Captains.AddAsync(captain); await _context.SaveChangesAsync(); }