diff --git a/ProjectLighthouse/Controllers/LoginController.cs b/ProjectLighthouse/Controllers/LoginController.cs
index 88368a2c..a2c381af 100644
--- a/ProjectLighthouse/Controllers/LoginController.cs
+++ b/ProjectLighthouse/Controllers/LoginController.cs
@@ -41,10 +41,19 @@ namespace LBPUnion.ProjectLighthouse.Controllers
{
loginData = null;
}
- if (loginData == null) return this.BadRequest();
+
+ if (loginData == null)
+ {
+ Logger.Log("loginData was null, rejecting login", LoggerLevelLogin.Instance);
+ return this.BadRequest();
+ }
IPAddress? remoteIpAddress = this.HttpContext.Connection.RemoteIpAddress;
- if (remoteIpAddress == null) return this.StatusCode(403, ""); // 403 probably isnt the best status code for this, but whatever
+ if (remoteIpAddress == null)
+ {
+ Logger.Log("unable to determine ip, rejecting login", LoggerLevelLogin.Instance);
+ return this.StatusCode(403, ""); // 403 probably isnt the best status code for this, but whatever
+ }
string ipAddress = remoteIpAddress.ToString();
@@ -56,11 +65,20 @@ namespace LBPUnion.ProjectLighthouse.Controllers
if (token == null) // If we cant find an existing token, try to generate a new one
{
token = await this.database.AuthenticateUser(loginData, ipAddress, titleId);
- if (token == null) return this.StatusCode(403, ""); // If not, then 403.
+ if (token == null)
+ {
+ Logger.Log("unable to find/generate a token, rejecting login", LoggerLevelLogin.Instance);
+ return this.StatusCode(403, ""); // If not, then 403.
+ }
}
User? user = await this.database.UserFromGameToken(token, true);
- if (user == null || user.Banned) return this.StatusCode(403, "");
+
+ if (user == null || user.Banned)
+ {
+ Logger.Log("unable to find a user from a token, rejecting login", LoggerLevelLogin.Instance);
+ return this.StatusCode(403, "");
+ }
if (ServerSettings.Instance.UseExternalAuth)
{
@@ -75,6 +93,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
DeniedAuthenticationHelper.AddAttempt(ipAddressAndName);
await this.database.SaveChangesAsync();
+ Logger.Log("too many denied logins, rejecting login", LoggerLevelLogin.Instance);
return this.StatusCode(403, "");
}
}
@@ -104,7 +123,11 @@ namespace LBPUnion.ProjectLighthouse.Controllers
await this.database.SaveChangesAsync();
- if (!token.Approved) return this.StatusCode(403, "");
+ if (!token.Approved)
+ {
+ Logger.Log("token unapproved, rejecting login", LoggerLevelLogin.Instance);
+ return this.StatusCode(403, "");
+ }
Logger.Log($"Successfully logged in user {user.Username} as {token.GameVersion} client ({titleId})", LoggerLevelLogin.Instance);
// After this point we are now considering this session as logged in.
diff --git a/ProjectLighthouse/Helpers/Extensions/RequestExtensions.cs b/ProjectLighthouse/Helpers/Extensions/RequestExtensions.cs
new file mode 100644
index 00000000..a31b359a
--- /dev/null
+++ b/ProjectLighthouse/Helpers/Extensions/RequestExtensions.cs
@@ -0,0 +1,15 @@
+using System.Text.RegularExpressions;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Net.Http.Headers;
+
+namespace LBPUnion.ProjectLighthouse.Helpers.Extensions
+{
+ // yoinked and adapted from https://stackoverflow.com/a/68641796
+ public static class RequestExtensions
+ {
+ private static readonly Regex mobileCheck = new
+ ("Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);
+
+ public static bool IsMobile(this HttpRequest request) => mobileCheck.IsMatch(request.Headers[HeaderNames.UserAgent].ToString());
+ }
+}
\ No newline at end of file
diff --git a/ProjectLighthouse/Helpers/TimestampHelper.cs b/ProjectLighthouse/Helpers/TimestampHelper.cs
index 3a3e9d48..456f33ab 100644
--- a/ProjectLighthouse/Helpers/TimestampHelper.cs
+++ b/ProjectLighthouse/Helpers/TimestampHelper.cs
@@ -5,5 +5,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
public static class TimestampHelper
{
public static long Timestamp => (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
+
+ public static long TimestampMillis => (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
}
}
\ No newline at end of file
diff --git a/ProjectLighthouse/Pages/Layouts/BaseLayout.cshtml b/ProjectLighthouse/Pages/Layouts/BaseLayout.cshtml
index d4e14ade..ee35c549 100644
--- a/ProjectLighthouse/Pages/Layouts/BaseLayout.cshtml
+++ b/ProjectLighthouse/Pages/Layouts/BaseLayout.cshtml
@@ -1,4 +1,5 @@
@using LBPUnion.ProjectLighthouse.Helpers
+@using LBPUnion.ProjectLighthouse.Helpers.Extensions
@using LBPUnion.ProjectLighthouse.Types
@using LBPUnion.ProjectLighthouse.Types.Settings
@model LBPUnion.ProjectLighthouse.Pages.Layouts.BaseLayout
@@ -26,6 +27,9 @@
}
Model.NavigationItemsRight.Add(new PageNavigationItem("Log out", "/logout", "user alternate slash")); // should always be last
}
+
+ Model.IsMobile = Model.Request.IsMobile();
+ long timeStarted = TimestampHelper.TimestampMillis;
}
@@ -48,10 +52,20 @@
-
-
-
+
+
+ @* Embed Stuff *@
+
+
+ @if (!string.IsNullOrEmpty(Model.Description))
+ {
+
+ }
+
+
+
+ @* Google Analytics *@
@if (ServerSettings.Instance.GoogleAnalyticsEnabled)
{
@@ -81,14 +95,21 @@