Auto approve migration emails if the password is correct. Change Email Link dump to Critical to ensure it makes it into the logs. (#1069)

This commit is contained in:
Joseph Milazzo 2022-02-12 15:14:13 -08:00 committed by GitHub
parent fb8d40c360
commit bb5e0593a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 33 deletions

3
.gitignore vendored
View File

@ -526,5 +526,4 @@ API/config/post-metadata/
API.Tests/TestResults/ API.Tests/TestResults/
UI/Web/.vscode/settings.json UI/Web/.vscode/settings.json
/API.Tests/Services/Test Data/ArchiveService/CoverImages/output/* /API.Tests/Services/Test Data/ArchiveService/CoverImages/output/*
/UI/Web/.angular/ UI/Web/.angular/

View File

@ -409,7 +409,7 @@ namespace API.Controllers
if (string.IsNullOrEmpty(token)) return BadRequest("There was an issue sending email"); if (string.IsNullOrEmpty(token)) return BadRequest("There was an issue sending email");
var emailLink = GenerateEmailLink(token, "confirm-email", dto.Email); var emailLink = GenerateEmailLink(token, "confirm-email", dto.Email);
_logger.LogInformation("[Invite User]: Email Link for {UserName}: {Link}", user.UserName, emailLink); _logger.LogCritical("[Invite User]: Email Link for {UserName}: {Link}", user.UserName, emailLink);
if (dto.SendEmail) if (dto.SendEmail)
{ {
await _emailService.SendConfirmationEmail(new ConfirmationEmailDto() await _emailService.SendConfirmationEmail(new ConfirmationEmailDto()
@ -507,7 +507,7 @@ namespace API.Controllers
} }
var emailLink = GenerateEmailLink(await _userManager.GeneratePasswordResetTokenAsync(user), "confirm-reset-password", user.Email); var emailLink = GenerateEmailLink(await _userManager.GeneratePasswordResetTokenAsync(user), "confirm-reset-password", user.Email);
_logger.LogInformation("[Forgot Password]: Email Link for {UserName}: {Link}", user.UserName, emailLink); _logger.LogCritical("[Forgot Password]: Email Link for {UserName}: {Link}", user.UserName, emailLink);
var host = _environment.IsDevelopment() ? "localhost:4200" : Request.Host.ToString(); var host = _environment.IsDevelopment() ? "localhost:4200" : Request.Host.ToString();
if (await _emailService.CheckIfAccessible(host)) if (await _emailService.CheckIfAccessible(host))
{ {
@ -561,7 +561,7 @@ namespace API.Controllers
if (user.EmailConfirmed) return BadRequest("User already confirmed"); if (user.EmailConfirmed) return BadRequest("User already confirmed");
var emailLink = GenerateEmailLink(await _userManager.GenerateEmailConfirmationTokenAsync(user), "confirm-email", user.Email); var emailLink = GenerateEmailLink(await _userManager.GenerateEmailConfirmationTokenAsync(user), "confirm-email", user.Email);
_logger.LogInformation("[Email Migration]: Email Link: {Link}", emailLink); _logger.LogCritical("[Email Migration]: Email Link: {Link}", emailLink);
await _emailService.SendMigrationEmail(new EmailMigrationDto() await _emailService.SendMigrationEmail(new EmailMigrationDto()
{ {
EmailAddress = user.Email, EmailAddress = user.Email,
@ -615,21 +615,23 @@ namespace API.Controllers
try try
{ {
var token = await _userManager.GenerateEmailConfirmationTokenAsync(user); var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);
if (string.IsNullOrEmpty(token)) return BadRequest("There was an issue sending email"); //if (string.IsNullOrEmpty(token)) return BadRequest("There was an issue sending email");
user.Email = dto.Email; user.Email = dto.Email;
if (!await ConfirmEmailToken(token, user)) return BadRequest("There was a critical error during migration");
_unitOfWork.UserRepository.Update(user); _unitOfWork.UserRepository.Update(user);
await _unitOfWork.CommitAsync(); await _unitOfWork.CommitAsync();
var emailLink = GenerateEmailLink(await _userManager.GenerateEmailConfirmationTokenAsync(user), "confirm-migration-email", user.Email); //var emailLink = GenerateEmailLink(await _userManager.GenerateEmailConfirmationTokenAsync(user), "confirm-migration-email", user.Email);
_logger.LogInformation("[Email Migration]: Email Link for {UserName}: {Link}", dto.Username, emailLink); // _logger.LogCritical("[Email Migration]: Email Link for {UserName}: {Link}", dto.Username, emailLink);
// Always send an email, even if the user can't click it just to get them conformable with the system // // Always send an email, even if the user can't click it just to get them conformable with the system
await _emailService.SendMigrationEmail(new EmailMigrationDto() // await _emailService.SendMigrationEmail(new EmailMigrationDto()
{ // {
EmailAddress = dto.Email, // EmailAddress = dto.Email,
Username = user.UserName, // Username = user.UserName,
ServerConfirmationLink = emailLink // ServerConfirmationLink = emailLink
}); // });
return Ok(emailLink); return Ok();
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -26,7 +26,7 @@ export class AddEmailToAccountMigrationModalComponent implements OnInit {
error: string = ''; error: string = '';
constructor(private accountService: AccountService, private modal: NgbActiveModal, constructor(private accountService: AccountService, private modal: NgbActiveModal,
private serverService: ServerService, private confirmService: ConfirmService) { private serverService: ServerService, private confirmService: ConfirmService, private toastr: ToastrService) {
} }
ngOnInit(): void { ngOnInit(): void {
@ -40,25 +40,23 @@ export class AddEmailToAccountMigrationModalComponent implements OnInit {
} }
save() { save() {
this.serverService.isServerAccessible().subscribe(canAccess => { const model = this.registerForm.getRawValue();
const model = this.registerForm.getRawValue(); model.sendEmail = false;
model.sendEmail = canAccess; this.accountService.migrateUser(model).subscribe(async () => {
this.accountService.migrateUser(model).subscribe(async (email) => { // if (!canAccess) {
console.log(email); // // Display the email to the user
if (!canAccess) { // this.emailLink = email;
// Display the email to the user // await this.confirmService.alert('Please click this link to confirm your email. You must confirm to be able to login. The link is in your logs. You may need to log out of the current account before clicking. <br/> <a href="' + this.emailLink + '" target="_blank">' + this.emailLink + '</a>');
this.emailLink = email; // this.modal.close(true);
await this.confirmService.alert('Please click this link to confirm your email. You must confirm to be able to login. The link is in your logs. You may need to log out of the current account before clicking. <br/> <a href="' + this.emailLink + '" target="_blank">' + this.emailLink + '</a>'); // } else {
this.modal.close(true); // await this.confirmService.alert('Please check your email (or logs under "Email Link") for the confirmation link. You must confirm to be able to login.');
} else { // this.modal.close(true);
await this.confirmService.alert('Please check your email (or logs under "Email Link") for the confirmation link. You must confirm to be able to login.'); // }
this.modal.close(true); this.toastr.success('Email has been validated');
} this.modal.close(true);
}, err => { }, err => {
this.error = err; this.error = err;
}); });
});
} }