public async Task <IActionResult> ChangePassword(ChangePasswordViewModel model) { IActionResult result = View(model); if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(model.Email); if (user != null) { var changePasswordResult = await _userManager.ChangePasswordAsync(user, model.CurrentPassword, model.NewPassword); if (changePasswordResult.Succeeded) { TempData.Put("Dialog", new AlertViewModel(AlertType.Success, "Password changed", "Your password has been changed successfully!")); result = RedirectToAction(nameof(ChangePassword)); } else { foreach (var error in changePasswordResult.Errors) { ModelState.AddModelError(error.Code, error.Description); } } } } return(result); }
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 <bool> AssignRole(string email, string role) { bool result = false; try { var cogUser = await _userManager.FindByEmailAsync(email); var identityResult = await _userManager.AddToRoleAsync(cogUser, role); result = identityResult.Succeeded; if (identityResult.Errors?.Any() ?? false) { _loggingService.LogEvent( LogType.WARNING, $"{nameof(IdentityService)}.{nameof(AssignRole)}", string.Join("\n", identityResult.Errors.Select(e => $"{e.Code} - {e.Description}"))); } } catch (Exception ex) { _loggingService.LogEvent(ex); } return(result); }
public async Task <IActionResult> OnPostSecondAsync(string returnUrl = null) { HandlerName = "Second"; returnUrl = returnUrl ?? Url.Content("~/"); var user = await _userManager.FindByEmailAsync(Input.Email); if (user == null) { throw new InvalidOperationException($"Unable to retrieve user."); } var result = await _userManager.ResetPasswordAsync(user, Input.ResetToken, Input.NewPassword); if (result.Succeeded) { return(LocalRedirect(returnUrl)); } else { foreach (var item in result.Errors) { ModelState.AddModelError(item.Code, item.Description); } return(Page()); } }
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 Task <IActionResult> Confirm_Post(ConfirmModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { ModelState.AddModelError("NotFound", "User not found for this email address"); return(View(model)); } var result = await _userManager.ConfirmSignUpAsync(user, model.Code, true).ConfigureAwait(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> OnPostAsync(string returnUrl = null) { if (!ModelState.IsValid) { return(Page()); } returnUrl = returnUrl ?? Url.Content("~/"); var user = await _userManager.FindByEmailAsync(Input.Email); if (user == null) { throw new InvalidOperationException($"Unable to retrieve user."); } var result = await _userManager.ChangePasswordAsync(user, Input.CurrentPassword, Input.NewPassword); if (result.Succeeded) { _logger.LogInformation("Changed password for user with ID '{UserId}'.", user.UserID); return(LocalRedirect(returnUrl)); } else { _logger.LogInformation("Unable to change password for user with ID '{UserId}'.", user.UserID); foreach (var item in result.Errors) { ModelState.AddModelError(item.Code, item.Description); } return(Page()); } }
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(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> Confirm(ConfirmModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { ModelState.AddModelError("NotFound", "A user with the given email address was not found"); return(View(model)); } if (!await _userManager.IsEmailConfirmedAsync(user)) { var result = await _userManager.ConfirmSignUpAsync(user, model.Code, true); // var result = await _userManager.ConfirmEmailAsync(user, model.Code); if (result.Succeeded) { return(RedirectToAction("Index", "Home")); } foreach (var item in result.Errors) { ModelState.AddModelError(item.Code, item.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> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { //set origin attributew value for the user var user = _pool.GetUser(Input.UserName); user.Attributes.Add(CognitoAttribute.Email.AttributeName, Input.Email); user.Attributes.Add(CognitoAttribute.Address.AttributeName, "default"); user.Attributes.Add("custom:AddressLine1", "default"); user.Attributes.Add("custom:AddressLine2", "default"); user.Attributes.Add("custom:City", "default"); user.Attributes.Add("custom:State", "default"); user.Attributes.Add("custom:Country", "default"); user.Attributes.Add("custom:ZipCode", "default"); user.Attributes.Add(CognitoAttribute.BirthDate.AttributeName, "0000-00-00"); user.Attributes.Add(CognitoAttribute.Gender.AttributeName, "default"); user.Attributes.Add(CognitoAttribute.NickName.AttributeName, "default"); user.Attributes.Add(CognitoAttribute.PhoneNumber.AttributeName, "+01234567890"); user.Attributes.Add(CognitoAttribute.FamilyName.AttributeName, Input.LastName); user.Attributes.Add(CognitoAttribute.GivenName.AttributeName, Input.FirstName); //check if the email has been used var existuser = await _userManager.FindByEmailAsync(Input.Email); if (existuser != null) { ModelState.AddModelError(string.Empty, "E-mail address has been used"); return(Page()); } //creat account var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); await _signInManager.SignInAsync(user, isPersistent : false); return(RedirectToPage("./ConfirmAccount")); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <IActionResult> OnPostAsync() { var user = await _userManager.FindByEmailAsync(Input.Email); if (user == null) { throw new InvalidOperationException($"Unable to retrieve user."); } var a = await _userManager.ResetPasswordAsync(user); Input = new InputModel() { Email = "aaaaa" }; return(Page()); }
public async Task <IActionResult> OnPostAsync() { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(Input.Email); if (user == null || !(await _userManager.IsEmailConfirmedAsync(user))) { // Don't reveal that the user does not exist or is not confirmed return(RedirectToPage("./ResetPassword")); } // Cognito will send notification to user with reset token the user can use to reset their password. await user.ForgotPasswordAsync(); return(RedirectToPage("./ResetPassword")); } return(Page()); }
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> Index(object profile) { var user = await _userManager.FindByEmailAsync(User.GetEmail()); return(View()); }