mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-17 07:12:32 +00:00
* Initial support for leaderboards and some refactoring * Start of UI redesign * Finish slot and user redesign, added deletion of comments, reviews, scores, and photos * Remove leftover debug print * Fix bug in permission check * Simplify sidebar code and add hearted and queued levels * Fix navbar scrolling on mobile and refactor SlotCardPartial
52 lines
No EOL
1.6 KiB
C#
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.Email;
|
|
|
|
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();
|
|
}
|
|
} |