48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Claims;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using ReallifeGamemode.Database.Entities;
|
|
using ReallifeGamemode.Database.Models;
|
|
using ReallifeGamemode.DataService.Types;
|
|
|
|
namespace ReallifeGamemode.DataService.Controllers
|
|
{
|
|
[ApiController]
|
|
[Authorize]
|
|
[Route("DataService/User")]
|
|
[Produces("application/json")]
|
|
public class UserController : ControllerBase
|
|
{
|
|
private readonly DatabaseContext dbContext;
|
|
|
|
public UserController(DatabaseContext dbContext)
|
|
{
|
|
this.dbContext = dbContext;
|
|
}
|
|
|
|
[HttpGet("Data")]
|
|
public ActionResult<GetUserDataResponse> Data()
|
|
{
|
|
User user = dbContext.Users.Where(u => u.Id == UserId).FirstOrDefault();
|
|
|
|
if(user == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return new GetUserDataResponse()
|
|
{
|
|
Name = user.Name,
|
|
AdminLevel = user.AdminLevel,
|
|
RegistrationDate = user.RegistrationDate
|
|
};
|
|
}
|
|
|
|
private int UserId => int.Parse(User.Claims.Where(c => c.Type == ClaimTypes.Name).FirstOrDefault()?.Value ?? "0");
|
|
}
|
|
}
|