Exemple #1
0
        public virtual async Task <ActionResult> Index()
        {
            var user = await _queries.Execute(new UserViewBy(User.Identity.GetUserId <int>()));

            var emails = await _queries.Execute(new EmailAddressViewsBy(User.Identity.GetUserId <int>())
            {
                OrderBy = new Dictionary <Expression <Func <EmailAddressView, object> >, OrderByDirection>
                {
                    { x => x.IsPrimary, OrderByDirection.Descending },
                    { x => x.IsVerified, OrderByDirection.Descending },
                },
            });

            var model = new EmailAddressSettingsModel
            {
                UserView              = user,
                EmailAddresses        = emails.ToArray(),
                SendVerificationEmail = new SendVerificationEmail
                {
                    Purpose         = EmailVerificationPurpose.AddEmail,
                    SendFromUrl     = Url.AbsoluteAction(await MVC.UserEmails.Index()),
                    VerifyUrlFormat = Url.AbsoluteActionFormat(await MVC.UserEmailConfirm.Index("{0}", "{1}")),
                },
            };

            ViewBag.ActionUrl = Url.Action(MVC.UserEmails.Post());
            ViewBag.Purpose   = model.SendVerificationEmail.Purpose;
            return(View(MVC.Security.Views.User.EmailAddresses, model));
        }
Exemple #2
0
        public virtual async Task <ActionResult> Post(SendVerificationEmail command)
        {
            if (command == null || command.Purpose == EmailVerificationPurpose.Invalid)
            {
                return(View(MVC.Errors.Views.BadRequest));
            }

            if (!ModelState.IsValid)
            {
                var user = await _queries.Execute(new UserViewBy(User.Identity.GetUserId <int>()));

                var emails = await _queries.Execute(new EmailAddressViewsBy(User.Identity.GetUserId <int>())
                {
                    OrderBy = new Dictionary <Expression <Func <EmailAddressView, object> >, OrderByDirection>
                    {
                        { x => x.IsPrimary, OrderByDirection.Descending },
                        { x => x.IsVerified, OrderByDirection.Descending },
                    },
                });

                var model = new EmailAddressSettingsModel
                {
                    UserView              = user,
                    EmailAddresses        = emails.ToArray(),
                    SendVerificationEmail = command,
                };

                TempData.Alerts("**Could not send verification email due to error(s) below.**", AlertFlavor.Danger);
                ViewBag.ActionUrl = Url.Action(MVC.UserEmails.Post());
                return(View(MVC.Security.Views.User.EmailAddresses, model));
            }

            command.VerifyUrlFormat = Url.AbsoluteActionFormat(await MVC.UserEmailConfirm.Index("{0}", "{1}"));
            command.SendFromUrl     = Url.AbsoluteAction(await MVC.UserEmails.Index());
            await _commands.Execute(command);

            Session.VerifyEmailTickets(command.CreatedTicket);

            return(RedirectToAction(await MVC.UserEmailVerifySecret.Index(command.CreatedTicket)));
        }