public async Task <IActionResult> ConfirmEmail(string userId, string code) { if (userId == null || code == null) { return(View("Error")); } var user = await _userManager.FindByIdAsync(userId); if (user == null) { return(View("Error")); } var result = await _userManager.ConfirmEmailAsync(user, code); if (!result.Succeeded || _adminOptions.ConfirmationRecipient != MailAddressConfirmationRecipient.Admin) { return(View(result.Succeeded ? "ConfirmEmail" : "Error")); } var mailModel = new AccountConfirmedModel(_localizerFactory, _applicationOptions, Url.Action(nameof(Login))); await _emailSender.SendEmailAsync(user.Email, mailModel); return(View(result.Succeeded ? "ConfirmEmail" : "Error")); }
public async Task <IActionResult> Error() { // get exception-data var exceptionFeature = HttpContext.Features.Get <IExceptionHandlerPathFeature>(); var exception = exceptionFeature?.Error; var route = exceptionFeature?.Path; // only execute if there was a real exception if (exception != null) { _logger.LogError(0, exception, "Unhandled exception"); // collect additional exception-info from log? try { var mailModel = new ErrorMailModel(_localizerFactory, _applicationOptions, route, exception); await _mailService.SendEmailAsync(_errorOptions.ErrorRecipient, mailModel); } catch (Exception e) { _logger.LogError(0, e, "Unhandled exception in error-handling api"); } } return(View()); }
public async Task <IActionResult> ConfirmUser(int userId) { using (var uow = _identityDataService.StartUnitOfWork()) { var user = uow.UserRepository.Get(userId); if (user == null) { return(RedirectToAction(nameof(ManageUsers))); } user.EmailConfirmed = true; uow.UserRepository.Update(user); uow.Commit(); var mailModel = new AccountConfirmedModel(_localizerFactory, _applicationOptions, Url.Action(nameof(AccountController.Login), "Account")); await _emailSender.SendEmailAsync(user.Email, mailModel); } return(RedirectToAction(nameof(ManageUser), new { userId })); }