public async Task <IHttpActionResult> ConfirmEmail(Guid userId, string code = "") { if (string.IsNullOrWhiteSpace(code)) { Logger.ServiceLog.Warn($"Пользователь {userId} не указал код."); return(GetErrorFromModel("code", "Требуется код.")); } var user = await AppUserManager.FindByIdAsync(userId); if (user == null) { Logger.ServiceLog.Warn($"Пользователь с {userId} не зарегистрирован в БД"); return(GetErrorFromModel("userId", "Такого пользователя не существует.")); } code = HttpUtility.UrlDecode(code); var result = await AppUserManager.ConfirmEmailAsync(userId, code); if (result.Succeeded) { Logger.ServiceLog.Info($"Пользователь {user.Id} успешно подтвердил аккаунт."); return(Ok()); } Logger.ServiceLog.Warn($"Пользователь с {userId} не подтвердил аккаунт"); return(GetErrorResult(result)); }
public async Task <IActionResult> ConfirmEmail(string key, string code) { if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(code)) { return(View("Error")); } var user = await _userManager.Users.Where(u => u.GeneratedKey == key).SingleOrDefaultAsync(); if (user == null) { return(View("Error")); } var result = await _userManager.ConfirmEmailAsync(user, code); if (result.Succeeded) { return(View("ConfirmEmail", user.UserName)); } else { return(View("Error", new ErrorViewModel { Errordescription = result.Errors.OrderByDescending(d => d.Description) })); } }
public async Task <ActionResult> ConfirmEmail(long userId, string code) { if (code == null) { return(View("Error")); } var result = await UserManager.ConfirmEmailAsync(userId, code); return(View(result.Succeeded ? "ConfirmEmail" : "Error")); }
public async Task <ActionResult> ConfirmEmail(string userId, string code) { if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(code)) { return(View("Error")); } var result = await UserManager.ConfirmEmailAsync(userId, code); return(View(result.Succeeded ? "ConfirmEmail" : "Error")); }
public async Task <ActionResult> ConfirmEmail(string userId, string token) { var result = await _userManager.ConfirmEmailAsync(userId, token); if (!result.Succeeded) { return(await View("Error")); } return(RedirectToAction("Index", "User")); }
public async Task <IdentityResult> ConfirmEmailAsync(string userId, string token) { try { return(await AppUserManager.ConfirmEmailAsync(userId, token)); } catch (Exception) { return(null); } }
public async Task <IHttpActionResult> ConfirmEmail(string userId = "", string code = "") { if (string.IsNullOrWhiteSpace(userId) || string.IsNullOrWhiteSpace(code)) { ModelState.AddModelError("", "User Id and Code are required"); return(BadRequest(ModelState)); } var result = await AppUserManager.ConfirmEmailAsync(userId, code); return(result.Succeeded ? Ok() : GetErrorResult(result)); }
public async Task <IHttpActionResult> ConfirmEmail(string userId = "", string token = "") { string code = System.Web.HttpUtility.UrlDecode(token); if (string.IsNullOrWhiteSpace(userId) || string.IsNullOrWhiteSpace(code)) { ModelState.AddModelError("", "User Id and Code are required"); return(BadRequest(ModelState)); } IdentityResult result = await AppUserManager.ConfirmEmailAsync(userId, code); return(!result.Succeeded ? GetErrorResult(result) : Ok()); }
public async Task <ActionResult> ConfirmEmail(string userId, string code) { if (userId == null || code == null) { return(View("_Error", new string[] { "Something went wrong." })); } IdentityResult result = await _userManager.ConfirmEmailAsync(userId, code); if (result.Succeeded) { return(View("ConfirmEmail")); } return(View("_Error", new string[] { "Something went wrong." })); }
public async Task <ActionResult> VerifyEmailResponse(string verifyToken) { var userId = User.Id; var result = await _appUserManager.ConfirmEmailAsync(userId, verifyToken); if (!result.Succeeded) { return(ErrorResult(HttpStatusCode.BadRequest, GetLocalizedString <AreaResources>("VerifyEmailResponseError"))); } User.EmailConfirmed = true; await _signInManager.RefreshIdentity(User); return(RedirectToAction(nameof(VerifyEmail), new { status = AccountActionStatus.VerifyEmailResponseSuccess.ToLowerCaseString() })); }
public async Task <IActionResult> ConfirmEmail(string key, string code) { if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(code)) { return(View("Error")); } var user = await _userManager.Users.SingleOrDefaultAsync(); if (user == null) { return(View("Error")); } var result = await _userManager.ConfirmEmailAsync(user, code); return(View(result.Succeeded ? "ConfirmEmail" : "Error")); }
public async Task <IHttpActionResult> ConfirmEmail(string userId = "", string code = "") { var escapedCode = Uri.UnescapeDataString(code); if (string.IsNullOrWhiteSpace(userId) || string.IsNullOrWhiteSpace(escapedCode)) { ModelState.AddModelError("", "User Id and Code are required"); return(BadRequest(ModelState)); } IdentityResult result = await AppUserManager.ConfirmEmailAsync(userId, code); if (result.Succeeded) { return(Ok()); } return(GetIdentityErrorResult(result)); }
public async Task <IHttpActionResult> ConfirmEmailAsync(ConfirmEmailForm form) { return (!ModelState.IsValid ? BadRequest(ModelState) : !await verifyUserAuthData(form.UserId, form.UserName, form.Password) ? BadRequest("Nazwa użytkownika, identyfikator lub hasło są niepoprawne") : !await verifyUserTokenAsync(form.UserId, form.Token) ? BadRequest("podany token jest niepoprawny") : await activateAccountAsync(form.UserId, form.Token)); async Task <bool> verifyUserAuthData(string userId, string userName, string password) => await AppUserManager.FindAsync(userName, password) is ApplicationUser user ? user.Id == userId.ToString() : false; Task <bool> verifyUserTokenAsync(string userId, string token) => AppUserManager.VerifyUserTokenAsync(userId, "Confirmation", token); async Task <IHttpActionResult> activateAccountAsync(string userId, string token) { IdentityResult identityResult = await AppUserManager.ConfirmEmailAsync(userId, token); return(identityResult.Succeeded ? Ok() : (IHttpActionResult)InternalServerError(new Exception("Nieoczekiwany błąd serwera"))); } }
public async Task <IHttpActionResult> ConfirmEmail(string userId = "", string code = "") { //TODO: update to POST, and request password as well, since user could have incorrectly typed email address if (string.IsNullOrWhiteSpace(userId) || string.IsNullOrWhiteSpace(code)) { ModelState.AddModelError("", "User Id and Code are required"); return(BadRequest(ModelState)); } IdentityResult result = await AppUserManager.ConfirmEmailAsync(userId, code); if (result.Succeeded) { return(Ok("You have been registered. Welcome to Holl3r Services!")); } else { return(GetErrorResult(result)); } }
public async Task <IActionResult> OnGetAsync(string userId, string code) { if (userId == null || code == null) { return(RedirectToPage("/Index")); } var user = await _userManager.FindByIdAsync(userId); if (user == null) { return(NotFound($"Unable to load user with ID '{userId}'.")); } var result = await _userManager.ConfirmEmailAsync(user, code); if (!result.Succeeded) { throw new InvalidOperationException($"Error confirming email for user with ID '{userId}':"); } return(Page()); }
public async Task <IActionResult> OnGet(string key, string code) { if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(code)) { return(RedirectToPage("/Error")); } var user = await _userManager.Users.SingleOrDefaultAsync(u => u.GeneratedKey == key); if (user == null) { return(RedirectToPage("/Error")); } var result = await _userManager.ConfirmEmailAsync(user, code); if (result.Succeeded) { return(Page()); } return(RedirectToPage("/Error")); }
public async Task <ActionResult> ConfirmEmail(Guid u, string code) { if (u == Guid.Empty || code == null) { return(View("Error")); } var user = await UserManager.GetUserFromUniqueId(HttpContext.GetOwinContext(), u); var result = await UserManager.ConfirmEmailAsync(user.Id, code); if (result.Succeeded) { try { // Remove the confirmation url from the database. _adminManager.DeleteUserConfirmationUrl(user.Id); // We have an unconfirmed email address implying the email address was changed. if (!string.IsNullOrWhiteSpace(user.UnConfirmedEmail)) { // it's an email change var appUser = UserManager.FindById(user.Id); var oldEmail = appUser.Email; appUser.Email = user.UnConfirmedEmail; appUser.UserName = user.UnConfirmedEmail; appUser.UnConfirmedEmail = string.Empty; // Update the database. UserManager.Update(appUser); _adminManager.PushToMailChimp(user.Id, oldEmail); this.SetNotificationMessage(NotificationType.StickySuccess, string.Format("Thanks, you new email address has been confirmed.{0}You should use this address when you next log in.", Environment.NewLine)); return(RedirectToAction("Index", "Home", new { email = user.Email })); } else { if (user.IsCompanyAdmin) { // Push the user to MailChimp and send welcome email _adminManager.PushToMailChimp(user.Id); _adminManager.SendWelcomeEmail(user.Email); } this.SetNotificationMessage(NotificationType.StickySuccess, string.Format("Yay! Email confirmed.{0}Now you can log in and get started.", Environment.NewLine)); } } catch (Exception exception) { ErrorStore.LogException(exception, System.Web.HttpContext.Current); } } else { await SendEmailConfirmationTokenAsync(user.Id, u, "Confirm your account - Resent"); this.SetNotificationMessage(NotificationType.Warning, string.Format("Your activation link has expired.{0}{0}We've resent an email to confirm your address.", Environment.NewLine)); } return(RedirectToAction("Login", "Account", new { email = user.Email })); }