public IAccountVerificationTemplateBuilderContext CreateAccountVerificationContext(UserSummary user, string token)
        {
            var context = new AccountVerificationTemplateBuilderContext()
            {
                User  = user,
                Token = token,
                DefaultTemplateFactory = AccountVerificationTemplateFactory
            };

            // Can be null to allow a custom IDefaultMailTemplateBuilder implementation to the path explicitly
            var options = _userAreaDefinitionRepository.GetOptionsByCode(user.UserArea.UserAreaCode).AccountVerification;

            if (options.VerificationUrlBase != null)
            {
                context.VerificationUrlPath = _authorizedTaskTokenUrlHelper.MakeUrl(options.VerificationUrlBase, token);
            }

            return(context);
        }
        private async Task <AccountVerificationMailTemplate> AccountVerificationTemplateFactory(AccountVerificationTemplateBuilderContext context)
        {
            var userAreaDefinition = _userAreaDefinitionRepository.GetRequiredByCode(context.User.UserArea.UserAreaCode);

            if (userAreaDefinition is CofoundryAdminUserArea)
            {
                // Admin user area does not implement account verification
                throw new NotImplementedException();
            }

            if (context.VerificationUrlPath == null || !Uri.IsWellFormedUriString(context.VerificationUrlPath, UriKind.Relative))
            {
                // The VerificationUrlPath setting isn't required in config because the feature may not be used, or may
                // be manually constructed in a custom IDefaultMailTemplateBuilder implementation. However it should be
                // supplied at this point for our default builder.
                var options = _userAreaDefinitionRepository.GetOptionsByCode(userAreaDefinition.UserAreaCode).AccountVerification;
                if (string.IsNullOrEmpty(options.VerificationUrlBase))
                {
                    throw new InvalidOperationException($"To use the account verification feature you must configure the {nameof(AccountRecoveryOptions.RecoveryUrlBase)} setting by implementing {nameof(IUserAreaDefinition)}.{nameof(IUserAreaDefinition.ConfigureOptions)}.");
                }

                throw new InvalidOperationException($"{nameof(AccountRecoveryTemplateBuilderContext)}.{nameof(context.VerificationUrlPath)} should be a valid relative uri.");
            }

            var template = new AccountVerificationMailTemplate();

            template.VerificationUrl = _siteUrlResolver.MakeAbsolute(context.VerificationUrlPath);
            await _userMailTemplateInitializer.Initialize(context.User, template);

            return(template);
        }