-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added user management and require admin rights
- Loading branch information
Showing
17 changed files
with
498 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using CentaurScores.Attributes; | ||
using CentaurScores.Model; | ||
using CentaurScores.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace CentaurScores.Controllers | ||
{ | ||
/// <summary> | ||
/// Endpoints for user management. | ||
/// </summary> | ||
/// <remarks>Constructor</remarks> | ||
[ApiController] | ||
[Route("auth")] | ||
public class UserController(IAuthorizationService authorizationService) : ControllerBase | ||
{ | ||
/// <summary> | ||
/// Returns the list of all users. | ||
/// </summary> | ||
/// <returns></returns> | ||
[HttpGet("user")] | ||
[Authorize] | ||
public async Task<ActionResult<List<UserModel>>> GetUsers() | ||
{ | ||
return await authorizationService.GetUsers(); | ||
} | ||
|
||
/// <summary> | ||
/// Returns the list of all users. | ||
/// </summary> | ||
/// <returns></returns> | ||
[HttpGet("acl")] | ||
[Authorize] | ||
public async Task<ActionResult<List<UserACLModel>>> GetACLs() | ||
{ | ||
return await authorizationService.GetAcls(); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new user. | ||
/// </summary> | ||
/// <returns></returns> | ||
[HttpPost("user")] | ||
[Authorize] | ||
public async Task<ActionResult<UserModel>> CreateUser(UserModel model) | ||
{ | ||
return await authorizationService.CreateUser(HttpContext.User, model); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new ACL. | ||
/// </summary> | ||
/// <returns></returns> | ||
[HttpPost("acl")] | ||
[Authorize] | ||
public async Task<ActionResult<UserACLModel>> CreateACL(UserACLModel model) | ||
{ | ||
return await authorizationService.CreateACL(HttpContext.User, model); | ||
} | ||
|
||
/// <summary> | ||
/// Updates a user. | ||
/// </summary> | ||
/// <returns></returns> | ||
[HttpPut("user")] | ||
[Authorize] | ||
public async Task<ActionResult<UserModel>> UpdateUser(UserModel model) | ||
{ | ||
return await authorizationService.UpdateUser(HttpContext.User, model); | ||
} | ||
|
||
/// <summary> | ||
/// Updates an ACL. | ||
/// </summary> | ||
/// <returns></returns> | ||
[HttpPut("acl")] | ||
[Authorize] | ||
public async Task<ActionResult<UserACLModel>> UpdateACL(UserACLModel model) | ||
{ | ||
return await authorizationService.UpdateACL(HttpContext.User, model); | ||
} | ||
|
||
/// <summary> | ||
/// Updates a user. | ||
/// </summary> | ||
/// <returns></returns> | ||
[HttpDelete("user/{userId}")] | ||
[Authorize] | ||
public async Task<ActionResult<int>> DeleteUser([FromRoute] int userId) | ||
{ | ||
return await authorizationService.DeleteUser(HttpContext.User, userId); | ||
} | ||
|
||
/// <summary> | ||
/// Updates an ACL. | ||
/// </summary> | ||
/// <returns></returns> | ||
[HttpDelete("acl/{aclId}")] | ||
[Authorize] | ||
public async Task<ActionResult<int>> DeleteACL([FromRoute] int aclId) | ||
{ | ||
return await authorizationService.DeleteACL(HttpContext.User, aclId); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace CentaurScores.Model | ||
{ | ||
/// <summary> | ||
/// Login request data. | ||
/// </summary> | ||
public class LoginRequestModel | ||
{ | ||
/// <summary> | ||
/// USername, case sensitive. | ||
/// </summary> | ||
public string Username { get; set; } = string.Empty; | ||
/// <summary> | ||
/// Password, case sensitive. | ||
/// </summary> | ||
public string Password { get; set; } = string.Empty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace CentaurScores.Model | ||
{ | ||
/// <summary> | ||
/// ACL | ||
/// </summary> | ||
public class UserACLModel | ||
{ | ||
/// <summary> | ||
/// Persistence ID | ||
/// </summary> | ||
public int? Id { get; set; } | ||
/// <summary> | ||
/// Username | ||
/// </summary> | ||
public string Name { get; set; } = string.Empty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace CentaurScores.Model | ||
{ | ||
/// <summary> | ||
/// User | ||
/// </summary> | ||
public class UserModel | ||
{ | ||
/// <summary> | ||
/// Persistence ID | ||
/// </summary> | ||
public int? Id { get; set; } | ||
/// <summary> | ||
/// Username | ||
/// </summary> | ||
public string Username { get; set; } = string.Empty; | ||
/// <summary> | ||
/// Password, only set when changing the password | ||
/// </summary> | ||
public string Password { get; set; } = string.Empty; | ||
/// <summary> | ||
/// Required when changing the password. | ||
/// </summary> | ||
public string CurrentPassword { get; set; } = string.Empty; | ||
/// <summary> | ||
/// List of ACLs for the user | ||
/// </summary> | ||
public List<UserACLModel> Acls { get; set; } = []; | ||
} | ||
} |
Oops, something went wrong.