mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-11 04:57:22 +01:00
some logging
This commit is contained in:
parent
2e7672c440
commit
4326a134c6
1 changed files with 24 additions and 4 deletions
|
|
@ -26,19 +26,34 @@ public class UserRequirementHandler : AuthorizationHandler<UserRequirement, HubI
|
|||
{
|
||||
var uid = context.User.Claims.SingleOrDefault(g => string.Equals(g.Type, MareClaimTypes.Uid, StringComparison.Ordinal))?.Value;
|
||||
|
||||
if (uid == null) context.Fail();
|
||||
if (uid == null)
|
||||
{
|
||||
context.Fail();
|
||||
_logger.LogWarning("No user UID found in claims");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((requirement.Requirements & UserRequirements.Identified) is UserRequirements.Identified)
|
||||
{
|
||||
var ident = await _redis.GetAsync<string>("UID:" + uid).ConfigureAwait(false);
|
||||
if (ident == RedisValue.EmptyString) context.Fail();
|
||||
if (ident == RedisValue.EmptyString)
|
||||
{
|
||||
context.Fail();
|
||||
_logger.LogWarning("User {uid} not online", uid);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ((requirement.Requirements & UserRequirements.Administrator) is UserRequirements.Administrator)
|
||||
{
|
||||
using var dbContext = await _dbContextFactory.CreateDbContextAsync().ConfigureAwait(false);
|
||||
var user = await dbContext.Users.AsNoTracking().SingleOrDefaultAsync(b => b.UID == uid).ConfigureAwait(false);
|
||||
if (user == null || !user.IsAdmin) context.Fail();
|
||||
if (user == null || !user.IsAdmin)
|
||||
{
|
||||
context.Fail();
|
||||
_logger.LogWarning("Admin request for {uid} unauthenticated", uid);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Admin {uid} authenticated", uid);
|
||||
}
|
||||
|
||||
|
|
@ -46,7 +61,12 @@ public class UserRequirementHandler : AuthorizationHandler<UserRequirement, HubI
|
|||
{
|
||||
using var dbContext = await _dbContextFactory.CreateDbContextAsync().ConfigureAwait(false);
|
||||
var user = await dbContext.Users.AsNoTracking().SingleOrDefaultAsync(b => b.UID == uid).ConfigureAwait(false);
|
||||
if (user == null || !user.IsAdmin && !user.IsModerator) context.Fail();
|
||||
if (user == null || !user.IsAdmin && !user.IsModerator)
|
||||
{
|
||||
context.Fail();
|
||||
_logger.LogWarning("Admin/Moderator for {uid} unauthenticated", uid);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Admin/Moderator {uid} authenticated", uid);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue