public async Task <AdminTokenOutput> RegisterAsync(RegisterInput input) { if (await IsLoginBusyAsync(input.Login)) { throw AuthorizationException.LoginIsBusy(input.Login); } var password = _passwordEncoder.Encode(input.Password); var admin = new Admin(input.Name, input.Login, password); await _adminRepository.SaveAsync(admin); return(new AdminTokenOutput(admin, _jwtManager.CreateToken(admin))); }
public async Task <AdminTokenOutput> LogInAsync(LogInInput input) { var admin = await _adminRepository.FindAll() .Where(x => x.Login == input.Login) .FirstOrDefaultAsync(); bool DoesNotMatchPasswords() => false == _passwordEncoder.VerifyPassword(input.Password, admin !.Password); if (null == admin || DoesNotMatchPasswords()) { throw AuthorizationException.BadCredentials(); } return(new AdminTokenOutput(admin, _jwtManager.CreateToken(admin))); }