public IActionResult ResendVerificationEmailPost(long id, AdminResendVerificationEmailViewModel viewModel)
        {
            User user = dataRepository.Get <User>(id);

            viewModel.User = user;

            if (user.EmailVerifiedDate != null)
            {
                viewModel.AddErrorFor(
                    m => m.OtherErrorMessagePlaceholder,
                    "This user's email address has already been verified");
                return(View("ResendVerificationEmail", viewModel));
            }

            viewModel.ParseAndValidateParameters(Request, m => m.Reason);
            if (viewModel.HasAnyErrors())
            {
                return(View("ResendVerificationEmail", viewModel));
            }

            auditLogger.AuditChangeToUser(
                AuditedAction.AdminResendVerificationEmail,
                user,
                new
            {
                viewModel.Reason
            },
                User);

            string verificationCode = Guid.NewGuid().ToString("N");
            string verificationUrl  = Url.Action(
                "VerifyEmail",
                "AccountCreation",
                new { code = verificationCode },
                "https");

            emailSendingService.SendAccountVerificationEmail(user.EmailAddress, verificationUrl);
            user.EmailVerifyHash     = verificationCode;
            user.EmailVerifySendDate = VirtualDateTime.Now;

            dataRepository.SaveChanges();

            return(View("VerificationEmailSent", user));
        }
Esempio n. 2
0
        private void GenerateAndSendAccountVerificationEmail(User user)
        {
            string verificationCode = Guid.NewGuid().ToString("N");
            string verificationUrl  = Url.Action(
                "VerifyEmail",
                "AccountCreation",
                new { code = verificationCode },
                "https");

            try
            {
                emailSendingService.SendAccountVerificationEmail(user.EmailAddress, verificationUrl);
                user.EmailVerifyHash     = verificationCode;
                user.EmailVerifySendDate = VirtualDateTime.Now;
            }
            catch
            {
                // help user resend email
                throw new Exception("Failed to send verification email. Please try again");
            }
        }