SendPasswordResetInstructions() public méthode

public SendPasswordResetInstructions ( User user, string resetPasswordUrl, bool forgotPassword ) : void
user User
resetPasswordUrl string
forgotPassword bool
Résultat void
Exemple #1
0
        private ActionResult SendPasswordResetEmail(User user, bool forgotPassword)
        {
            var resetPasswordUrl = Url.ResetEmailOrPassword(
                user.Username,
                user.PasswordResetToken,
                forgotPassword,
                relativeUrl: false);

            MessageService.SendPasswordResetInstructions(user, resetPasswordUrl, forgotPassword);

            return(RedirectToAction(actionName: "PasswordSent", controllerName: "Users"));
        }
        private ActionResult SendPasswordResetEmail(User user, bool forgotPassword)
        {
            var resetPasswordUrl = Url.ConfirmationUrl(
                "ResetPassword",
                "Users",
                user.Username,
                user.PasswordResetToken,
                new { forgot = forgotPassword });

            MessageService.SendPasswordResetInstructions(user, resetPasswordUrl, forgotPassword);

            return(RedirectToAction(actionName: "PasswordSent", controllerName: "Users"));
        }
Exemple #3
0
        private ActionResult SendPasswordResetEmail(User user, bool forgotPassword)
        {
            var resetPasswordUrl = Url.ConfirmationUrl(
                "ResetPassword",
                "Users",
                user.Username,
                user.PasswordResetToken,
                new { forgot = forgotPassword });

            MessageService.SendPasswordResetInstructions(user, resetPasswordUrl, forgotPassword);

            TempData["Email"] = user.EmailAddress;
            return(RedirectToAction(MVC.Users.PasswordSent()));
        }
            public void WillSendInstructions()
            {
                var user = new User {
                    EmailAddress = "*****@*****.**", Username = "******"
                };
                var mailSender = new Mock <IMailSender>();
                var config     = new Mock <IAppConfiguration>();

                config.Setup(x => x.GalleryOwner).Returns(TestGalleryOwner);
                var         messageService = new MessageService(mailSender.Object, config.Object);
                MailMessage message        = null;

                mailSender.Setup(m => m.Send(It.IsAny <MailMessage>())).Callback <MailMessage>(m => { message = m; });

                messageService.SendPasswordResetInstructions(user, "http://example.com/pwd-reset-token-url");

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(TestGalleryOwner.Address, message.From.Address);
                Assert.Equal("[Joe Shmoe] Please reset your password.", message.Subject);
                Assert.Contains("Click the following link within the next", message.Body);
                Assert.Contains("http://example.com/pwd-reset-token-url", message.Body);
            }
        public virtual ActionResult ForgotPassword(ForgotPasswordViewModel model)
        {
            // We don't want Login to have us as a return URL
            // By having this value present in the dictionary BUT null, we don't put "returnUrl" on the Login link at all
            ViewData[Constants.ReturnUrlViewDataKey] = null;

            if (ModelState.IsValid)
            {
                var user = UserService.GeneratePasswordResetToken(model.Email, Constants.DefaultPasswordResetTokenExpirationHours * 60);
                if (user != null)
                {
                    var resetPasswordUrl = Url.ConfirmationUrl(
                        MVC.Users.ResetPassword(), user.Username, user.PasswordResetToken, protocol: Request.Url.Scheme);
                    MessageService.SendPasswordResetInstructions(user, resetPasswordUrl);

                    TempData["Email"] = user.EmailAddress;
                    return(RedirectToAction(MVC.Users.PasswordSent()));
                }

                ModelState.AddModelError("Email", "Could not find anyone with that email.");
            }

            return(View(model));
        }
            public void WillSendInstructions()
            {
                var user = new User { EmailAddress = "*****@*****.**", Username = "******" };
                var mailSender = new Mock<IMailSender>();
                var setting = new GallerySetting { GalleryOwnerName = "NuGet Gallery", GalleryOwnerEmail = "*****@*****.**" };
                var messageService = new MessageService(mailSender.Object, setting);
                MailMessage message = null;
                mailSender.Setup(m => m.Send(It.IsAny<MailMessage>())).Callback<MailMessage>(m => { message = m; });

                messageService.SendPasswordResetInstructions(user, "http://example.com/pwd-reset-token-url");

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal("[NuGet Gallery] Please reset your password.", message.Subject);
                Assert.Contains("Click the following link within the next", message.Body);
                Assert.Contains("http://example.com/pwd-reset-token-url", message.Body);
            }
            public void WillSendInstructions()
            {
                var user = new User { EmailAddress = "*****@*****.**", Username = "******" };
                var mailSender = new Mock<IMailSender>();
                var config = new Mock<IAppConfiguration>();
                config.Setup(x => x.GalleryOwner).Returns(TestGalleryOwner);
                var messageService = new MessageService(mailSender.Object, config.Object);
                MailMessage message = null;
                mailSender.Setup(m => m.Send(It.IsAny<MailMessage>())).Callback<MailMessage>(m => { message = m; });

                messageService.SendPasswordResetInstructions(user, "http://example.com/pwd-reset-token-url");

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(TestGalleryOwner.Address, message.From.Address);
                Assert.Equal("[Joe Shmoe] Please reset your password.", message.Subject);
                Assert.Contains("Click the following link within the next", message.Body);
                Assert.Contains("http://example.com/pwd-reset-token-url", message.Body);
            }