Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing admin users to change users email #3118

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions API/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,19 @@ public async Task<ActionResult> 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need a new line after the if statement to help the code be easier to digest.

user.EmailConfirmed = true;
user.NormalizedEmail = _userManager.NormalizeEmail(dto.Email);
_unitOfWork.UserRepository.Update(user);
}

// Update roles
var existingRoles = await _userManager.GetRolesAsync(user);
Expand Down
4 changes: 4 additions & 0 deletions API/DTOs/Account/UpdateUserDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ public record UpdateUserDto
/// An Age Rating which will limit the account to seeing everything equal to or below said rating.
/// </summary>
public AgeRestrictionDto AgeRestriction { get; init; } = default!;
/// <summary>
/// An email address on file for the user.
/// </summary>
public string Email { get; set; }
}
2 changes: 0 additions & 2 deletions UI/Web/src/app/admin/edit-user/edit-user.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Loading