public IActionResult Forgotpassword(ForgotPassword model) { if (!ModelState.IsValid) { return(View(model)); } var user = userService.GetUserForForgotPassword(model.Email); if (user != null) { ActiveEmailViewModel emailViewModel = new ActiveEmailViewModel { ActiveCode = user.ActiveCode, UserId = user.UserId }; emailSender.SendEmail(model.Email, "بازیابی کلمه عبور", renderViewToString.Render("_ResetPasswordEmail", emailViewModel)); return(RedirectToAction("ResetConfirm")); } ModelState.AddModelError("Email", "ایمیل معتبر نیست"); return(View(model)); }
public async Task <IActionResult> Register(RegisterUserViewModel model) { if (!ModelState.IsValid) { return(View(model)); } if (!await GoogleRecaptchaHelper.IsReCaptchaPassedAsync(Request.Form["g-recaptcha-response"], _config["GoogleReCaptcha:secret"])) { ModelState.AddModelError(string.Empty, "احراز هویت را انجام دهید"); return(View(model)); } string activecode = Guid.NewGuid().ToString().Replace("-", ""); User user = new User { Email = model.Email, Password = string.Join("-", PasswordHash.HashPasswordV2(model.Password)), EmailActiveCode = activecode }; int userid = userService.AddUser(user); if (userid > 0) { ActiveEmailViewModel emailViewModel = new ActiveEmailViewModel { ActiveCode = activecode, UserId = userid }; emailSender.SendEmail(model.Email, "ارسال ایمیل فعال سازی", renderViewToString.Render("_ActiveEmail", emailViewModel)); } ModelState.AddModelError(string.Empty, "در ثبت اطلاعات مشکلی به وجود امده است"); return(View(model)); }