public ActionResult Email(ForgotenPasswordViewModel model) { try { var mail = new System.Net.Mail.MailAddress(model.Email); String username = Membership.GetUserNameByEmail(model.Email); MembershipUser user = Membership.GetUser(username); if (user != null) { string oldpassword = user.ResetPassword(); string newPassword = Membership.GeneratePassword(12, 2); bool password = user.ChangePassword(oldpassword, newPassword); umbraco.library.SendMail("*****@*****.**", model.Email, "newPassword", "hei " + user + " passord endred: " + newPassword + "", false); } if (user == null) { umbraco.library.SendMail("*****@*****.**", model.Email, "newPassword", "Ingen bruker med " + model.Email + " er registrert i dette systemet", false); } TempData["Status"] = "Sjekk din inbox for nytt passord!"; } catch { TempData["Status"] = "Dette er ikke en epost adresse! skriv riktig epost"; return(RedirectToCurrentUmbracoPage()); } return(Redirect("/")); }
public string ForgotenPasswordSendCode(ForgotenPasswordViewModel model) { var checkEmailAtDB = this.context.Users.FirstOrDefault(u => u.Email == model.Email); if (checkEmailAtDB == null) { return("Няма регистриран потребител с такъв email"); } var userId = checkEmailAtDB.Email; var claimType = "ForgotenPasswordSendCode"; const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; string code = userId.Substring(0, Math.Min(3, userId.Length)); var length = 8 - code.Length; Random random = new Random(); code += new string(Enumerable.Repeat(chars, length) .Select(s => s[random.Next(s.Length)]).ToArray()); var claim = new IdentityUserClaim <string>(); var checkClaimCode = this.context.UserClaims .FirstOrDefault(c => c.UserId == userId && c.ClaimType == claimType); if (checkClaimCode != null) { claim = checkClaimCode; } claim.ClaimType = claimType; claim.ClaimValue = code; claim.UserId = userId; this.context.SaveChanges(); var info = new Dictionary <string, string>(); info.Add("code", code); var userEmail = model.Email; this.sendMail.SendMailByTemplate(userEmail, claimType, info); return(" "); }
public ActionResult ShowNewPasswordRequestForm() { var model = new ForgotenPasswordViewModel(); return(PartialView("~/Views/Partials/Demo/NewPasswordPagePartial.cshtml", model)); }
public IActionResult ForgotenPasswordSendCode(ForgotenPasswordViewModel model) { var result = this.homeService.ForgotenPasswordSendCode(model); return(this.View()); }