Login with email and confirm age on registration (#493)

* Implement login with email

* Add confirm age checkbox to register page

* Fix registration unit tests

* Fix registration unit tests for real this time

Co-authored-by: Dagg <32235163+daggintosh@users.noreply.github.com>
This commit is contained in:
Josh 2022-09-29 17:34:22 -05:00 committed by GitHub
parent f46bd4fc87
commit ee11798dc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 10 deletions

View file

@ -54,4 +54,7 @@
<data name="recent_photos" xml:space="preserve">
<value>Most recent photos</value>
</data>
<data name="email" xml:space="preserve">
<value>Email</value>
</data>
</root>

View file

@ -4,6 +4,7 @@ public static class GeneralStrings
{
public static readonly TranslatableString Username = create("username");
public static readonly TranslatableString Password = create("password");
public static readonly TranslatableString Email = create("email");
public static readonly TranslatableString Register = create("register");
public static readonly TranslatableString ResetPassword = create("reset_password");
public static readonly TranslatableString ForgotPassword = create("forgot_password");

View file

@ -41,9 +41,12 @@
<input type="hidden" id="redirect" name="redirect">
<div class="field">
<label>@Model.Translate(GeneralStrings.Username)</label>
@{
string username = ServerConfiguration.Instance.Mail.MailEnabled ? Model.Translate(GeneralStrings.Email) : Model.Translate(GeneralStrings.Username);
}
<label>@username</label>
<div class="ui left icon input">
<input type="text" name="username" id="text" placeholder="@Model.Translate(GeneralStrings.Username)">
<input type="text" name="username" id="text" placeholder="@username">
<i class="user icon"></i>
</div>
</div>

View file

@ -27,7 +27,7 @@ public class LoginForm : BaseLayout
{
if (string.IsNullOrWhiteSpace(username))
{
this.Error = this.Translate(ErrorStrings.UsernameInvalid);
this.Error = ServerConfiguration.Instance.Mail.MailEnabled ? this.Translate(ErrorStrings.UsernameInvalid) : this.Translate(ErrorStrings.EmailInvalid);
return this.Page();
}
@ -43,7 +43,23 @@ public class LoginForm : BaseLayout
return this.Page();
}
User? user = await this.Database.Users.FirstOrDefaultAsync(u => u.Username == username);
User? user;
if (!ServerConfiguration.Instance.Mail.MailEnabled)
{
user = await this.Database.Users.FirstOrDefaultAsync(u => u.Username == username);
}
else
{
user = await this.Database.Users.FirstOrDefaultAsync(u => u.EmailAddress == username);
if (user == null)
{
User? noEmailUser = await this.Database.Users.FirstOrDefaultAsync(u => u.Username == username);
if (noEmailUser != null && noEmailUser.EmailAddress == null) user = noEmailUser;
}
}
if (user == null)
{
Logger.Warn($"User {username} failed to login on web due to invalid username", LogArea.Login);

View file

@ -74,6 +74,12 @@
<i class="lock icon"></i>
</div>
</div>
<div class="inline field">
<div class="ui checkbox">
<input type="checkbox" id="age-checkbox" required>
<label for="age-checkbox">I confirm that I am above 13 years old</label>
</div>
</div>
@if (ServerConfiguration.Instance.Captcha.CaptchaEnabled)
{

View file

@ -67,7 +67,7 @@ function onSubmit(e){
@if (ServerConfiguration.Instance.Mail.MailEnabled && (Model.User == Model.ProfileUser || Model.User!.IsAdmin))
{
<div class="field">
<label style="text-align: left" for="email">Email</label>
<label style="text-align: left" for="email">@Model.Translate(GeneralStrings.Email)</label>
<input type="text" name="email" id="email" required value="@Model.ProfileUser.EmailAddress" placeholder="Email Address">
</div>
}

View file

@ -28,6 +28,8 @@ public class RegisterTests : LighthouseWebTest
this.Driver.FindElement(By.Id("password")).SendKeys(password);
this.Driver.FindElement(By.Id("confirmPassword")).SendKeys(password);
this.Driver.FindElement(By.Id("age-checkbox")).Click();
this.Driver.FindElement(By.Id("submit")).Click();
User? user = await database.Users.FirstOrDefaultAsync(u => u.Username == username);
@ -51,6 +53,8 @@ public class RegisterTests : LighthouseWebTest
this.Driver.FindElement(By.Id("password")).SendKeys(password);
this.Driver.FindElement(By.Id("confirmPassword")).SendKeys(password + "a");
this.Driver.FindElement(By.Id("age-checkbox")).Click();
this.Driver.FindElement(By.Id("submit")).Click();
User? user = await database.Users.FirstOrDefaultAsync(u => u.Username == username);
@ -76,6 +80,8 @@ public class RegisterTests : LighthouseWebTest
this.Driver.FindElement(By.Id("password")).SendKeys(password);
this.Driver.FindElement(By.Id("confirmPassword")).SendKeys(password);
this.Driver.FindElement(By.Id("age-checkbox")).Click();
this.Driver.FindElement(By.Id("submit")).Click();
Assert.Contains("The username you've chosen is already taken.", this.Driver.PageSource);