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

@ -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);