public ActionResult Forgot(ForgotModel model) { if (string.IsNullOrEmpty(model.NewPassword)) { return(View(model)); } // trimming model.RestaurantID = model.RestaurantID.Trim(); model.UserName = model.UserName.Trim(); // Login in screen [Login] LoginModel en = new LoginModel(); en.UserName = model.UserName; en.Password = model.NewPassword; en.RestaurantID = model.RestaurantID; switch (DoLogin(en)) { case AfterLoginAction.ToSummaryPage: // show summary screen return(RedirectToAction("Index", "Summary")); case AfterLoginAction.ToChangePasswordPage: // show change pass screen return(RedirectToAction("ChangePassword")); default: ViewBag.ErrorMessage = Msg.M001; return(View(model)); } }
public async Task <IActionResult> Forgot(ForgotModel model) { await accountManager.ForgotPassword(model.Email); ViewData["Send"] = true; return(View()); }
public async Task <IActionResult> ForgotPost(ForgotModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(model.Email).ConfigureAwait(false); if (user.Status == null) { ModelState.AddModelError("Not Found", "User doesnt exists"); return(View(model)); } try { await user.ForgotPasswordAsync().ConfigureAwait(false); } catch (Exception exp) { ModelState.AddModelError("Failed", exp.Message); return(View(model)); } return(RedirectToAction("ForgotConfirm", new ForgotConfirmModel { Email = model.Email })); } return(View(model)); }
public async Task <IActionResult> Forgot(ForgotModel model) { string email = model.Email.ToString(); var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var stringChars = new char[8]; var random = new Random(); for (int i = 0; i < stringChars.Length; i++) { stringChars[i] = chars[random.Next(chars.Length)]; } var finalString = new String(stringChars); //Work with user User user = await _context.Users .Include(u => u.Role) .FirstOrDefaultAsync(u => u.Email == email); if (user != null) { user.Password = finalString; _context.Update(user); await _context.SaveChangesAsync(); try { SmtpClient smtpClient = new SmtpClient("mail7.meuhost.net", 25); smtpClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Info4!891"); smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.EnableSsl = true; MailMessage mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(new MailAddress(email)); mail.Subject = "Star Wars: Renegade - забыли пароль?"; mail.Body = "Вы забыли пароль? Ваш новый: " + finalString + " Поменять пароль всегда можно в личном кабинете."; try { await Task.Run(() => { smtpClient.Send(mail); }); } catch (Exception ex) { } return(RedirectToAction("Login")); }catch (Exception ex) { } } return(RedirectToAction("Login")); }
public ActionResult Forgot() { if (Session.CurrentUser() != null) { return(RedirectToAction("Index", "Home")); } else { var model = new ForgotModel(); return(View(model)); } }
public async Task <ActionResult> Forgot(ForgotModel model) { if (ModelState.IsValid) { try { if (Session["Captcha"] != null && model.Sum.HasValue && model.Sum == (int)Session["Captcha"]) { var ctx = SingletonIpl.GetInstance <DataProvider>(); var user = ctx.GetUserByEmail(model.Email); if (!user.Active) { ModelState.AddModelError(string.Empty, string.Format("User Name or Email is inactive.")); return(View()); } if (user != null) { var sender = Utils.GetSetting("mail-sender", ""); var guid = Guid.NewGuid(); var url = UrlUtil.GetCurrentHost() + string.Format("Security/ResetPassword/{0}", guid); string body = Utilities.Utils.Stringtmp("ForgotPassword.txt", new { User = user.FullName, Url = url }); EmailService.Send(sender, model.Email, "Forgot Password", body); var forgotExpired = DateTime.UtcNow.AddHours(Utils.GetSetting <double>("expiredHour", 4)); ctx.ResetExpireDate(user.UserId, forgotExpired, guid); return(View("ForgotResult")); } } else { if (!model.Sum.HasValue) { ModelState.AddModelError("Sum", "The Captcha is required."); } else if (Session["Captcha"] != null && model.Sum != (int)Session["Captcha"]) { ModelState.AddModelError("Sum", "The Captcha is invalid. Please try again."); } } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } } return(View(model)); }
public async Task <IActionResult> Forgot(ForgotModel model) { if (ModelState.IsValid) { var user = _pool.GetUser(model.Email); if (user != null) { await user.ForgotPasswordAsync(); } } return(View(model)); }
public async Task <IActionResult> Forgot(ForgotModel model) { StringBuilder builder = new StringBuilder(); Random random = new Random(); char ch; for (int i = 0; i < 8; i++) { ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))); builder.Append(ch); } EmailService emailService = new EmailService(); if (ModelState.IsValid) { string URL = "https://beautysaloonnika.azurewebsites.net/"; string message = @"<html> <body> <h3> Восстановление пароля учетной записи в салоне красоты 'Ника'⠀</h3> <br> <p>Ваш логин: " + model.Email + @" <br> Ваш новый пароль: " + builder.ToString() + @" </p> <br> <p>Изменить свой пароль вы можете в личном кабинете. Перейти на сайт можно по <a href='" + URL + @"'>ссылке</a> <br> Будем рады видеть Вас в салоне красоты 'Nika'! </p> С уважением, администрация салона красоты 'Nika'! </body> </html> "; User user = await db.Users.FirstOrDefaultAsync(cl => cl.Email == model.Email); if (user != null) { await emailService.SendEmailAsync(model.Email, "Password recovery", message); // апдэйт пользователя в бд user.Password = GetHashString(builder.ToString()); await db.SaveChangesAsync(); return(RedirectToAction("Login", "Account")); } else { ModelState.AddModelError(model.Email, "Пользователя нет в системе"); } } return(View(model)); }
public async Task <ActionResult> ForgotPassword(ForgotModel model) { if (ModelState.IsValid) { var user = unitOfWork.UserManager.FindByEmail(model.Email); if (user == null || user.EmailConfirmed == false) { return(View("ForgotPasswordConfirmation")); } string code = await unitOfWork.UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Auth", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await unitOfWork.UserManager.SendEmailAsync(user.Id, "Reset password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction <AuthController>(c => c.ForgotPasswordConfirmation())); } return(View(model)); }
public ActionResult Forgot(ForgotModel model) { if (WebSecurity.GetUserId(model.UserName) > -1 && (WebSecurity.IsConfirmed(model.UserName))) { string token = WebSecurity.GeneratePasswordResetToken(model.UserName, 1200); /* Get IBO Email */ IBO ibo = IBOVirtualAPI.GetIBOByUId(WebSecurity.GetUserId(model.UserName).ToString()); /* Set And Send Email Reset Request */ ResertEmailContact contact = new ResertEmailContact(); contact.name = model.UserName; contact.email = ibo.email; contact.token = token; bool result = IBOVirtualAPI.CreateResetEmail(contact); } else { ModelState.AddModelError(String.Empty, TextResources.Businesslms.ErrorUserNotFound); } return(View(model)); }
public ActionResult Forgot(ForgotModel model) { if (ModelState.IsValid) { DbContext db = new DbContext("DefaultConnection"); using (DiamondCircle_dbEntities dbs = new DiamondCircle_dbEntities()) { var user = dbs.UserDetails.Where(s => s.Email == model.Email).FirstOrDefault(); if (user == null) { TempData["Msg"] = "Your email address does not exist in our records. We are unable to reset your password."; return(RedirectToAction("Message", "Home")); } else { string query = String.Format("select UserName from UserProfile where UserId ='{0}'", user.UserId); string username = db.Database.SqlQuery <string>(query, user.UserId).FirstOrDefault(); RandomStringGenerator newPass = new RandomStringGenerator(); string NewPassword = newPass.Create(6).Trim(); var token = WebSecurity.GeneratePasswordResetToken(username); WebSecurity.ResetPassword(token, NewPassword); string body = "Dear " + username + ",\n\r Your new password is: \n\r " + NewPassword + " \n\r \n\r Regards," + " \n\r \n\r The Diamond Circle team"; SendEmail.Send("Diamond Circle", model.Email, "New Password", body); } } TempData["Msg"] = "A new password has been sent to your email address."; return(RedirectToAction("Message", "Home")); } return(View(model)); }
public ActionResult Forgot(ForgotModel oFM) { try { if (!String.IsNullOrEmpty(oFM.Username) || !String.IsNullOrEmpty(oFM.Email)) { CGeneralUser oUser = CFGeneral.ForgotPassword(oFM.Username, oFM.Email); if (oUser.Success) { return(RedirectToAction("Login", "Account")); } else { ViewBag.ErrorMsg = oUser.Exception; } } return(View()); } catch (Exception ex) { return(RedirectToAction("Index", "Error", new { Message = ex.Message, InnerException = ex.InnerException })); } }
public async Task <ActionResult> ForgotPass(ForgotModel model) { var user = await userManager.FindByEmailAsync(model.Email); if (user != null) { var provider = new DpapiDataProtectionProvider("MVC_Prices2"); userManager.UserTokenProvider = new DataProtectorTokenProvider <AppUser>( provider.Create("MVC_Prices2")); string code = await userManager.GeneratePasswordResetTokenAsync(user.Id); string message; var callbackUrl = Url.Action("ResetPass", "Account", new { UserId = user.Id, code = code }, protocol: Request.Url.Scheme); message = "To reset your password please click <a href=\"" + callbackUrl + "\">here</a>"; ModelState.AddModelError("", "Please check your email."); await SendEmail(user.Email, "Reset Your Password", message); } else { ModelState.AddModelError("", "There is no user signed with this e-mail. "); } return(View()); }
public async Task <IActionResult> Forgot() { var model = new ForgotModel(); return(View(model)); }
public ActionResult FORGOT_PASSWORD(ForgotModel model) { /*//verify Email * //generate reset password link * //send email * string message = " "; * bool Status = false;*/ string MailCon = ConfigurationManager.ConnectionStrings["SqlServer"].ConnectionString; SqlConnection Sqlcon = new SqlConnection(MailCon); string Sqlquery = "select Email, Password from [dbo].[User] where Email = @Email"; SqlCommand Sqlcommand = new SqlCommand(Sqlquery, Sqlcon); Sqlcommand.Parameters.AddWithValue("@Email", SqlNotificationType.Subscribe); Sqlcon.Open(); SqlDataReader sdr = Sqlcommand.ExecuteReader(); if (sdr.Read()) { string username = sdr["Email"].ToString(); string password = sdr["Password"].ToString(); MailMessage mm = new MailMessage("*****@*****.**", " chimene.com237"); mm.Subject = "your password"; mm.Body = string.Format("hello: <h1>{0}</h1> is your email id <br/> your password is <h1>{1}</h1>", username, password); mm.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; NetworkCredential nc = new NetworkCredential(); nc.UserName = "******"; nc.Password = "******"; smtp.UseDefaultCredentials = true; smtp.Credentials = nc; smtp.Port = 587; smtp.Send(mm); // string msg = " "; } /* * using (Authenticate dc = new Authenticate()) * { * var account = dc.User.where(XmlSiteMapProvider => XmlSiteMapProvider.Email == Email).FirstOrDefaut(); * * if (account != null) * { * // send email for reset password * string resetcode = Guid.NewGuid().ToString(); * sendVerificationLinkEmail(account.Email, resetcode,"resetpassword"); * account.ResetPasswordCode = resetcode; * // this line i have added here to avoid confirm password not match * //issu, as we had added a confirm password property * //in cur model class in part * dc.Configuration.ValidateOnSaveEnabled = false; * * dc.SaveChanges(); * message="reset password link has been send to your email id" * * } * else * { * message = " Account not found"; * } * }*/ return(View()); }
public async Task <IActionResult> Forgot(ForgotModel model) { return(View(model)); }
public LogonModule (SuperSimpleAuth ssa) { this.ssa = ssa; Get["/settings"] = parameters => { SettingsModel model = new SettingsModel(); if(this.Context.CurrentUser == null) { return this.LogoutAndRedirect("/"); } model.Planeswalker = (Planeswalker)this.Context.CurrentUser; return View["Logon/Settings",model]; }; Post["/settings"] = parameters => { SettingsModel model = this.Bind<SettingsModel>(); if(this.Context.CurrentUser == null) { return this.LogoutAndRedirect("/"); } model.Planeswalker = (Planeswalker)this.Context.CurrentUser; if(Request.Form.Save != null) { model.Planeswalker.Profile.Email = model.Email; model.Planeswalker.Profile.Name = model.Name; try { model.Planeswalker = repository.UpdatePlaneswalker(model.Planeswalker); } catch(Exception e) { model.Errors.Add("Could not update account"); model.Errors.Add(e.Message); } } if(Request.Form.Delete != null) { try { if(model.Yes) { ssa.Disable(model.Planeswalker.AuthToken); repository.RemovePlaneswalker(model.Planeswalker.Id); return this.LogoutAndRedirect("/"); } else { model.Errors.Add("You must check, 'Yes, I know'. To delete."); } } catch(Exception e) { model.Errors.Add("Account could not be deleted"); model.Errors.Add(e.Message); } } if(Request.Form.ChangePassword != null) { if(model.Password != null && model.ConfirmPassword != null) { if(model.Password == model.ConfirmPassword) { try { ssa.ChangePassword(model.Planeswalker.AuthToken, model.Password); model.Messages.Add("Password successfully changed."); } catch(Exception e) { model.Errors.Add("Password cannot be changed."); model.Errors.Add(e.Message); } } else { model.Errors.Add("Password and Confirmation Password do not match."); } } else { model.Errors.Add("Password and Confirmation Password must not be blank."); } } return View["Logon/Settings",model]; }; Get["/logon"] = parameters => { LogonModel model = new LogonModel(); model.ActiveMenu = "signin"; model.UrlRedirect = (string)Request.Query.Url; if(Request.Query.returnUrl != null) { model.UrlRedirect = (string)Request.Query.returnUrl; } return View["Logon/logon",model]; }; Post["/logon"] = parameters => { LogonModel model = this.Bind<LogonModel>(); model.ActiveMenu = "signin"; var results = this.Validate(model); if(!results.IsValid) { model.Errors = ErrorUtility.GetValidationErrors(results); return View["Logon/Logon", model]; } model.Errors.Add("Password or/and Username is incorrect."); User user = null; try { user = ssa.Authenticate(model.UserName, model.Secret, this.Context.Request.UserHostAddress); } catch(Exception e) { model.Errors.Add(e.Message); if(user == null) { return View["Logon/logon", model]; } } return this.LoginAndRedirect(user.AuthToken, fallbackRedirectUrl: model.UrlRedirect); }; Get ["/register"] = parameters => { SignupModel model = new SignupModel(); model.ActiveMenu = "register"; return View["register", model]; }; Post ["/register"] = parameters => { SignupModel model = this.Bind<SignupModel>(); var result = this.Validate(model); model.ActiveMenu = "register"; if (!result.IsValid) { model.Errors.AddRange(ErrorUtility.GetValidationErrors(result)); return View["Register", model]; } try { repository.AddPlaneswalker(model.UserName, model.Secret, model.Email); } catch(Exception e) { model.Errors.Add(e.Message); return View["Register", model]; } LogonModel logon = new LogonModel(); logon.Messages.Add("You have successfully created an account. Please Sign In."); try { Email.send("*****@*****.**", "New Planeswalker alert", model.UserName); } catch(Exception e) { //swallow this for now } return View["Logon", logon]; }; Get["/logout"] = parameters => { Planeswalker nuser = (Planeswalker)Context.CurrentUser; ssa.End(nuser.AuthToken); return this.LogoutAndRedirect((string)Request.Query.Url); }; Get ["/forgot"] = parameters => { ForgotModel model = new ForgotModel(); model.ActiveMenu = "signin"; return View["Forgot", model]; }; Post ["/forgot"] = parameters => { ForgotModel model = this.Bind<ForgotModel>(); model.ActiveMenu = "signin"; string subject = "MtgDb.info: Password reset request."; string body = "You have requested a password reset. You new password is: {0}"; try { string newPass = ssa.Forgot(model.Email); Email.send(model.Email, subject,string.Format(body,newPass)); model.Messages.Add("Your new password has been successfully sent to your email."); } catch(Exception e) { model.Errors.Add(e.Message); } return View["Forgot", model]; }; }