Skip to content

Commit

Permalink
feat: modifica request e response do login
Browse files Browse the repository at this point in the history
  • Loading branch information
GoliasVictor committed Dec 19, 2024
1 parent 7333126 commit 1ee4da7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/LivrEtec.GIB/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ public AuthController(ILogger<AuthController> logger, IAutenticacaoService auten
this.authKeyProvider = authKeyProvider;
this.repUsuarios = repUsuarios;
}
public record RequestLogin(int IdUsuario, string HashSenha);
public record RequestLogin(string Login, string HashSenha);
public record ResponseLogin(string JwtToken);
[AllowAnonymous]
[HttpPost("login")]
public async Task<ActionResult<string>> Login(RequestLogin request)
public async Task<ActionResult<ResponseLogin>> Login(RequestLogin request)
{
if (await autenticacaoService.EhAutentico(request.IdUsuario, request.HashSenha))
return TokenService.GerarToken(request.IdUsuario, authKeyProvider.authKey);
var id = await repUsuarios.ObterId(request.Login);
if (id is not null && await autenticacaoService.EhAutentico(id.Value, request.HashSenha))
return new ResponseLogin(TokenService.GerarToken(id.Value, authKeyProvider.authKey));
return Unauthorized("Usuario não encontrado ou Senha incorreta");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
"content": {
"text/plain": {
"schema": {
"type": "string"
"$ref": "#/components/schemas/ResponseLogin"
}
},
"application/json": {
"schema": {
"type": "string"
"$ref": "#/components/schemas/ResponseLogin"
}
},
"text/json": {
"schema": {
"type": "string"
"$ref": "#/components/schemas/ResponseLogin"
}
}
}
Expand Down Expand Up @@ -978,9 +978,9 @@
"RequestLogin": {
"type": "object",
"properties": {
"idUsuario": {
"type": "integer",
"format": "int32"
"login": {
"type": "string",
"nullable": true
},
"hashSenha": {
"type": "string",
Expand Down Expand Up @@ -1013,6 +1013,16 @@
},
"additionalProperties": false
},
"ResponseLogin": {
"type": "object",
"properties": {
"jwtToken": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
},
"Tag": {
"type": "object",
"properties": {
Expand Down

0 comments on commit 1ee4da7

Please sign in to comment.