ProjectLighthouse/ProjectLighthouse.Servers.Website/Pages/CompleteEmailVerificationPage.cshtml.cs
Josh f6a7fe6283
User settings, level settings, language and timezone selection and more. (#471)
* Initial work for user settings page

* Finish user setting and slot setting pages

* Don't show slot upload date on home page and fix team pick redirection

* Fix upload image button alignment on mobile

* Fix image upload on iPhone

* Remove unused css and add selected button color

* Fix login email check and bump ChromeDriver to 105

* Remove duplicated code and allow users to leave fields empty

* Add unpublish button on level settings and move settings button position

* Don't show edit button on mini card

* Self review bug fixes and users can no longer use an in-use email
2022-09-17 14:02:46 -05:00

52 lines
No EOL
1.6 KiB
C#

#nullable enable
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
using LBPUnion.ProjectLighthouse.PlayerData.Profiles.Email;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages;
public class CompleteEmailVerificationPage : BaseLayout
{
public CompleteEmailVerificationPage(Database database) : base(database)
{}
public string? Error;
public async Task<IActionResult> OnGet(string token)
{
if (!ServerConfiguration.Instance.Mail.MailEnabled) return this.NotFound();
User? user = this.Database.UserFromWebRequest(this.Request);
if (user == null) return this.Redirect("~/login");
EmailVerificationToken? emailVerifyToken = await this.Database.EmailVerificationTokens.FirstOrDefaultAsync(e => e.EmailToken == token);
if (emailVerifyToken == null)
{
this.Error = "Invalid verification token";
return this.Page();
}
if (DateTime.Now > emailVerifyToken.ExpiresAt)
{
this.Error = "This token has expired";
return this.Page();
}
if (emailVerifyToken.UserId != user.UserId)
{
this.Error = "This token doesn't belong to you!";
return this.Page();
}
this.Database.EmailVerificationTokens.Remove(emailVerifyToken);
user.EmailAddressVerified = true;
await this.Database.SaveChangesAsync();
return this.Page();
}
}