public async Task <IActionResult> SignIn([FromBody] SignInRequest request) { Guid id = _identityService.GenerateIdentityHash(request.Email); Identity identity = await _identityDataSource.Read(id); if (identity == null || !_identityService.IsPasswordValid(request.Password, identity.Hash, identity.Salt)) { return(BadRequest("Password incorrect or email not found.")); } TokenResponse tokenResponse = _jwtAuthenticationService.CreateTokenResponse(identity); return(Ok(tokenResponse)); }
public async Task <IActionResult> SignUp([FromBody] SignUpRequest request) { var id = _identityService.GenerateIdentityHash(request.Login); _identityService.GeneratePasswordHashAndSalt( request.Password, out byte[] hash, out byte[] salt); var user = await _userDataSource.CreateAsync(request.Name); var identity = await _identityDataSource.CreateAsync(id, user.Id, salt, hash); if (identity == null) { // delete user return(StatusCode((int)HttpStatusCode.Conflict, "Login is already in use.")); } var tokenResponse = _jwtAuthenticationService.CreateTokenResponse(identity); return(Ok(tokenResponse)); }