public forgetclass ForgetPassword(ForgetPasswordModel forgetPasswordModel) { ForgetModel forget = new ForgetModel(); UserAccount login = new UserAccount(); login.Email = forgetPasswordModel.Email; UserAccount validateEmail = userContext.Accounts .Where(e => e.Email.Equals(login.Email)).FirstOrDefault(e => e.Email == login.Email); var jwt = GenerateToken(validateEmail); forget.JwtToken = jwt; if (validateEmail != null) { var model1 = new ForgetPasswordModel { Email = forgetPasswordModel.Email }; var model2 = new ForgetModel { JwtToken = forget.JwtToken }; var model = new forgetclass { Email = model1.Email, JwtToken = model2.JwtToken }; return(model); } else { throw new UserAccountException(UserAccountException.ExceptionType.EMAIL_DONT_EXIST, "email address is not registered"); } }
public void UISaveForgetModel(ForgetModel forgetModel) { User user = mapper.Map <User>(forgetModel); user.BindingEmail = new Email(); userRepository.UserSaveChanges(user); }
private void EmailCheckOut(ForgetModel model, PasswordService passwordService) { EmailController email = new EmailController(); int captcha = email.EmailActivate(new ActivateModel { Email = model.Email, Expire = DateTime.Now.AddMinutes(10), UserName = model.UserName }, "改变密码"); }
public ActionResult ForgetPassword(ForgetModel forget) { DbConnection dbhandle = new DbConnection(); dbhandle.Connection(); try { if (ModelState.IsValid) { using (SqlCommand FrgtCmd = new SqlCommand("USPForgotPassword", dbhandle.con)) { FrgtCmd.Connection = dbhandle.con; FrgtCmd.CommandType = CommandType.StoredProcedure; FrgtCmd.Parameters.AddWithValue("@EmailId", forget.Email); dbhandle.con.Open(); using (SqlDataReader profile = FrgtCmd.ExecuteReader()) { if (profile.HasRows) { while (profile.Read()) { FrgtCmd.Connection = dbhandle.con; string emailId = profile["Email"].ToString(); string Username = profile["UserName"].ToString(); string Password = profile["Password"].ToString(); string message = "Hi,\n Your request for Username and password is recieved.\n \n Username: "******" \n Password : "******"Forget Username and Password", message); ViewBag.message = " Your Password has been sent to your mail"; } } else { ViewBag.message = " Email is not Registered"; return(View("ForgotPassword")); } } } dbhandle.con.Close(); } } catch (Exception e) { ExceptionLog.Log(e, Request.UserHostAddress); return(RedirectToAction("Error_View", "CompanyRegister")); } finally { Dispose(); } return(View("ForgotPassword")); }
public ActionResult Forget(ForgetModel model) { if (ModelState.IsValid) { var check = CommonEmail.IsValidEmailAddress(model.Email); if (!check) { alertLogin = true; ViewBag.alertLogin = alertLogin; Redirect("Login/Forget"); ViewBag.Mes = "Email không đúng định dạng!"; } else { var dao = new UserDao(); var result = dao.GetUserWithEmail(model.Email); if (result == null) { alertLogin = true; ViewBag.alertLogin = alertLogin; Redirect("Login/Forget"); ViewBag.Mes = "Email không tồn tại trong hệ thống!"; } else { var newPassword = CommonString.GenerateNumber(); check = CommonEmail.Send(result.Email, "Lấy lại mật khẩu", string.Format("Mật khẩu của tài khoản '{0}' là: {1}", result.UserName, newPassword)); if (check) { check = dao.UpdatePassword(result.ID, Encryptor.MD5Hash(newPassword)); } if (check) { ViewBag.alertSuss = true; ViewBag.Mes = "Đã gửi mật khẩu vào Email!"; } else { alertLogin = true; ViewBag.alertLogin = alertLogin; Redirect("Login/Forget"); ViewBag.Mes = "Gửi mật khẩu bị lỗi!"; } } } } return(View("Forget")); }
public async Task <IActionResult> Forget(ForgetModel model) { var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { return(BadRequest("Incorrect")); } string code = await _userManager.GeneratePasswordResetTokenAsync(user); // string callBackUrl = ""=code; // EmailSender.EmailService(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callBackUrl + "\">here</a>"); return(Ok()); }
public ActionResult Forget(ForgetModel model) { //new EmailService().SendEmailHeiper(model.EmailAddress);//真 new EmailService().SendEmailHelper("*****@*****.**");//假的 开发便利 ForgetModel RepoModel = _passwordService.GetForgetModelByName(model.UserName); if (model.VerificationCode != Session["Capthca"].ToString()) { ModelState.AddModelError(nameof(model.VerificationCode), "* 验证码不正确"); } if (!ModelState.IsValid) { return(View(model)); } return(View(RepoModel)); }
public ForgetModel FindUserInfo(ForgetModel model) { if (model.Email != null) { user = userRepository.FindByEmail(model.Email); } else if (model.UserName != null) { user = userRepository.GetByName(model.UserName); } else { return(null); } ForgetModel forgetModel = mapper.Map <ForgetModel>(user); forgetModel.Email = user.Email.Address; return(forgetModel); }
public ActionResult Forget(ForgetModel model) { //验证 if (model.Captcha != Session[Keys.CAPTCHA].ToString()) { ModelState.AddModelError(model.Captcha, "验证码填错啦"); return(View(model)); } ForgetModel forgetModel = new ForgetModel(); if (model.Email != null) { forgetModel = passwordService.FindUserInfo(model); if (model.Email == forgetModel.Email) { EmailCheckOut(model, passwordService); } //else nothing } else if (model.UserName != null) { forgetModel = passwordService.FindUserInfo(model); if (model.UserName == forgetModel.UserName) { EmailCheckOut(model, passwordService); } //else nothing } else { ModelState.AddModelError(model.Email, "请您填写内容"); return(View()); } return(View()); }