Example #1
0
        public ActionResult ForgotPassword(string email)
        {
            var userStore = new UserStore<IdentityUser>();
            UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);
            var user = manager.FindByEmail(email);
            CreateTokenProvider(manager, PASSWORD_RESET);

            var code = manager.GeneratePasswordResetToken(user.Id);
            var callbackUrl = Url.Action("ResetPassword", "Home",
                                         new { userId = user.Id, code = code },
                                         protocol: Request.Url.Scheme);
            ViewBag.FakeEmailMessage = "Please reset your password by clicking <a href=\""
                                     + callbackUrl + "\">here</a>";
            return View();
        }
Example #2
0
        public ActionResult ForgotPassword(string email, RegisteredUser userRecovery)
        {
            var userStore = new UserStore<IdentityUser>();
            UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);
            var user = manager.FindByEmail(email);
            CreateTokenProvider(manager, PASSWORD_RESET);

            var code = manager.GeneratePasswordResetToken(user.Id);
            var callbackUrl = Url.Action("ResetPassword", "Accounts",
                                         new { userId = user.Id, code = code },
                                         protocol: Request.Url.Scheme);
            var body = "Please reset your password by clicking <a href=\""
                                     + callbackUrl + "\">here</a>";

            MailHelper mailer = new MailHelper();
            string response = mailer.EmailFromArvixe(
                                       new RegisteredUser(userRecovery.Email = email, userRecovery.Subject = "Password Recovery Email", userRecovery.Body = body));
            return View("PasswordEmail");
        }
        public ActionResult ForgotPassword(string email)
        {
            var userStore = new UserStore<IdentityUser>();
            UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);
            var user = manager.FindByEmail(email);
            CreateTokenProvider(manager, PASSWORD_RESET);

            if (user != null)
            {

                var code = manager.GeneratePasswordResetToken(user.Id);
                string callbackUrl = Url.Action("ResetPassword", "Home",
                                             new { userId = user.Id, code = code },
                                             protocol: Request.Url.Scheme);
                string emailMessage = "Please reset your password by clicking <a href=\""
                                         + callbackUrl + "\">here</a>";

                string response = new MailHelper().EmailFromArvixe(new ViewModels.Message(email, emailMessage));

                ViewBag.FakeEmailMessage = "Email successfully sent. Please check your email to reset your password";

                return View();
            }

            ViewBag.Error = "There wasn't an account for that email";
            return View();
        }
        public ActionResult ForgotPassword(string email)
        {
            //ensures valid input
            if (ModelState.IsValid)
            {
                CaptchaHelper captchaHelper = new CaptchaHelper();
                string captchaResponse = captchaHelper.CheckRecaptcha();
                ViewBag.CaptchaResponse = captchaResponse;

                //creates token to be sent to mail helper to allow password reset through email
                var userStore = new UserStore<IdentityUser>();
                UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);
                var user = manager.FindByEmail(email);
                CreateToken ct = new CreateToken();
                CreateTokenProvider(manager, PASSWORD_RESET);

                var code = manager.GeneratePasswordResetToken(user.Id);
                var callbackUrl = Url.Action("ResetPassword", "Home",
                                             new { userId = user.Id, code = code },
                                             protocol: Request.Url.Scheme);

                //send callbackUrl to email helper
                MailHelper mailer = new MailHelper();
                string message = "Please reset your password by clicking <a href=\""
                                         + callbackUrl + "\">here</a>";
                string subject = "Please reset your password";
                try
                {
                    mailer.EmailFromArvixe(message, user.Email, subject);
                    ViewBag.FakeEmailMessage =
                        "You have been sent an email to finish reseting your password";
                }
                catch (System.Exception ex)
                {
                    ViewBag.FakeEmailMessage = ex.Message;
                }
            }
            return View();
        }
Example #5
0
        public ActionResult ForgotPassword(string email)
        {

            CaptchaHelper captchaHelper = new CaptchaHelper();
            string captchaResponse = captchaHelper.CheckRecaptcha();
            ViewBag.CaptchaResponse = captchaResponse;
            if (captchaResponse == VALID_CAPTCHA)
            {
                var userStore = new UserStore<IdentityUser>();
                UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);
                var user = manager.FindByEmail(email);
                CreateTokenProvider(manager, PASSWORD_RESET);
                var code = manager.GeneratePasswordResetToken(user.Id);
                var callbackUrl = Url.Action("ResetPassword", "Home",
                                             new { userId = user.Id, code = code },
                                             protocol: Request.Url.Scheme);
                var emailMsg = "<h3>Please reset your password by clicking</h3> <a href=\""
                                         + callbackUrl + "\">This Link</a>";
                MailHelper mailer = new MailHelper();
                string response = mailer.EmailFromArvixe(new RegisteredUser { Email = user.Email, UserName = user.UserName }, emailMsg);
                ViewBag.Response = response;
                TempData["response"] = response;
                return RedirectToAction("Index", "Home");
            }
            return View();
        }
 public void EmailConfirmationToken()
 {
     var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(this._session));
     userManager.UserTokenProvider = new EmailTokenProvider<ApplicationUser, string>() { BodyFormat = "xxxx {0}", Subject = "Reset password" };
     userManager.Create(new ApplicationUser() { UserName = "test", Email = "[email protected]", EmailConfirmed = false }, "Welcome");
     var x = userManager.FindByEmail("[email protected]");
     string token = userManager.GeneratePasswordResetToken(x.Id);
     userManager.ResetPassword(x.Id, token, "Welcome!");
 }
Example #7
0
        public ActionResult ForgotPassword(string email)
        {
            var userStore = new UserStore<IdentityUser>();
            UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);
            var user = manager.FindByEmail(email);
            CreateTokenProvider(manager, PASSWORD_RESET);

            var code = manager.GeneratePasswordResetToken(user.Id);
            var callbackUrl = Url.Action("ResetPassword", "Account",
                                         new { userId = user.Id, code = code },
                                         protocol: Request.Url.Scheme);
            string link = "Please reset your password by clicking <a href=\""
                                     + callbackUrl + "\">here</a>";


            MailHelper mailer = new MailHelper();
            string response = mailer.EmailFromArvixe(
                                       new RegisteredUser(email, PASSWORD_RESET, link));
            if (response != "Failure sending mail.")
            {
                ViewBag.Success = response;
            }
            else {
                ViewBag.Failure = response;
            }

            return View();
        }
        public ActionResult ForgotPassword(string email)
        {
            var userStore = new UserStore<IdentityUser>();
            UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);
            var user = manager.FindByEmail(email);

            if (user == null)
            {
                ViewBag.Message = "Email not found. Please double-check and try again.";
                return View();
            }
            CreateTokenProvider(manager, PASSWORD_RESET);

            var code = manager.GeneratePasswordResetToken(user.Id);
            var callbackUrl = Url.Action("ResetPassword", "Home",
                                         new { userId = user.Id, code = code },
                                         protocol: Request.Url.Scheme);

            string emailBody = "Please reset your password by clicking <a href=\""
                                     + callbackUrl + "\">here</a>";

            MailHelper mailer = new MailHelper();

            string Subject = "Confirm password reset";
            string response = mailer.EmailFromArvixe(
                                       new Message(user.Email, Subject, emailBody));

            if (response.IndexOf("Success") >= 0)
            {
                ViewBag.Message = "A confirm email has been sent. Please check your your email.";
                ViewBag.Email = user.Email;
            }
            else
            {
                ViewBag.Message = response;
            }
            return View();
        }