Prevent user locking when duplicating the email entries

This commit is contained in:
Marcel Baumgartner
2023-06-24 22:35:38 +02:00
parent 389ded9b77
commit f9f5865ef9

View File

@@ -5,6 +5,8 @@
@using Moonlight.App.Models.Forms
@using Moonlight.App.Repositories
@using Mappy.Net
@using Moonlight.App.Exceptions
@using Moonlight.App.Helpers
@inject UserRepository UserRepository
@@ -89,9 +91,20 @@
private Task Save()
{
CurrentUser = Mapper.Map(CurrentUser, Model);
// Prevent users from locking out other users by changing their email
CurrentUser.Email = CurrentUser.Email.ToLower();
Model.Email = Model.Email.ToLower();
var userWithThatEmail = UserRepository
.Get()
.FirstOrDefault(x => x.Email == Model.Email);
if (userWithThatEmail != null && CurrentUser.Id != userWithThatEmail.Id)
{
Logger.Warn($"A user tried to lock another user out by changing the email. Email: {Model.Email}", "security");
throw new DisplayException("A user with that email does already exist");
}
CurrentUser = Mapper.Map(CurrentUser, Model);
UserRepository.Update(CurrentUser);