mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-04 12:21:27 +00:00
Use UtcNow instead of Now for internal time keeping (#965)
This commit is contained in:
parent
c529dada35
commit
092f8bc5a2
15 changed files with 26 additions and 26 deletions
|
@ -109,7 +109,7 @@ public class UserEndpoints : ApiEndpointController
|
||||||
|
|
||||||
RegistrationTokenEntity token = new()
|
RegistrationTokenEntity token = new()
|
||||||
{
|
{
|
||||||
Created = DateTime.Now,
|
Created = DateTime.UtcNow,
|
||||||
Token = CryptoHelper.GenerateAuthToken(),
|
Token = CryptoHelper.GenerateAuthToken(),
|
||||||
Username = username,
|
Username = username,
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class ModerationCaseController : ControllerBase
|
||||||
ModerationCaseEntity? @case = await this.database.Cases.FirstOrDefaultAsync(c => c.CaseId == id);
|
ModerationCaseEntity? @case = await this.database.Cases.FirstOrDefaultAsync(c => c.CaseId == id);
|
||||||
if (@case == null) return this.NotFound();
|
if (@case == null) return this.NotFound();
|
||||||
|
|
||||||
@case.DismissedAt = DateTime.Now;
|
@case.DismissedAt = DateTime.UtcNow;
|
||||||
@case.DismisserId = user.UserId;
|
@case.DismisserId = user.UserId;
|
||||||
@case.DismisserUsername = user.Username;
|
@case.DismisserUsername = user.Username;
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class CompleteEmailVerificationPage : BaseLayout
|
||||||
|
|
||||||
UserEntity user = await this.Database.Users.FirstAsync(u => u.UserId == emailVerifyToken.UserId);
|
UserEntity user = await this.Database.Users.FirstAsync(u => u.UserId == emailVerifyToken.UserId);
|
||||||
|
|
||||||
if (DateTime.Now > emailVerifyToken.ExpiresAt)
|
if (DateTime.UtcNow > emailVerifyToken.ExpiresAt)
|
||||||
{
|
{
|
||||||
this.Error = "This token has expired";
|
this.Error = "This token has expired";
|
||||||
return this.Page();
|
return this.Page();
|
||||||
|
@ -52,7 +52,7 @@ public class CompleteEmailVerificationPage : BaseLayout
|
||||||
// if user's account was created automatically
|
// if user's account was created automatically
|
||||||
WebTokenEntity webToken = new()
|
WebTokenEntity webToken = new()
|
||||||
{
|
{
|
||||||
ExpiresAt = DateTime.Now.AddDays(7),
|
ExpiresAt = DateTime.UtcNow.AddDays(7),
|
||||||
Verified = true,
|
Verified = true,
|
||||||
UserId = user.UserId,
|
UserId = user.UserId,
|
||||||
UserToken = CryptoHelper.GenerateAuthToken(),
|
UserToken = CryptoHelper.GenerateAuthToken(),
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class LoginForm : BaseLayout
|
||||||
{
|
{
|
||||||
UserId = user.UserId,
|
UserId = user.UserId,
|
||||||
UserToken = CryptoHelper.GenerateAuthToken(),
|
UserToken = CryptoHelper.GenerateAuthToken(),
|
||||||
ExpiresAt = DateTime.Now + TimeSpan.FromDays(7),
|
ExpiresAt = DateTime.UtcNow + TimeSpan.FromDays(7),
|
||||||
Verified = !ServerConfiguration.Instance.TwoFactorConfiguration.TwoFactorEnabled || !user.IsTwoFactorSetup,
|
Verified = !ServerConfiguration.Instance.TwoFactorConfiguration.TwoFactorEnabled || !user.IsTwoFactorSetup,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class RegisterForm : BaseLayout
|
||||||
{
|
{
|
||||||
UserId = user.UserId,
|
UserId = user.UserId,
|
||||||
UserToken = CryptoHelper.GenerateAuthToken(),
|
UserToken = CryptoHelper.GenerateAuthToken(),
|
||||||
ExpiresAt = DateTime.Now + TimeSpan.FromDays(7),
|
ExpiresAt = DateTime.UtcNow + TimeSpan.FromDays(7),
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Database.WebTokens.Add(webToken);
|
this.Database.WebTokens.Add(webToken);
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class NewCasePage : BaseLayout
|
||||||
Reason = reason,
|
Reason = reason,
|
||||||
ModeratorNotes = modNotes,
|
ModeratorNotes = modNotes,
|
||||||
ExpiresAt = expires,
|
ExpiresAt = expires,
|
||||||
CreatedAt = DateTime.Now,
|
CreatedAt = DateTime.UtcNow,
|
||||||
CreatorId = user.UserId,
|
CreatorId = user.UserId,
|
||||||
CreatorUsername = user.Username,
|
CreatorUsername = user.Username,
|
||||||
AffectedId = affectedId.Value,
|
AffectedId = affectedId.Value,
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class AdminTests : LighthouseWebTest
|
||||||
{
|
{
|
||||||
UserId = user.UserId,
|
UserId = user.UserId,
|
||||||
UserToken = CryptoHelper.GenerateAuthToken(),
|
UserToken = CryptoHelper.GenerateAuthToken(),
|
||||||
ExpiresAt = DateTime.Now + TimeSpan.FromHours(1),
|
ExpiresAt = DateTime.UtcNow + TimeSpan.FromHours(1),
|
||||||
Verified = true,
|
Verified = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class AdminTests : LighthouseWebTest
|
||||||
{
|
{
|
||||||
UserId = user.UserId,
|
UserId = user.UserId,
|
||||||
UserToken = CryptoHelper.GenerateAuthToken(),
|
UserToken = CryptoHelper.GenerateAuthToken(),
|
||||||
ExpiresAt = DateTime.Now + TimeSpan.FromHours(1),
|
ExpiresAt = DateTime.UtcNow + TimeSpan.FromHours(1),
|
||||||
Verified = true,
|
Verified = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class AuthenticationTests : LighthouseWebTest
|
||||||
{
|
{
|
||||||
UserId = user.UserId,
|
UserId = user.UserId,
|
||||||
UserToken = CryptoHelper.GenerateAuthToken(),
|
UserToken = CryptoHelper.GenerateAuthToken(),
|
||||||
ExpiresAt = DateTime.Now + TimeSpan.FromHours(1),
|
ExpiresAt = DateTime.UtcNow + TimeSpan.FromHours(1),
|
||||||
Verified = true,
|
Verified = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class CreateApiKeyCommand : ICommand
|
||||||
key.Description = "<no description specified>";
|
key.Description = "<no description specified>";
|
||||||
}
|
}
|
||||||
key.Key = CryptoHelper.GenerateAuthToken();
|
key.Key = CryptoHelper.GenerateAuthToken();
|
||||||
key.Created = DateTime.Now;
|
key.Created = DateTime.UtcNow;
|
||||||
DatabaseContext database = provider.GetRequiredService<DatabaseContext>();
|
DatabaseContext database = provider.GetRequiredService<DatabaseContext>();
|
||||||
await database.APIKeys.AddAsync(key);
|
await database.APIKeys.AddAsync(key);
|
||||||
await database.SaveChangesAsync();
|
await database.SaveChangesAsync();
|
||||||
|
|
|
@ -117,7 +117,7 @@ public static class MaintenanceHelper
|
||||||
CompletedMigrationEntity completedMigration = new()
|
CompletedMigrationEntity completedMigration = new()
|
||||||
{
|
{
|
||||||
MigrationName = migrationTask.GetType().Name,
|
MigrationName = migrationTask.GetType().Name,
|
||||||
RanAt = DateTime.Now,
|
RanAt = DateTime.UtcNow,
|
||||||
};
|
};
|
||||||
|
|
||||||
database.CompletedMigrations.Add(completedMigration);
|
database.CompletedMigrations.Add(completedMigration);
|
||||||
|
|
|
@ -33,7 +33,7 @@ public partial class DatabaseContext
|
||||||
|
|
||||||
if (token == null) return null;
|
if (token == null) return null;
|
||||||
|
|
||||||
if (DateTime.Now <= token.ExpiresAt) return token;
|
if (DateTime.UtcNow <= token.ExpiresAt) return token;
|
||||||
|
|
||||||
this.Remove(token);
|
this.Remove(token);
|
||||||
await this.SaveChangesAsync();
|
await this.SaveChangesAsync();
|
||||||
|
|
|
@ -72,7 +72,7 @@ public partial class DatabaseContext
|
||||||
Platform = npTicket.Platform,
|
Platform = npTicket.Platform,
|
||||||
TicketHash = npTicket.TicketHash,
|
TicketHash = npTicket.TicketHash,
|
||||||
// we can get away with a low expiry here since LBP will just get a new token everytime it gets 403'd
|
// we can get away with a low expiry here since LBP will just get a new token everytime it gets 403'd
|
||||||
ExpiresAt = DateTime.Now + TimeSpan.FromHours(1),
|
ExpiresAt = DateTime.UtcNow + TimeSpan.FromHours(1),
|
||||||
};
|
};
|
||||||
|
|
||||||
this.GameTokens.Add(gameToken);
|
this.GameTokens.Add(gameToken);
|
||||||
|
|
|
@ -26,7 +26,7 @@ public partial class DatabaseContext
|
||||||
WebTokenEntity? token = this.WebTokens.FirstOrDefault(t => t.UserToken == lighthouseToken);
|
WebTokenEntity? token = this.WebTokens.FirstOrDefault(t => t.UserToken == lighthouseToken);
|
||||||
if (token == null) return null;
|
if (token == null) return null;
|
||||||
|
|
||||||
if (DateTime.Now <= token.ExpiresAt) return this.Users.FirstOrDefault(u => u.UserId == token.UserId);
|
if (DateTime.UtcNow <= token.ExpiresAt) return this.Users.FirstOrDefault(u => u.UserId == token.UserId);
|
||||||
|
|
||||||
this.Remove(token);
|
this.Remove(token);
|
||||||
this.SaveChanges();
|
this.SaveChanges();
|
||||||
|
@ -48,7 +48,7 @@ public partial class DatabaseContext
|
||||||
WebTokenEntity? token = this.WebTokens.FirstOrDefault(t => t.UserToken == lighthouseToken);
|
WebTokenEntity? token = this.WebTokens.FirstOrDefault(t => t.UserToken == lighthouseToken);
|
||||||
if (token == null) return null;
|
if (token == null) return null;
|
||||||
|
|
||||||
if (DateTime.Now <= token.ExpiresAt) return token;
|
if (DateTime.UtcNow <= token.ExpiresAt) return token;
|
||||||
|
|
||||||
this.Remove(token);
|
this.Remove(token);
|
||||||
this.SaveChanges();
|
this.SaveChanges();
|
||||||
|
@ -65,7 +65,7 @@ public partial class DatabaseContext
|
||||||
await this.PasswordResetTokens.FirstOrDefaultAsync(token => token.ResetToken == resetToken);
|
await this.PasswordResetTokens.FirstOrDefaultAsync(token => token.ResetToken == resetToken);
|
||||||
if (token == null) return null;
|
if (token == null) return null;
|
||||||
|
|
||||||
if (token.Created >= DateTime.Now.AddHours(-1))
|
if (token.Created >= DateTime.UtcNow.AddHours(-1))
|
||||||
return await this.Users.FirstOrDefaultAsync(user => user.UserId == token.UserId);
|
return await this.Users.FirstOrDefaultAsync(user => user.UserId == token.UserId);
|
||||||
|
|
||||||
this.PasswordResetTokens.Remove(token);
|
this.PasswordResetTokens.Remove(token);
|
||||||
|
@ -81,7 +81,7 @@ public partial class DatabaseContext
|
||||||
RegistrationTokenEntity? token = this.RegistrationTokens.FirstOrDefault(t => t.Token == tokenString);
|
RegistrationTokenEntity? token = this.RegistrationTokens.FirstOrDefault(t => t.Token == tokenString);
|
||||||
if (token == null) return false;
|
if (token == null) return false;
|
||||||
|
|
||||||
if (token.Created >= DateTime.Now.AddDays(-7)) return true;
|
if (token.Created >= DateTime.UtcNow.AddDays(-7)) return true;
|
||||||
|
|
||||||
this.RegistrationTokens.Remove(token);
|
this.RegistrationTokens.Remove(token);
|
||||||
this.SaveChanges();
|
this.SaveChanges();
|
||||||
|
@ -92,7 +92,7 @@ public partial class DatabaseContext
|
||||||
|
|
||||||
public async Task RemoveExpiredTokens()
|
public async Task RemoveExpiredTokens()
|
||||||
{
|
{
|
||||||
List<GameTokenEntity> expiredTokens = await this.GameTokens.Where(t => DateTime.Now > t.ExpiresAt).ToListAsync();
|
List<GameTokenEntity> expiredTokens = await this.GameTokens.Where(t => DateTime.UtcNow > t.ExpiresAt).ToListAsync();
|
||||||
foreach (GameTokenEntity token in expiredTokens)
|
foreach (GameTokenEntity token in expiredTokens)
|
||||||
{
|
{
|
||||||
UserEntity? user = await this.Users.FirstOrDefaultAsync(u => u.UserId == token.UserId);
|
UserEntity? user = await this.Users.FirstOrDefaultAsync(u => u.UserId == token.UserId);
|
||||||
|
@ -100,10 +100,10 @@ public partial class DatabaseContext
|
||||||
}
|
}
|
||||||
await this.SaveChangesAsync();
|
await this.SaveChangesAsync();
|
||||||
|
|
||||||
await this.GameTokens.RemoveWhere(t => DateTime.Now > t.ExpiresAt);
|
await this.GameTokens.RemoveWhere(t => DateTime.UtcNow > t.ExpiresAt);
|
||||||
await this.WebTokens.RemoveWhere(t => DateTime.Now > t.ExpiresAt);
|
await this.WebTokens.RemoveWhere(t => DateTime.UtcNow > t.ExpiresAt);
|
||||||
await this.EmailVerificationTokens.RemoveWhere(t => DateTime.Now > t.ExpiresAt);
|
await this.EmailVerificationTokens.RemoveWhere(t => DateTime.UtcNow > t.ExpiresAt);
|
||||||
await this.EmailSetTokens.RemoveWhere(t => DateTime.Now > t.ExpiresAt);
|
await this.EmailSetTokens.RemoveWhere(t => DateTime.UtcNow > t.ExpiresAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RemoveRegistrationToken(string? tokenString)
|
public async Task RemoveRegistrationToken(string? tokenString)
|
||||||
|
|
|
@ -48,7 +48,7 @@ public static class SMTPHelper
|
||||||
|
|
||||||
PasswordResetTokenEntity token = new()
|
PasswordResetTokenEntity token = new()
|
||||||
{
|
{
|
||||||
Created = DateTime.Now,
|
Created = DateTime.UtcNow,
|
||||||
UserId = user.UserId,
|
UserId = user.UserId,
|
||||||
ResetToken = CryptoHelper.GenerateAuthToken(),
|
ResetToken = CryptoHelper.GenerateAuthToken(),
|
||||||
};
|
};
|
||||||
|
@ -90,7 +90,7 @@ public static class SMTPHelper
|
||||||
UserId = user.UserId,
|
UserId = user.UserId,
|
||||||
User = user,
|
User = user,
|
||||||
EmailToken = CryptoHelper.GenerateAuthToken(),
|
EmailToken = CryptoHelper.GenerateAuthToken(),
|
||||||
ExpiresAt = DateTime.Now.AddHours(6),
|
ExpiresAt = DateTime.UtcNow.AddHours(6),
|
||||||
};
|
};
|
||||||
|
|
||||||
database.EmailVerificationTokens.Add(verifyToken);
|
database.EmailVerificationTokens.Add(verifyToken);
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class ModerationCaseEntity
|
||||||
public DateTime CreatedAt { get; set; }
|
public DateTime CreatedAt { get; set; }
|
||||||
|
|
||||||
public DateTime? ExpiresAt { get; set; }
|
public DateTime? ExpiresAt { get; set; }
|
||||||
public bool Expired => this.ExpiresAt != null && this.ExpiresAt < DateTime.Now;
|
public bool Expired => this.ExpiresAt != null && this.ExpiresAt < DateTime.UtcNow;
|
||||||
|
|
||||||
public DateTime? DismissedAt { get; set; }
|
public DateTime? DismissedAt { get; set; }
|
||||||
public bool Dismissed => this.DismissedAt != null;
|
public bool Dismissed => this.DismissedAt != null;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue