Skip to content

Commit

Permalink
Merge pull request #209 from amosproj/develop
Browse files Browse the repository at this point in the history
Release 13
  • Loading branch information
n3rdc4ptn authored Feb 1, 2023
2 parents 7e30b85 + db586c1 commit 337affa
Show file tree
Hide file tree
Showing 83 changed files with 10,073 additions and 3,099 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ bin/
src/deskstar-backend/DeskstarSolution.sln.DotSettings.user
*.cs~
src/deskstar-backend/Deskstar/out/
.devcontainer/.env
Binary file added Deliverables/sprint-13/demo-day-slide.pdf
Binary file not shown.
Binary file added Deliverables/sprint-13/demo-day-video.mp4
Binary file not shown.
Binary file added Deliverables/sprint-13/feature-board.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Deliverables/sprint-13/planning-documents.pdf
Binary file not shown.
Binary file modified Documentation/Database Model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/Screenshot/user_page_manage_delete_only_admin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/Screenshot/user_page_manage_edit_only_admin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/Screenshot/user_page_manage_only_admin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
143 changes: 87 additions & 56 deletions src/deskstar-backend/Deskstar/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Deskstar.Core.Exceptions;
using Deskstar.Entities;
using Deskstar.Models;
using Deskstar.Usecases;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -10,68 +12,97 @@ 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;
private readonly IAuthUsecases _authUsecases;
private readonly IConfiguration _configuration;

public AuthController(ILogger<AuthController> logger, IAuthUsecases authUsecases, IConfiguration configuration)
{
_logger = logger;
_authUsecases = authUsecases;
_configuration = configuration;
}

public AuthController(ILogger<AuthController> logger, IAuthUsecases authUsecases, IConfiguration configuration)
/// <summary>
/// Login functionality
/// </summary>
/// <returns> JWT, if users is approved and psw is correct </returns>
/// <remarks>
/// Sample request:
/// Post /auth/createToken
/// </remarks>
///
/// <response code="200">Login succesful </response>
/// <response code="401">Credentials wrong or user not approved</response>
[HttpPost("createToken")]
[AllowAnonymous]
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(LoginResponse), StatusCodes.Status401Unauthorized)]
public IActionResult CreateToken(CreateTokenUser user)
{
var returnValue = _authUsecases.CheckCredentials(user.MailAddress, user.Password);
if (returnValue.Message == LoginReturn.Ok)
{
_logger = logger;
_authUsecases = authUsecases;
_configuration = configuration;
return Ok(_authUsecases.CreateToken(_configuration, user.MailAddress));
}

/// <summary>
/// Login functionality
/// </summary>
/// <returns> JWT, if users is approved and psw is correct </returns>
/// <remarks>
/// Sample request:
/// Post /auth/createToken
/// </remarks>
///
/// <response code="200">Login succesful </response>
/// <response code="401">Credentials wrong or user not approved</response>
[HttpPost("createToken")]
[AllowAnonymous]
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(LoginResponse), StatusCodes.Status401Unauthorized)]
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));
}
return Unauthorized(returnValue.Message.ToString());
}

return Unauthorized(returnValue.Message.ToString());
/// <summary>
/// Register functionality
/// </summary>
/// <remarks>
/// 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>
[HttpPost("register")]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(RegisterResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(RegisterResponse), StatusCodes.Status404NotFound)]
public IActionResult Register(RegisterUser registerUser)
{
var result = _authUsecases.RegisterUser(registerUser);
return result.Message switch
{
RegisterReturn.Ok => Ok(),
RegisterReturn.CompanyNotFound => NotFound(result.Message.ToString()),
_ => BadRequest(result.Message.ToString())
};
}
/// <summary>
/// Register functionality
/// </summary>
/// <remarks>
/// 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")]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public IActionResult RegisterAdmin(RegisterAdminDto registerAdmin)
{
try
{
var admin = _authUsecases.RegisterAdmin(registerAdmin.FirstName, registerAdmin.LastName, registerAdmin.MailAddress, registerAdmin.Password, registerAdmin.CompanyName);
return Ok();
}

/// <summary>
/// Register functionality
/// </summary>
/// <remarks>
/// 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>
[HttpPost("register")]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(RegisterResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(RegisterResponse), StatusCodes.Status404NotFound)]
public IActionResult Register(RegisterUser registerUser)
catch (ArgumentInvalidException e)
{
return BadRequest(e.Message);
}
catch (Exception e)
{
var result = _authUsecases.RegisterUser(registerUser);
return result.Message switch
{
RegisterReturn.Ok => Ok(),
RegisterReturn.CompanyNotFound => NotFound(result.Message.ToString()),
_ => BadRequest(result.Message.ToString())
};
return Problem(statusCode: 500, detail:e.Message);
}
}
}
}
Loading

0 comments on commit 337affa

Please sign in to comment.