public async Task <IActionResult> Index(string returnUrl) { var vm = new RecoverViewModel(); if (!String.IsNullOrWhiteSpace(returnUrl)) { var context = await _interaction.GetAuthorizationContextAsync(returnUrl); if (context != null) { vm.Email = context.LoginHint; vm.ReturnUrl = returnUrl; if (!String.IsNullOrWhiteSpace(context.ClientId)) { var client = await _clientService.FindEnabledClientByIdAsync(context.ClientId); vm.ExternalProviders = await _clientService.GetEnabledProvidersAsync(client); vm.EnableLocalLogin = client != null ? client.EnableLocalLogin : false; } } } return(View(vm)); }
public async Task <IActionResult> Index(RecoverInputModel model) { if (ModelState.IsValid) { // Load user by email var email = model.Email.ToLower(); // Check if user with same email exists var userAccount = await _userAccountService.LoadByEmailAsync(email); if (userAccount != null) { await _userAccountService.SetResetPasswordVirificationKey(userAccount, model.ReturnUrl); var args = new { Key = userAccount.VerificationKey }; await _emailService.SendEmailAsync( IdentityBaseConstants.EmailTemplates.UserAccountRecover, userAccount.Email, new { ConfirmUrl = Url.Action("Confirm", "Recover", args, Request.Scheme), CancelUrl = Url.Action("Cancel", "Recover", args, Request.Scheme) } ); return(await this.RedirectToSuccessAsync(userAccount, model.ReturnUrl)); } else { ModelState.AddModelError("", "User is deactivated."); } } var vm = new RecoverViewModel(model); return(View(vm)); }
public async Task <IActionResult> Confirm(string key) { var result = await _userAccountService.HandleVerificationKey(key, VerificationKeyPurpose.ResetPassword); if (result.UserAccount == null || !result.PurposeValid || result.TokenExpired) { ModelState.AddModelError("", "Invalid token"); return(View("InvalidToken")); } var returnUrl = result.UserAccount.VerificationStorage; var vm = new RecoverViewModel { ReturnUrl = returnUrl, Email = result.UserAccount.Email }; return(View(vm)); }