From b520eecd4e5a0b68086d5acfdf29833bc360c5fe Mon Sep 17 00:00:00 2001 From: jvyden Date: Thu, 3 Mar 2022 17:55:43 -0500 Subject: [PATCH] Dont show email-related pages if SMTP is disabled --- .../Pages/CompleteEmailVerificationPage.cshtml.cs | 3 +++ ProjectLighthouse/Pages/LoginForm.cshtml.cs | 2 +- ProjectLighthouse/Pages/SendVerificationEmailPage.cshtml.cs | 2 ++ ProjectLighthouse/Pages/SetEmailForm.cshtml.cs | 4 ++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ProjectLighthouse/Pages/CompleteEmailVerificationPage.cshtml.cs b/ProjectLighthouse/Pages/CompleteEmailVerificationPage.cshtml.cs index 6be84c7b..4ec8bd8e 100644 --- a/ProjectLighthouse/Pages/CompleteEmailVerificationPage.cshtml.cs +++ b/ProjectLighthouse/Pages/CompleteEmailVerificationPage.cshtml.cs @@ -4,6 +4,7 @@ using JetBrains.Annotations; using LBPUnion.ProjectLighthouse.Pages.Layouts; using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types.Profiles.Email; +using LBPUnion.ProjectLighthouse.Types.Settings; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -18,6 +19,8 @@ public class CompleteEmailVerificationPage : BaseLayout public async Task OnGet(string token) { + if (!ServerSettings.Instance.SMTPEnabled) return this.NotFound(); + User? user = this.Database.UserFromWebRequest(this.Request); if (user == null) return this.Redirect("~/login"); diff --git a/ProjectLighthouse/Pages/LoginForm.cshtml.cs b/ProjectLighthouse/Pages/LoginForm.cshtml.cs index 98dfdf67..86cb9b9f 100644 --- a/ProjectLighthouse/Pages/LoginForm.cshtml.cs +++ b/ProjectLighthouse/Pages/LoginForm.cshtml.cs @@ -105,7 +105,7 @@ public class LoginForm : BaseLayout Logger.Log($"User {user.Username} (id: {user.UserId}) successfully logged in on web", LoggerLevelLogin.Instance); if (user.PasswordResetRequired) return this.Redirect("~/passwordResetRequired"); - if (!user.EmailAddressVerified) return this.Redirect("~/login/sendVerificationEmail"); + if (ServerSettings.Instance.SMTPEnabled && !user.EmailAddressVerified) return this.Redirect("~/login/sendVerificationEmail"); return this.RedirectToPage(nameof(LandingPage)); } diff --git a/ProjectLighthouse/Pages/SendVerificationEmailPage.cshtml.cs b/ProjectLighthouse/Pages/SendVerificationEmailPage.cshtml.cs index a6dc791a..d07fd8ed 100644 --- a/ProjectLighthouse/Pages/SendVerificationEmailPage.cshtml.cs +++ b/ProjectLighthouse/Pages/SendVerificationEmailPage.cshtml.cs @@ -17,6 +17,8 @@ public class SendVerificationEmailPage : BaseLayout public async Task OnGet() { + if (!ServerSettings.Instance.SMTPEnabled) return this.NotFound(); + User? user = this.Database.UserFromWebRequest(this.Request); if (user == null) return this.Redirect("/login"); diff --git a/ProjectLighthouse/Pages/SetEmailForm.cshtml.cs b/ProjectLighthouse/Pages/SetEmailForm.cshtml.cs index dfcb3c3e..1b39d592 100644 --- a/ProjectLighthouse/Pages/SetEmailForm.cshtml.cs +++ b/ProjectLighthouse/Pages/SetEmailForm.cshtml.cs @@ -7,6 +7,7 @@ using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Pages.Layouts; using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types.Profiles.Email; +using LBPUnion.ProjectLighthouse.Types.Settings; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -22,6 +23,7 @@ public class SetEmailForm : BaseLayout public async Task OnGet(string? token = null) { + if (!ServerSettings.Instance.SMTPEnabled) return this.NotFound(); if (token == null) return this.Redirect("/login"); EmailSetToken? emailToken = await this.Database.EmailSetTokens.FirstOrDefaultAsync(t => t.EmailToken == token); @@ -34,6 +36,8 @@ public class SetEmailForm : BaseLayout public async Task OnPost(string emailAddress, string token) { + if (!ServerSettings.Instance.SMTPEnabled) return this.NotFound(); + EmailSetToken? emailToken = await this.Database.EmailSetTokens.Include(t => t.User).FirstOrDefaultAsync(t => t.EmailToken == token); if (emailToken == null) return this.Redirect("/login");