/// <summary> /// Executes the command for the specified user info /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <CommandResult <AuthToken> > GenerateTokenAsync(TokenGenerationRequestModel model) { var dbResult = InsertOrUpdDbResult.NotFound; var authToken = await this.auth.ValidatePasswordAndGenerateTokenAsync(model.Email, model.Password); if (authToken != null) { using (var connection = await this.sqlConnectionFactory.CreateConnectionAsync(true)) using (var transaction = connection.BeginTransaction()) { try { dbResult = await this.database.ReplaceRefreshTokenAsync(model.Email, authToken.RefreshToken, transaction); transaction.Commit(); } catch { transaction.Rollback(); throw; } } } if (dbResult.IsNotFound) { return(CommandResult.NotFound <AuthToken>()); } else { return(new CommandResult <AuthToken>(authToken, CommandStatus.Created)); } }
public async Task <IActionResult> GenerateTokenAsync([FromBody] TokenGenerationRequestModel model) { var command = this.commandFactory.CreateGenerateAuthTokenCommand(); var commandResult = await command.GenerateTokenAsync(model); if (commandResult.Success) { return(this.Ok(commandResult.Value)); } else { return(this.NotFound()); } }