Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

203 toast no #215

Merged
merged 7 commits into from
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions src/deskstar-backend/Deskstar/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Deskstar.Core.Exceptions;
using Deskstar.Entities;
using Deskstar.Models;
using Deskstar.Usecases;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -12,9 +11,9 @@ namespace Deskstar.Controllers;
[Produces("text/plain")]
public class AuthController : ControllerBase
{
private readonly ILogger<AuthController> _logger;
private readonly IAuthUsecases _authUsecases;
private readonly IConfiguration _configuration;
private readonly ILogger<AuthController> _logger;

public AuthController(ILogger<AuthController> logger, IAuthUsecases authUsecases, IConfiguration configuration)
{
Expand All @@ -24,14 +23,13 @@ public AuthController(ILogger<AuthController> logger, IAuthUsecases authUsecases
}

/// <summary>
/// Login functionality
/// Login functionality
/// </summary>
/// <returns> JWT, if users is approved and psw is correct </returns>
/// <remarks>
/// Sample request:
/// Post /auth/createToken
/// Sample request:
/// Post /auth/createToken
/// </remarks>
///
/// <response code="200">Login succesful </response>
/// <response code="401">Credentials wrong or user not approved</response>
[HttpPost("createToken")]
Expand All @@ -41,22 +39,18 @@ public AuthController(ILogger<AuthController> logger, IAuthUsecases authUsecases
public IActionResult CreateToken(CreateTokenUser user)
{
var returnValue = _authUsecases.CheckCredentials(user.MailAddress, user.Password);
if (returnValue.Message == LoginReturn.Ok)
{
return Ok(_authUsecases.CreateToken(_configuration, user.MailAddress));
}
if (returnValue.Message == LoginReturn.Ok) return Ok(_authUsecases.CreateToken(_configuration, user.MailAddress));

return Unauthorized(returnValue.Message.ToString());
}

/// <summary>
/// Register functionality
/// Register functionality
/// </summary>
/// <remarks>
/// Sample request:
/// Post /auth/register
/// Sample request:
/// Post /auth/register
/// </remarks>
///
/// <response code="200">User added to db</response>
/// <response code="400">Mail already in use</response>
/// <response code="404">Company not found</response>
Expand All @@ -75,14 +69,14 @@ public IActionResult Register(RegisterUser registerUser)
_ => BadRequest(result.Message.ToString())
};
}

/// <summary>
/// Register functionality
/// Register functionality
/// </summary>
/// <remarks>
/// Sample request:
/// Post /auth/registerAdmin
/// Sample request:
/// Post /auth/registerAdmin
/// </remarks>
///
/// <response code="200">Admin added to db</response>
/// <response code="400">Mail or Company name already in use</response>
[HttpPost("registerAdmin")]
Expand All @@ -93,7 +87,8 @@ public IActionResult RegisterAdmin(RegisterAdminDto registerAdmin)
{
try
{
var admin = _authUsecases.RegisterAdmin(registerAdmin.FirstName, registerAdmin.LastName, registerAdmin.MailAddress, registerAdmin.Password, registerAdmin.CompanyName);
var admin = _authUsecases.RegisterAdmin(registerAdmin.FirstName, registerAdmin.LastName,
registerAdmin.MailAddress, registerAdmin.Password, registerAdmin.CompanyName);
return Ok();
}
catch (ArgumentInvalidException e)
Expand All @@ -102,7 +97,7 @@ public IActionResult RegisterAdmin(RegisterAdminDto registerAdmin)
}
catch (Exception e)
{
return Problem(statusCode: 500, detail:e.Message);
return Problem(statusCode: 500, detail: e.Message);
}
}
}
Loading