mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 01:58:40 +00:00
Allow RegistrationTokens to have a username pre-selected (#524)
* Add prefilled username to registration token * call toString on query to work with EF * Fix typo in RegisterForm.cshtml * Only show username notice if the user's username hasn't been chosen already * Add confirmation message to DeleteUserCommand
This commit is contained in:
parent
bfe81c3461
commit
c7195df74f
9 changed files with 66 additions and 12 deletions
|
@ -33,7 +33,10 @@
|
|||
</div>
|
||||
}
|
||||
|
||||
<p><b>@Model.Translate(RegisterStrings.UsernameNotice)</b></p>
|
||||
@if (Model.Username == null)
|
||||
{
|
||||
<p><b>@Model.Translate(RegisterStrings.UsernameNotice)</b></p>
|
||||
}
|
||||
|
||||
<form class="ui form" onsubmit="return onSubmit(this)" method="post">
|
||||
@Html.AntiForgeryToken()
|
||||
|
@ -41,7 +44,14 @@
|
|||
<div class="field">
|
||||
<label>Username</label>
|
||||
<div class="ui left icon input">
|
||||
<input type="text" name="username" id="text" placeholder="Username" pattern="^[a-zA-Z0-9_.-]*$" minlength="3" maxlength="16">
|
||||
@{
|
||||
string extra = "";
|
||||
if (Model.Username != null)
|
||||
{
|
||||
extra = "value=" + Model.Username + " readonly";
|
||||
}
|
||||
}
|
||||
<input type="text" name="username" id="text" placeholder="Username" pattern="^[a-zA-Z0-9_.-]*$" minlength="3" maxlength="16" @extra>
|
||||
<i class="user icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -7,7 +7,6 @@ using LBPUnion.ProjectLighthouse.Localization.StringLists;
|
|||
using LBPUnion.ProjectLighthouse.PlayerData;
|
||||
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
|
||||
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
@ -20,6 +19,8 @@ public class RegisterForm : BaseLayout
|
|||
|
||||
public string? Error { get; private set; }
|
||||
|
||||
public string? Username { get; set; }
|
||||
|
||||
[UsedImplicitly]
|
||||
[SuppressMessage("ReSharper", "SpecifyStringComparison")]
|
||||
public async Task<IActionResult> OnPost(string username, string password, string confirmPassword, string emailAddress)
|
||||
|
@ -30,6 +31,8 @@ public class RegisterForm : BaseLayout
|
|||
{
|
||||
if (!this.Database.IsRegistrationTokenValid(this.Request.Query["token"]))
|
||||
return this.StatusCode(403, this.Translate(ErrorStrings.TokenInvalid));
|
||||
|
||||
username = (await this.Database.RegistrationTokens.FirstAsync(r => r.Token == this.Request.Query["token"].ToString())).Username;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -119,6 +122,8 @@ public class RegisterForm : BaseLayout
|
|||
{
|
||||
if (!this.Database.IsRegistrationTokenValid(this.Request.Query["token"]))
|
||||
return this.StatusCode(403, this.Translate(ErrorStrings.TokenInvalid));
|
||||
|
||||
this.Username = this.Database.RegistrationTokens.First(r => r.Token == this.Request.Query["token"].ToString()).Username;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue