Example #1
0
        public async Task <IActionResult> EmailConfirmation(string email)
        {
            _logger.LogInformation($"##Start## Email confirmation process for {email}");

            var user = await _userService.GetUserByEmail(email);

            var urlAction = new UrlActionContext {
                Action     = "ConfirmEmail",
                Controller = "UserRegistration",
                Values     = new { email, code = await _userService.GetEmailConfirmationCode(user) },
                Protocol   = Request.Scheme,
                Host       = Request.Host.ToString()
            };

            var userRegistrationEmail = new UserRegistrationEmailModel {
                DisplayName = $"{user.FirstName} {user.LastName}", Email = email, ActionUrl = Url.Action(urlAction)
            };

            var emailRenderService = HttpContext.RequestServices.GetService <IEmailTemplateRenderService>();

            var message = await emailRenderService.RenderTemplate("EmailTemplates/UserRegistrationEmail", userRegistrationEmail, Request.Host.ToString());

            try
            {
                _emailService.SendEmail(email, "Tic-Tac-Toe Email Confirmation", message).Wait();
            }
            catch (Exception) {
            }

            ViewBag.Email = email;

            return(View());
        }
        public async Task <IActionResult> EmailConfirmation(string email)
        {
            var user = await _userService.GetUserByEmail(email);

            var urlAction = new UrlActionContext
            {
                Action     = "ConfirmEmail",
                Controller = "UserRegistration",
                Values     = new {
                    email,
                    code = await _userService.GetEmailConfirmationCode(user)
                },
                Protocol = Request.Scheme,
                Host     = Request.Host.ToString()
            };

            var userRegistrationEmail = new UserRegistrationEmailModel
            {
                DisplayName = $"{user.FirstName} {user.LastName}",
                Email       = email,
                ActionUrl   = Url.Action(urlAction)
            };

            var emailRenderService = HttpContext.RequestServices.GetService <IEmailTemplateRenderService>();
            var message            = await emailRenderService.RenderTemplate("EmailTemplates/UserRegistrationEmail",
                                                                             userRegistrationEmail, Request.Host.ToString());

            try
            {
                _emailService.SendEmail(email, "Potwierdzenie adresu e-mail w grze Kółko i krzyżyk", message).Wait();
            }
            catch (Exception e)
            {
            }

            if (user?.IsEmailConfirmed == true)
            {
                return(RedirectToAction("Index", "GameInvitation",
                                        new { email }));
            }

            ViewBag.Email = email;
            return(View());

            //Symulowanie potwierdzenia adresu email
            //if(user?.IsEmailConfirmed == true)
            //{
            //    return RedirectToAction("Index", "GameInvitation", new
            //    {
            //        email
            //    });
            //}
            //ViewBag.Email = email;
            //return View();
        }
Example #3
0
        public async Task <IActionResult> EmailConfirmation(string email)
        {
            _logger.LogInformation($"##Start## Email confirmation process for {email}");

            var user = await _userService.GetUserByEmail(email);

            var urlAction = new UrlActionContext
            {
                Action     = "confirmEmail",
                Controller = "UserRegistration",
                Values     = new { email },
                Protocol   = Request.Scheme,
                Host       = Request.Host.ToString()
            };

            var userRegistrationEmail = new UserRegistrationEmailModel
            {
                DisplayName = $"{user.FirstName} {user.LastName}",
                Email       = email,
                ActionUrl   = Url.Action(urlAction)
            };

            var emailRenderService = HttpContext.RequestServices.GetService <IEmailTemplateRenderService>();
            var message            = await emailRenderService.RenderTemplate("EmailTemplates/UserRegistrationEmail", userRegistrationEmail, Request.Host.ToString());

            //var message = $"Thank you for your registration on our web site, please cick here to confirm your email " + $"{Url.Action(urlAction)}";
            try
            {
                _emailService.SendEmail(email, "Tic-Tac-Toe Email Confirmation", message).Wait();
            }
            catch (Exception e)
            {
            }

            if (user?.IsEmailConfirmed == true)
            {
                return(RedirectToAction("Index", "GameInvitation", new { email = email }));
            }

            ViewBag.Email = email;

            // This code is no longer needed here.
            // Communication Middleware is now going to simulate the effective email confirmation
            //user.IsEmailConfirmed = true;
            //user.EmailConfirmationDate = DateTime.Now;
            //await _userService.UpdateUser(user);

            return(View());
        }