Show authentication attempts on landing page

This commit is contained in:
jvyden 2021-12-13 14:04:39 -05:00
commit 5b8d9cdb10
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
2 changed files with 17 additions and 0 deletions

View file

@ -1,5 +1,6 @@
@page "/"
@using LBPUnion.ProjectLighthouse.Types
@using LBPUnion.ProjectLighthouse.Types.Settings
@model LBPUnion.ProjectLighthouse.Pages.LandingPage
@{
@ -11,6 +12,12 @@
@if (Model.User != null)
{
<p>You are currently logged in as <b>@Model.User.Username</b>.</p>
if (ServerSettings.Instance.UseExternalAuth && Model.AuthenticationAttemptsCount > 0)
{
<p>
<b>You have @Model.AuthenticationAttemptsCount authentication attempts pending. Click <a href="/authentication">here</a> to view them.</b>
</p>
}
}
@if (Model.PlayersOnlineCount == 1)
@ -21,6 +28,7 @@
<a href="/user/@user.UserId">@user.Username</a>
}
}
else if (Model.PlayersOnlineCount == 0)
{
<p>There are no users online. Why not hop on?</p>

View file

@ -16,6 +16,8 @@ namespace LBPUnion.ProjectLighthouse.Pages
public List<User> PlayersOnline;
public int PlayersOnlineCount;
public int AuthenticationAttemptsCount;
public LandingPage(Database database) : base(database)
{}
@ -27,6 +29,13 @@ namespace LBPUnion.ProjectLighthouse.Pages
this.PlayersOnlineCount = await StatisticsHelper.RecentMatches();
if (user != null)
{
this.AuthenticationAttemptsCount = await this.Database.AuthenticationAttempts.Include
(a => a.GameToken)
.CountAsync(a => a.GameToken.UserId == user.UserId);
}
List<int> userIds = await this.Database.LastContacts.Where(l => TimestampHelper.Timestamp - l.Timestamp < 300).Select(l => l.UserId).ToListAsync();
this.PlayersOnline = await this.Database.Users.Where(u => userIds.Contains(u.UserId)).ToListAsync();