protected async Task <IActionResult> HandleLoginNotAllowed(UserLoginResult result, string returnUrl) { Analytics.HandleLoginNotAllowed(result).Forget(); if (result.User != null) { await IpAddressTracker.TackUserIpAddress(CurrentSite.Id, result.User.Id); if (result.NeedsEmailConfirmation) { if (ShouldSendConfirmation(result.User)) { var callbackUrl = Url.Action(new UrlActionContext { Action = "ConfirmEmail", Controller = "Account", Values = new { userId = result.User.Id.ToString(), code = result.EmailConfirmationToken, returnUrl }, Protocol = HttpContext.Request.Scheme }); EmailSender.SendAccountConfirmationEmailAsync( CurrentSite, result.User.Email, StringLocalizer["Confirm your account"], callbackUrl, result.EmailConfirmationToken ).Forget(); this.AlertSuccess(StringLocalizer["Please check your email inbox, we just sent you a link that you need to click to confirm your account"], true); } return(RedirectToAction("EmailConfirmationRequired", new { userId = result.User.Id, didSend = true, returnUrl })); } if (result.NeedsAccountApproval) { var timeSpan = DateTime.UtcNow - result.User.CreatedUtc; if (timeSpan.TotalDays < 1) { // account was just created so send notification to approver EmailSender.AccountPendingApprovalAdminNotification(CurrentSite, result.User).Forget(); } return(RedirectToAction("PendingApproval", new { userId = result.User.Id, didSend = true })); } } return(this.RedirectToSiteRoot(CurrentSite)); }
public virtual async Task <IActionResult> ConfirmEmail(string userId, string code, string returnUrl) { if (AccountService.IsSignedIn(User)) { return(this.RedirectToSiteRoot(CurrentSite)); } if (userId == null || code == null) { return(this.RedirectToSiteRoot(CurrentSite)); } var result = await AccountService.ConfirmEmailAsync(userId, code); if (result.User == null) { return(this.RedirectToSiteRoot(CurrentSite)); } if (result.IdentityResult.Succeeded) { if (CurrentSite.RequireApprovalBeforeLogin && !result.User.AccountApproved) { await EmailSender.AccountPendingApprovalAdminNotification(CurrentSite, result.User).ConfigureAwait(false); return(RedirectToAction("PendingApproval", new { userId = result.User.Id, didSend = true })); } else if (!string.IsNullOrWhiteSpace(returnUrl)) { // if we have a return url we should just go ahead and redirect to login this.AlertSuccess(StringLocalizer["Thank you for confirming your email."], true); return(RedirectToAction("Login", new { returnUrl })); } } else { this.AlertDanger(StringLocalizer["Oops something went wrong"], true); } return(View()); }