SendNewAccountEmail() public method

public SendNewAccountEmail ( MailAddress toAddress, string confirmationUrl ) : void
toAddress MailAddress
confirmationUrl string
return void
Example #1
0
        public virtual ActionResult ConfirmationRequiredPost()
        {
            User user            = GetCurrentUser();
            var  confirmationUrl = Url.ConfirmationUrl(
                "Confirm", "Users", user.Username, user.EmailConfirmationToken);

            var alreadyConfirmed = user.UnconfirmedEmailAddress == null;

            ConfirmationViewModel model;

            if (!alreadyConfirmed)
            {
                MessageService.SendNewAccountEmail(new MailAddress(user.UnconfirmedEmailAddress, user.Username), confirmationUrl);

                model = new ConfirmationViewModel
                {
                    ConfirmingNewAccount    = !(user.Confirmed),
                    UnconfirmedEmailAddress = user.UnconfirmedEmailAddress,
                    SentEmail = true,
                };
            }
            else
            {
                model = new ConfirmationViewModel {
                    AlreadyConfirmed = true
                };
            }
            return(View(model));
        }
        public virtual ActionResult ResendConfirmation(ResendConfirmationEmailViewModel 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 usersClaimingEmailAddress = UserService.FindByUnconfirmedEmailAddress(model.Email, model.Username);

                if (usersClaimingEmailAddress.Count == 1)
                {
                    var user            = usersClaimingEmailAddress.SingleOrDefault();
                    var confirmationUrl = Url.ConfirmationUrl(
                        MVC.Users.Confirm(), user.Username, user.EmailConfirmationToken, protocol: Request.Url.Scheme);
                    MessageService.SendNewAccountEmail(new MailAddress(user.UnconfirmedEmailAddress, user.Username), confirmationUrl);
                    return(RedirectToAction(MVC.Users.Thanks()));
                }
                else if (usersClaimingEmailAddress.Count > 1)
                {
                    ModelState.AddModelError("Username", "Multiple users registered with your email address. Enter your username in order to resend confirmation email.");
                }
                else
                {
                    ModelState.AddModelError("Email", "There was an issue resending your confirmation token.");
                }
            }
            return(View(model));
        }
Example #3
0
        public virtual ActionResult Register(RegisterRequest request)
        {
            // If we have to render a view, 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;

            // TODO: consider client-side validation for unique username
            // TODO: add email validation

            if (!ModelState.IsValid)
            {
                return(View());
            }

            User user;

            try
            {
                user = UserService.Create(
                    request.Username,
                    request.Password,
                    request.EmailAddress);
            }
            catch (EntityException ex)
            {
                ModelState.AddModelError(String.Empty, ex.Message);
                return(View());
            }

            if (Config.ConfirmEmailAddresses)
            {
                // Passing in scheme to force fully qualified URL
                var confirmationUrl = Url.ConfirmationUrl(
                    MVC.Users.Confirm(), user.Username, user.EmailConfirmationToken, protocol: Request.Url.Scheme);

                if (Config.ConfirmationsViaAdminEmail)
                {
                    MessageService.SendNewAdminApprovedAccountEmail(Config.AdminConfirmationEmail, user.Username, request.EmailAddress, confirmationUrl);
                }
                else
                {
                    MessageService.SendNewAccountEmail(new MailAddress(request.EmailAddress, user.Username), confirmationUrl);
                }
            }
            return(RedirectToAction(MVC.Users.Thanks()));
        }
        public virtual ActionResult ConfirmationRequiredPost()
        {
            User user            = UserService.FindByUsername(User.Identity.Name);
            var  confirmationUrl = Url.ConfirmationUrl(
                MVC.Users.Confirm(), user.Username, user.EmailConfirmationToken, protocol: Request.Url.Scheme);

            MessageService.SendNewAccountEmail(new MailAddress(user.UnconfirmedEmailAddress, user.Username), confirmationUrl);

            var model = new ConfirmationViewModel
            {
                ConfirmingNewAccount    = !(user.Confirmed),
                UnconfirmedEmailAddress = user.UnconfirmedEmailAddress,
                SentEmail = true,
            };

            return(View(model));
        }
            public void WillSendEmailToNewUser()
            {
                var to         = new MailAddress("*****@*****.**", "too");
                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.SendNewAccountEmail(to, "http://example.com/confirmation-token-url");

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(TestGalleryOwner.Address, message.From.Address);
                Assert.Equal("[Joe Shmoe] Please verify your account.", message.Subject);
                Assert.Contains("http://example.com/confirmation-token-url", message.Body);
            }
Example #6
0
        public virtual ActionResult ResendConfirmation(ResendConfirmationEmailViewModel 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.FindByUnconfirmedEmailAddress(model.Email);
                if (user != null && !user.Confirmed)
                {
                    var confirmationUrl = Url.ConfirmationUrl(
                        MVC.Users.Confirm(), user.Username, user.EmailConfirmationToken, protocol: Request.Url.Scheme);
                    MessageService.SendNewAccountEmail(new MailAddress(user.UnconfirmedEmailAddress, user.Username), confirmationUrl);
                    return(RedirectToAction(MVC.Users.Thanks()));
                }
                ModelState.AddModelError("Email", "There was an issue resending your confirmation token.");
            }
            return(View(model));
        }
        protected override void SendNewAccountEmail(User account)
        {
            var confirmationUrl = Url.ConfirmOrganizationEmail(account.Username, account.EmailConfirmationToken, relativeUrl: false);

            MessageService.SendNewAccountEmail(account, confirmationUrl);
        }
Example #8
0
        protected override void SendNewAccountEmail(User account)
        {
            var confirmationUrl = Url.ConfirmEmail(account.Username, account.EmailConfirmationToken, relativeUrl: false);

            MessageService.SendNewAccountEmail(new MailAddress(account.UnconfirmedEmailAddress, account.Username), confirmationUrl);
        }
            public void WillSendEmailToNewUser()
            {
                var to = new MailAddress("*****@*****.**", "too");
                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.SendNewAccountEmail(to, "http://example.com/confirmation-token-url");

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal("[NuGet Gallery] Please verify your account.", message.Subject);
                Assert.Contains("http://example.com/confirmation-token-url", message.Body);
            }
Example #10
0
            public void WillSendEmailToNewUser()
            {
                var to = new MailAddress("*****@*****.**", "too");
                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.SendNewAccountEmail(to, "http://example.com/confirmation-token-url");

                Assert.Equal("*****@*****.**", message.To[0].Address);
                Assert.Equal(TestGalleryOwner.Address, message.From.Address);
                Assert.Equal("[Joe Shmoe] Please verify your account.", message.Subject);
                Assert.Contains("http://example.com/confirmation-token-url", message.Body);
            }