diff --git a/API/Controllers/AccountController.cs b/API/Controllers/AccountController.cs index 2276a5a831..b3acc7e1cf 100644 --- a/API/Controllers/AccountController.cs +++ b/API/Controllers/AccountController.cs @@ -508,6 +508,19 @@ public async Task UpdateAccount(UpdateUserDto dto) await _userManager.UpdateNormalizedUserNameAsync(user); _unitOfWork.UserRepository.Update(user); } + + // Update email + if (!string.IsNullOrEmpty(dto.Email) && !user.Email!.Equals(dto.Email)) + { + // Validate email change + var emailValidationErrors = await _accountService.ValidateEmail(dto.Email); + if (emailValidationErrors.Any()) return BadRequest(await _localizationService.Translate(User.GetUserId(), "email-taken")); + + user.Email = dto.Email; + user.EmailConfirmed = true; + user.NormalizedEmail = _userManager.NormalizeEmail(dto.Email); + _unitOfWork.UserRepository.Update(user); + } // Update roles var existingRoles = await _userManager.GetRolesAsync(user); diff --git a/API/DTOs/Account/UpdateUserDto.cs b/API/DTOs/Account/UpdateUserDto.cs index bda664bdbc..c8354aac05 100644 --- a/API/DTOs/Account/UpdateUserDto.cs +++ b/API/DTOs/Account/UpdateUserDto.cs @@ -18,4 +18,8 @@ public record UpdateUserDto /// An Age Rating which will limit the account to seeing everything equal to or below said rating. /// public AgeRestrictionDto AgeRestriction { get; init; } = default!; + /// + /// An email address on file for the user. + /// + public string Email { get; set; } } diff --git a/UI/Web/src/app/admin/edit-user/edit-user.component.ts b/UI/Web/src/app/admin/edit-user/edit-user.component.ts index b460e82f8f..90a56fdb31 100644 --- a/UI/Web/src/app/admin/edit-user/edit-user.component.ts +++ b/UI/Web/src/app/admin/edit-user/edit-user.component.ts @@ -49,8 +49,6 @@ export class EditUserComponent implements OnInit { ngOnInit(): void { this.userForm.addControl('email', new FormControl(this.member.email, [Validators.required, Validators.email])); this.userForm.addControl('username', new FormControl(this.member.username, [Validators.required, Validators.pattern(AllowedUsernameCharacters)])); - - this.userForm.get('email')?.disable(); this.selectedRestriction = this.member.ageRestriction; this.cdRef.markForCheck(); }