fix some potential crashes

This commit is contained in:
rootdarkarchon
2023-10-18 09:58:33 +02:00
parent 6fc2f1e90c
commit a3e2718271
2 changed files with 6 additions and 6 deletions

View File

@@ -57,15 +57,15 @@ public class SecretKeyAuthenticatorService
using var context = scope.ServiceProvider.GetService<MareDbContext>();
var authReply = await context.Auth.AsNoTracking().SingleOrDefaultAsync(u => u.HashedKey == hashedSecretKey).ConfigureAwait(false);
var isBanned = authReply?.IsBanned ?? false;
var primaryUid = authReply.PrimaryUserUID ?? authReply.UserUID;
var primaryUid = authReply.PrimaryUserUID ?? authReply?.UserUID;
if (authReply.PrimaryUserUID != null)
if (authReply?.PrimaryUserUID != null)
{
var primaryUser = await context.Auth.AsNoTracking().SingleOrDefaultAsync(u => u.UserUID == authReply.PrimaryUserUID).ConfigureAwait(false);
isBanned = isBanned || primaryUser.IsBanned;
}
SecretKeyAuthReply reply = new(authReply != null, authReply?.UserUID, authReply.PrimaryUserUID ?? authReply.UserUID, TempBan: false, isBanned);
SecretKeyAuthReply reply = new(authReply != null, authReply?.UserUID, authReply?.PrimaryUserUID ?? authReply?.UserUID, TempBan: false, isBanned);
if (reply.Success)
{

View File

@@ -63,9 +63,8 @@ public partial class MareHub : Hub<IMareHub>, IMareHub
await Clients.Caller.Client_UpdateSystemInfo(_systemInfoService.SystemInfoDto).ConfigureAwait(false);
var dbUser = _dbContext.Users.SingleOrDefault(f => f.UID == UserUID);
var dbUser = await _dbContext.Users.SingleAsync(f => f.UID == UserUID).ConfigureAwait(false);
dbUser.LastLoggedIn = DateTime.UtcNow;
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Information, "Welcome to Mare Synchronos \"" + _shardName + "\", Current Online Users: " + _systemInfoService.SystemInfoDto.OnlineUsers).ConfigureAwait(false);
@@ -78,9 +77,10 @@ public partial class MareHub : Hub<IMareHub>, IMareHub
};
_dbContext.UserDefaultPreferredPermissions.Add(defaultPermissions);
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
}
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
return new ConnectionDto(new UserData(dbUser.UID, string.IsNullOrWhiteSpace(dbUser.Alias) ? null : dbUser.Alias))
{
CurrentClientVersion = _expectedClientVersion,