blob: cf653e853f15b372c13d9c9e1b789f364edd5835 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
using IOL.GreatOffice.Api.Models.Database;
namespace IOL.GreatOffice.Api.Endpoints.Internal.Account;
public class GetAccountRoute : RouteBaseAsync.WithoutRequest.WithActionResult<LoggedInUserModel>
{
private readonly MainAppDatabase _database;
public GetAccountRoute(MainAppDatabase database) {
_database = database;
}
[HttpGet("~/_/account")]
public override async Task<ActionResult<LoggedInUserModel>> HandleAsync(CancellationToken cancellationToken = default) {
var user = _database.Users
.Select(x => new {x.Username, x.Id})
.SingleOrDefault(c => c.Id == LoggedInUser.Id);
if (user != default) {
return Ok(new LoggedInUserModel {
Id = LoggedInUser.Id,
Username = LoggedInUser.Username
});
}
await HttpContext.SignOutAsync();
return Unauthorized();
}
}
|