@page "/profile" @using Moonlight.Shared.Components.Navigations @using Moonlight.App.Database.Entities @using Moonlight.App.Models.Forms @using Moonlight.App.Repositories @using Mappy.Net @using Moonlight.App.Exceptions @using Moonlight.App.Helpers @inject UserRepository UserRepository
@code { private UserDataModel Model = new(); [CascadingParameter] public User CurrentUser { get; set; } private Task Load(LazyLoader loader) { Model = Mapper.Map(CurrentUser); return Task.CompletedTask; } private Task Save() { // Prevent users from locking out other users by changing their email 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); return Task.CompletedTask; } }