|
@@ -2,6 +2,7 @@ using System.Security.Claims;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using RunnersMeet.Server.Domain;
|
|
using RunnersMeet.Server.Domain;
|
|
|
|
|
+using RunnersMeet.Server.Persistence;
|
|
|
|
|
|
|
|
namespace RunnersMeet.Server.Controllers;
|
|
namespace RunnersMeet.Server.Controllers;
|
|
|
|
|
|
|
@@ -10,15 +11,27 @@ namespace RunnersMeet.Server.Controllers;
|
|
|
[Authorize]
|
|
[Authorize]
|
|
|
public class UsersController : ControllerBase
|
|
public class UsersController : ControllerBase
|
|
|
{
|
|
{
|
|
|
|
|
+ private readonly QueryFactory _queryFactory;
|
|
|
|
|
+
|
|
|
|
|
+ public UsersController(QueryFactory queryFactory)
|
|
|
|
|
+ {
|
|
|
|
|
+ _queryFactory = queryFactory;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
[HttpGet("validate")]
|
|
[HttpGet("validate")]
|
|
|
- public ActionResult<UserValidationResult> Validate()
|
|
|
|
|
|
|
+ public ActionResult<UserValidationResult> Validate([FromQuery] string? nickname)
|
|
|
{
|
|
{
|
|
|
|
|
+ var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
|
|
|
|
+ if (userId == null)
|
|
|
|
|
+ {
|
|
|
|
|
+ throw new ApiException("UsersController.Validate call without a User / authentication token");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var userProfile = _queryFactory.ValidateUserCommand().Validate(userId, nickname);
|
|
|
|
|
+
|
|
|
return new UserValidationResult
|
|
return new UserValidationResult
|
|
|
{
|
|
{
|
|
|
- UserProfile = new UserProfile {
|
|
|
|
|
- UserId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? "<unknown>",
|
|
|
|
|
- DisplayName = "TODO",
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ UserProfile = userProfile,
|
|
|
Claims = User.FindAll("permissions").Select(claim => claim.Value),
|
|
Claims = User.FindAll("permissions").Select(claim => claim.Value),
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|