public async Task <IActionResult> ResetPassword(string userId) { var user = await userManager.FindByIdAsync(userId); PasswordResetVM model = new PasswordResetVM() { UserId = userId }; return(PartialView(model)); }
public ActionResult ChangePassword(PasswordResetVM passwordResetViewModel) { bool isSaved = false; if (ModelState.IsValid) { isSaved = _authService.PasswordReset(passwordResetViewModel, LoginId); } passwordResetViewModel.Message = isSaved ? SuccessMessage : ErrorMessage; passwordResetViewModel.NewPassword = string.Empty; return(View(passwordResetViewModel)); }
public bool PasswordReset(PasswordResetVM passwordResetViewModel, string loginId) { bool isSaved = false; string oldPassword = SecurityFacade.Encrypt(passwordResetViewModel.OldPassword.Trim()); string newPassword = SecurityFacade.Encrypt(passwordResetViewModel.NewPassword.Trim()); if (string.IsNullOrEmpty(oldPassword) && string.IsNullOrEmpty(newPassword)) { return(isSaved); } try { isSaved = AuthDAO.PasswordReset(loginId, oldPassword, newPassword); } catch { isSaved = false; } return(isSaved); }
public async Task <JsonResult> ResetPassword(PasswordResetVM model) { if (model.Password != model.Password2) { return(Json(new { isok = false, error = "Двете копия на паролата не съвпадат." })); } var user = await userManager.FindByIdAsync(model.UserId); var userRoles = await userManager.GetRolesAsync(user); if (!userContext.IsUserInRole(Roles.GlobalAdministrator)) { if (userRoles.Contains(Roles.GlobalAdministrator)) { return(Json(new { isok = false, error = "Не можете да задавате парола на Администратор на инфраструктурата!" })); } } string resetToken = await userManager.GeneratePasswordResetTokenAsync(user); IdentityResult resetResult = await userManager.ResetPasswordAsync(user, resetToken, model.Password); return(Json(new { isok = resetResult.Succeeded, error = string.Join(",", resetResult.Errors.Select(x => x.Description)) })); }
public ActionResult ResetPassword(PasswordResetVM model) { var response = Request["g-recaptcha-response"]; const string secret = "6LcjsTQUAAAAALUtX2jw6R8y7oEkK8zHtBolrLli"; //Kendi Secret keyinizle değiştirin. //webclient recaptcha test var client = new WebClient(); var reply = client.DownloadString( string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secret, response)); var captchaResponse = JsonConvert.DeserializeObject <CaptchaResponse>(reply); if (ModelState.IsValid) { ContentSharingEntities1 db = new ContentSharingEntities1(); var usr = db.UserTable.FirstOrDefault(x => x.ActivationCode == model.ActivationCode); if (usr != null) { if (!captchaResponse.Success) { ViewBag.Message = "Lütfen güvenliği doğrulayınız."; } else { ViewBag.Message = "Güvenlik başarıyla doğrulanmıştır."; usr.Password = model.Password; db.SaveChanges(); } } } return(View()); }
public async Task <ResponseResult> PasswordReset(PasswordResetVM model) => await passwordResetClient.PostAsync(model);