public ActionResult LostPassword(LostPasswordModel model) { if (!ModelState.IsValid) { return(View(model)); } try { var accountName = Core.Common.UrlHelper.GetAccountNameFromUrl(Url.ToAbsolute(Url.Current().ToString())); var userService = new UserService(DbContext); var user = userService.FindUser(model.Login, accountName); if (user == null) { ModelState.AddModelError(string.Empty, "Такого пользователя не существует"); return(View(model)); } userService.StartResetPassword(user.Id); return(View("PasswordRestored", (object)user.Login)); } catch (UserFriendlyException exception) { ModelState.AddModelError(string.Empty, exception.Message); return(View(model)); } }
public HttpResponseMessage LostPassword(HttpRequestMessage request, LostPasswordModel model) { try { var user = IoC.Resolve <IUserService>().GetSingleByCondition(n => n.UserName.Equals(model.UserName)); if (model.UserName.Equals(user.UserName) && model.Email.Equals(user.Email)) { string keyId = user.Id; string nonce = Guid.NewGuid().ToString("N"); string link = _domain + "/api/account/resetpassword?keyId=" + keyId + "&nonce=" + nonce; string contentMail = System.IO.File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath("~/Content/html/EmailLostpassword.html")); contentMail = contentMail.Replace("{{account}}", user.UserName); contentMail = contentMail.Replace("{{link}}", link); var timeStamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; MemoryCache.Default.Add(nonce, timeStamp, DateTimeOffset.UtcNow.AddSeconds(maxTimeStamp)); EmailHelper.SendEmail(fromMail, user.Email, "Hệ thống thông báo", contentMail, displayName, emailPassword, host, port, ssl); return(request.CreateResponse(HttpStatusCode.OK)); } else { return(request.CreateResponse(HttpStatusCode.BadRequest)); } } catch (Exception ex) { IoC.Resolve <cvmk.service.Interface.IErrorService>().TryLog(ex); return(request.CreateResponse(HttpStatusCode.BadRequest)); } }
public ActionResult LostPassword(LostPasswordModel model) { bool tr = false; if (ModelState.IsValid) { User user = db.Users.Where(a => a.UserName == model.ReturnToken).FirstOrDefault(); user.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(model.Password, "md5"); UpdateModel(user.Password); db.SubmitChanges(); tr = true; if (tr == true) { ViewBag.Message = "Şifreniz Başarıyla Değiştirildi.Yeni Şifrenizle Giriş Yapabilirsiniz."; } else { ViewBag.Message = "Parola Sıfırlamada Hata Oluştu"; } } return(View()); }
public ActionResult LostPassword(string rt) { LostPasswordModel model = new LostPasswordModel(); model.ReturnToken = rt; return(View(model)); }
public ActionResult LostPassword(LostPasswordModel model) { if (ModelState.IsValid) { MembershipUser user; using (var context = new MultipartContext()) { var foundUserName = (from u in context.UserProfiles where u.Email == model.Email select u.UserName).FirstOrDefault(); if (foundUserName != null) { user = Membership.GetUser(foundUserName.ToString()); } else { user = null; } } if (user != null) { // Generae password token that will be used in the email link to authenticate user var token = WebSecurity.GeneratePasswordResetToken(user.UserName); // Generate the html link sent via email string resetLink = "<a href='" + Url.Action("ResetPassword", "Account", new { rt = token }, "http") + "'>Reset Password Link</a><br/>"; MailMessage mail = new MailMessage(); mail.To.Add(new MailAddress(model.Email)); mail.From = new MailAddress("*****@*****.**"); mail.Bcc.Add(new MailAddress("*****@*****.**")); mail.Subject = "Reset your password for Multi-PART application website"; mail.Body = "We have received a request to reset your password on Multi-PART application website. Please ignore this email if the request was not sent by you. <br/> If you want to reset your password, please click on the link: " + resetLink + "<br><br/> Thank you, <br/>Multi-PART Group"; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); // Attempt to send the email try { smtp.Send(mail); } catch (Exception e) { ModelState.AddModelError("", "Issue sending email: " + e.Message + "<br/>"); } } } ViewBag.sent = "yes"; return(View(model)); }
public ActionResult LostPassword(LostPasswordModel model) { if (ModelState.IsValid) { MembershipUser user; using (var context = new UsersContext()) { var foundUserName = (from u in context.UserProfiles where u.UserMail == model.Email select u.UserName).FirstOrDefault(); if (foundUserName != null) { user = Membership.GetUser(foundUserName.ToString()); } else { user = null; } } if (user != null) { var token = WebSecurity.GeneratePasswordResetToken(user.UserName); dynamic email = new Email("ResetPass"); email.UserName = user.UserName; email.To = model.Email; email.resetlink = Url.Action("ResetPassword", "Account", new { rt = token }, "http"); try { email.Send(); ViewBag.MailSent = "Sprawdź swoją pocztę, link do zreseotwania hasła został wysłany."; } catch (Exception e) { ModelState.AddModelError("", "Błąd wysyłania wiadomości: " + e.Message); } } else { ModelState.AddModelError("", "Nie znaleziono użytkownika z danym adresem e-mail."); } } return(View(model)); }
public ActionResult LostPassword(LostPasswordModel model) { if (ModelState.IsValid) { if (Membership.GetUserNameByEmail(model.Email) != null) { return(View("LostPasswordSuccess", model)); } else { ModelState.AddModelError("", "L'adresse email saisie n'a pas été trouvée dans notre système."); } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult RecoverPassword(LostPasswordModel model) { var user = _userRepository.Filter(x => x.Email.Equals(model.Email)).FirstOrDefault(); if (user == null) { return(RedirectToAction("Index", "Home")); } var password = _passwordGenerationService.GenerateTemporaryPassword(); user.Password = password; user.HashPassword(); user.DefaultPassword = user.Password; user.IsUsingDefaultPassword = true; _userRepository.Update(user); MailgunEmailService.SendEmailToUser(user, MessageService.ChangePasswordMessage(password)); return(RedirectToAction("LogIn", "Account")); }
public ActionResult LostPassword(LostPasswordModel lostPasswordModel) { if (ModelState.IsValid) { var client = new RestClient(WebConfigurationManager.AppSettings["webApiUrl"]); var request = new RestRequest("api/account/lostpassword", Method.POST); request.RequestFormat = DataFormat.Json; request.AddJsonBody(lostPasswordModel); var response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.BadRequest) { return(View("~/Views/Account/LostPasswordSent.cshtml")); } } return(View()); }
public async Task <IHttpActionResult> LostPassword(LostPasswordModel lostPasswordModel) { if (!ModelState.IsValid) { var message = responseService.ModelStateErrorsToString(ModelState); return(BadRequest(message)); } IdentityUser user = await repository.FindUserByLoginInfo(lostPasswordModel.LoginInfo); if (user == null) { return(BadRequest("User not found.")); } var passwordResetToken = await repository.GeneratePasswordResetToken(user); emailService.SendLostPasswordMail(user.Email, passwordResetToken); return(Ok()); }
public ActionResult ForgotPassword(LostPasswordModel model) { if (ModelState.IsValid) { var person = (from a in db.Registered_Person where a.Person_ID == model.personId select a).FirstOrDefault(); var result = db.spResetPasswordFunc(model.personId).FirstOrDefault(); if (Convert.ToBoolean(result.ReturnCode)) { SendPasswordResetEmail(result.Email, model.personId, result.UniqueId.ToString()); } return(RedirectToAction("passResetPost")); } else { return(View()); } }
public ActionResult LostPassword(LostPasswordModel model) { if (ModelState.IsValid) { string errorCode = string.Empty; if (Manager.ResetPassword(model.Email, Url, out errorCode)) { ViewBag.Message = Resources.Resource.EmailSentMsg; } else { if (errorCode == ErrorCodes.EmailSentError.ToString()) { ModelState.AddModelError("", Resources.Resource.EmailSendError); } else if (errorCode == ErrorCodes.UserNotFoundError.ToString()) { ModelState.AddModelError("", Resources.Resource.NoUserWithThatEmailError); } } } return(View(model)); }
public ActionResult ForgotPassword(LostPasswordModel model) { //Boolean ErrorFlag = false; //unused if (TryValidateModel(model)) { var messageService = new AuthMessageSender(); var userService = new User.UserService(); var newPassword = userService.ResetUserPassword(model.Email); var sentmessage = messageService.SendEmailAsync(model.Email, "Reset IRIS Password", "Hello " + model.Email + " your temporary password is " + newPassword); if (!sentmessage) { //ErrorFlag = true; ModelState.AddModelError(string.Empty, "SMTP server is down, unable to send temporary password at this time."); return(View("ForgotPassword", model)); } else { Session["ExpirationTime"] = DateTime.Now.AddHours(4); return(View("ForgotPasswordConfirmation")); } //return RedirectToAction("ForgotPasswordConfirmation"); //unreachable } else { return(View("Login")); } }
public ActionResult Login(AuthStartRequestModel model, string ReturnUrl) { Dictionary <int, string> tenantList = (Dictionary <int, string>)Session["TenantList"]; if (ModelState.IsValid) { var userInfo = _coreService.LoadModel <IRISUserModel>(conName: "IrisAuth").FirstOrDefault(u => u.UserName == model.Username); if (userInfo != null) { var hashPassword = CryptoHelper.ComputeHash(model.Password, userInfo.SALT); if (userInfo.HashPassword != hashPassword) { ModelState.AddModelError(string.Empty, "Invalid email and/or password."); return(View("Login", model)); } if (userInfo.LoginChangePassword.HasValue ? !userInfo.LoginChangePassword.Value : false) { HttpCookie sessionCookie = _userService.StartSessionCookie(model.Username, model.Password); if (sessionCookie != null) { Session["DefaultTenantKey"] = userInfo.DefaultTenant_Key; Session["CurrentTenantKey"] = userInfo.DefaultTenant_Key; Session["CurrentGeneralAccessLevel"] = userInfo.GeneralAccessLevel; Session["CurrentUserKey"] = userInfo.User_Key; Session["CurrentUserName"] = userInfo.UserName; Session["ConString"] = "User" + userInfo.DefaultTenant_Key.ToString(); pageHelper.CreateTables(); Response.Cookies.Set(sessionCookie); if (string.IsNullOrEmpty(ReturnUrl)) { return(RedirectToAction(actionName: "ReportMain", controllerName: "ReportApp")); } else { return(Redirect(ReturnUrl)); } } else { ModelState.AddModelError(string.Empty, "Invalid email and/or password."); return(View("Login", model)); } } else { if (Session["ExpirationTime"] != null && (DateTime)Session["ExpirationTime"] < DateTime.Now) { ModelState.AddModelError(string.Empty, "Your temporary password has expired. Click the Forgot Your Password link to receive a new one."); LostPasswordModel expiredPassword = new LostPasswordModel(); expiredPassword.Email = model.Username; expiredPassword.FirstName = userInfo.FirstName; ForgotPassword(expiredPassword); return(View("Login", model)); } else { var IRISUserModel = new ChangePasswordViewModel { UserName = model.Username }; return(RedirectToAction("ChangePassword", "ReportApp", IRISUserModel)); } } } else { ModelState.AddModelError(string.Empty, "Invalid email and/or password."); return(View("Login", model)); } } return(View("ReportMain", model)); }
public ActionResult LostPassword() { var model = new LostPasswordModel(); return(View(model)); }
public ActionResult LostPassword(LostPasswordModel model) { if (ModelState.IsValid) { MembershipUser user; using (var context = new UsersContext()) { var foundUserName = (from u in context.UserProfiles where u.EmployeeId == model.EmployeeId select u.UserName).FirstOrDefault(); if (foundUserName != null) { user = Membership.GetUser(foundUserName.ToString()); } else { user = null; } } if (user != null) { // Generae password token that will be used in the email link to authenticate user var token = WebSecurity.GeneratePasswordResetToken(user.UserName); return(RedirectToAction("ResetPassword", new { rt = token })); //// Generate the html link sent via email //string resetLink = "<a href='" // + Url.Action("ResetPassword", "Account", new { rt = token }, "http") // + "'>Reset Password Link</a>"; //// Email stuff //string subject = "Reset your password for asdf.com"; //string body = "You link: " + resetLink; //string from = "*****@*****.**"; //MailMessage message = new MailMessage(from, model.Email); //message.Subject = subject; //message.Body = body; //SmtpClient client = new SmtpClient(); //client.EnableSsl = false; //client.Credentials = CredentialCache.DefaultNetworkCredentials; ////client.DeliveryMethod = SmtpDeliveryMethod.Network; //// Attempt to send the email //try //{ // client.Send(message); //} //catch (Exception e) //{ // ModelState.AddModelError("", "Issue sending email: " + e.Message); //} } else // Email not found { /* Note: You may not want to provide the following information * since it gives an intruder information as to whether a * certain email address is registered with this website or not. * If you're really concerned about privacy, you may want to * forward to the same "Success" page regardless whether an * user was found or not. This is only for illustration purposes. */ ModelState.AddModelError("", "No user found by that email."); } } /* You may want to send the user to a "Success" page upon the successful * sending of the reset email link. Right now, if we are 100% successful * nothing happens on the page. :P */ return(View(model)); }