Add page to become a pirate

This commit is contained in:
jvyden 2022-08-02 11:12:33 -04:00
commit 77a2d27f13
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
7 changed files with 106 additions and 8 deletions

View file

@ -52,6 +52,8 @@ public class BaseLayout : PageModel
{
if (ServerStatics.IsUnitTesting) return LocalizationManager.DefaultLang;
if (this.language != null) return this.language;
if (this.User?.IsAPirate ?? false) return "en-PT";
IRequestCultureFeature? requestCulture = Request.HttpContext.Features.Get<IRequestCultureFeature>();
if (requestCulture == null) return this.language = LocalizationManager.DefaultLang;

View file

@ -0,0 +1,31 @@
@page "/pirate"
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.PirateSignupPage
@{
Layout = "Layouts/BaseLayout";
Model.Title = "ARRRRRRRRRR!";
}
<!--suppress GrazieInspection -->
@if (!Model.User!.IsAPirate)
{
<p>So, ye wanna be a pirate? Well, ye came to the right place!</p>
<p>Just click this 'ere button, and welcome aboard!</p>
<p>If you ever wanna walk the plank, come back 'ere.</p>
<form method="post">
@Html.AntiForgeryToken()
<input type="submit" class="ui blue button" value="Aye aye, captain!"/>
</form>
}
else
{
<p>Back so soon, aye?</p>
<p>If you're gonna walk the plank, then do it!</p>
<form method="post">
@Html.AntiForgeryToken()
<input type="submit" class="ui red button" value="Walk the plank"/>
</form>
}

View file

@ -0,0 +1,32 @@
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages;
public class PirateSignupPage : BaseLayout
{
public PirateSignupPage(Database database) : base(database)
{}
public async Task<IActionResult> OnGet()
{
User? user = this.Database.UserFromWebRequest(this.Request);
if (user == null) return this.RedirectToPage("/login");
return this.Page();
}
public async Task<IActionResult> OnPost()
{
User? user = this.Database.UserFromWebRequest(this.Request);
if (user == null) return this.Redirect("/login");
user.IsAPirate = !user.IsAPirate;
await this.Database.SaveChangesAsync();
return this.Redirect("/");
}
}