public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name).Value; var user = await _userManager.FindByIdAsync(userId); if (user == null) { return(NotFound($"Unable to load user with ID '{userId}'.")); } var result = await _userManager.ConfirmSignUpAsync(user, Input.Code, true); if (!result.Succeeded) { throw new InvalidOperationException($"Error confirming account for user with ID '{userId}':"); } else { return(returnUrl != null?LocalRedirect(returnUrl) : Page() as IActionResult); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <IActionResult> Confirm(ConfirmModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { ModelState.AddModelError("UserNotFound", "User with given email is not found"); return(View(model)); } var result = await _userManager.ConfirmSignUpAsync(user, model.Code, false); if (result.Succeeded) { return(RedirectToAction("Index", "Home")); } else { foreach (var error in result.Errors) { ModelState.AddModelError(error.Code, error.Description); } return(View(model)); } } return(View(model)); }
public async Task <IActionResult> Confirm_Post(ConfirmModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(model.Email).ConfigureAwait(false); if (user == null) { ModelState.AddModelError("NotFound", "A user with the email adress was not found"); return(View(model)); } var result = await _userManager.ConfirmSignUpAsync(user, model.Code, true).ConfigureAwait(false); if (result.Succeeded) { return(RedirectToAction("Index", "Home")); } else { foreach (var item in result.Errors) { ModelState.AddModelError(item.Code, item.Description); } return(View(model)); } } return(View(model)); }
public async Task <IActionResult> Confirm(ConfirmModel model) { if (!ModelState.IsValid) { ModelState.AddModelError("InvalidData", "Please check input values."); return(View(model)); } var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { ModelState.AddModelError("NotFound", "User with the given email address is not found."); return(View(model)); } var result = await _userManager.ConfirmSignUpAsync(user, model.Code, true); if (result.Succeeded) { return(RedirectToAction("Index", "Home")); } else { foreach (var item in result.Errors) { ModelState.AddModelError(item.Code, item.Description); } return(View(model)); } }
public async Task <IActionResult> Confirm([FromForm] AccountConfirmViewModel model) { IActionResult result = View(model); if (ModelState.IsValid) { var email = User.GetEmail(); var user = await _userManager.FindByEmailAsync(email); if (user != null) { var confirmResult = await _userManager.ConfirmSignUpAsync(user, model.ConfirmationCode, true); if (confirmResult.Succeeded) { result = RedirectToAction("Index", "Home"); } else { foreach (var error in confirmResult.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } } } return(result); }
public async Task <IActionResult> Confirm(ConfirmViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = await _cognitoUserManager.FindByEmailAsync(model.Email); if (user == null) { ModelState.AddModelError("UserNotFound", "User doesn't exist."); return(View(model)); } var result = await _cognitoUserManager.ConfirmSignUpAsync(user, model.Code, false); if (result.Succeeded) { return(RedirectToAction(nameof(HomeController.Index), "Home")); } foreach (var error in result.Errors) { ModelState.AddModelError(error.Code, error.Description); } return(View(model)); }
public async Task <IActionResult> ConfirmSend(ConfirmModel model) { if (!ModelState.IsValid) { return(View("Confirm", model)); } var user = await userManager.FindByEmailAsync(model.Email); if (user == null) { ModelState.AddModelError("NotFound", "A user with given email was not found"); return(View("Confirm", model)); } await signInManager.SignInAsync(user, true); var result = await userManager.ConfirmSignUpAsync(user, model.Code, false); if (result.Succeeded) { return(RedirectToAction("Index", "Home")); } foreach (var item in result.Errors) { ModelState.AddModelError(item.Code, item.Description); } return(View("Confirm", model)); }
public async Task <IActionResult> Confirm(ConfirmationModel model) { if (!ModelState.IsValid) { // If we got this far, something failed, redisplay form return(await Task.FromResult(View())); } var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { ModelState.AddModelError("NotFound", "User with the email addres provided was not found"); return(await Task.FromResult(View(model))); } var confirmSignup = await _userManager.ConfirmSignUpAsync(user, model.Code, true); if (!confirmSignup.Succeeded) { foreach (var error in confirmSignup.Errors) { ModelState.AddModelError(error.Code, error.Description); } return(await Task.FromResult(View(model))); } return(RedirectToAction("Index", "Home")); }
public async void Test_GivenAUser_WhenConfirmSignUp_ThenResponseIsNotAltered() { userStoreMock.Setup(mock => mock.ConfirmSignUpAsync(It.IsAny <CognitoUser>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); var output = await userManager.ConfirmSignUpAsync(GetCognitoUser(), "code", true).ConfigureAwait(false); Assert.Equal(IdentityResult.Success, output); userStoreMock.Verify(); }
public async Task <IActionResult> Confirm(Confirm model) { if (ModelState.IsValid) { var user = await userManager.FindByEmailAsync(model.Email); if (user == null) { ModelState.AddModelError("NotFound", "A user with given email address was not found"); return(View(model)); } try { var result = await userManager.ConfirmSignUpAsync(user, model.Code, false).ConfigureAwait(false); if (result.Succeeded) { return(RedirectToAction("Index", "Home")); } else { foreach (var item in result.Errors) { ModelState.AddModelError(item.Code, item.Description); } return(View(model)); } } catch (Exception ex) { ModelState.AddModelError("Confirm", "Unable to confirm new user"); ModelState.AddModelError("ConfirmUnhandleError", ex.Message); } } return(View("Confirm", model)); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { //get user id var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name).Value; var user = await _userManager.FindByIdAsync(userId); if (user == null) { return(NotFound($"Unable to load user with ID '{userId}'.")); } var result = await _userManager.ConfirmSignUpAsync(user, Input.Code, true); if (!result.Succeeded) { throw new InvalidOperationException($"Error confirming account for user with ID '{userId}':"); } else { //this part is to add customer information into the DB var userName = await _userManager.GetUserNameAsync(user); var firstName = user.Attributes[CognitoAttribute.GivenName.AttributeName]; var lastName = user.Attributes[CognitoAttribute.FamilyName.AttributeName]; var email = user.Attributes[CognitoAttribute.Email.AttributeName]; var dateOfBirth = user.Attributes[CognitoAttribute.BirthDate.AttributeName]; var phone = user.Attributes[CognitoAttribute.PhoneNumber.AttributeName]; var customer_ID = user.Attributes[CognitoAttribute.Sub.AttributeName]; var customer = new Customer() { Customer_Id = customer_ID, //Customer_Id = 1111, Username = userName, FirstName = firstName, LastName = lastName, Email = email, Phone = phone }; _context.Add(customer); _context.SaveChanges(); var currentCustomerID = _context.Customer.Find(user.Attributes[CognitoAttribute.Sub.AttributeName]); //get cardid var cartId = HttpContext.Request.Cookies["CartId"]; var recentCart = await _context.Cart.FindAsync(Convert.ToString(cartId)); recentCart.Customer = currentCustomerID; _context.Update(recentCart); await _context.SaveChangesAsync(); return(returnUrl != null?LocalRedirect(returnUrl) : Page() as IActionResult); } } // If we got this far, something failed, redisplay form return(Page()); }