Skip to content

Commit 965e8e6

Browse files
authored
Merge pull request #25 from cloudscribe/feature/19
#19 contact form notification email settings
2 parents 3bacc69 + 48629ef commit 965e8e6

5 files changed

Lines changed: 33 additions & 43 deletions

File tree

src/cloudscribe.SimpleContactForm.CoreIntegration/SiteContactFormResolver.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ IOptions<ContactFormSettings> contactFormAccessor
2121
public override async Task<ContactFormSettings> GetCurrentContactForm()
2222
{
2323
var form = await base.GetCurrentContactForm();
24-
if (!string.IsNullOrWhiteSpace(_currentSite.AccountApprovalEmailCsv))
24+
25+
// if we require account approval and we don't have any contact form recipients in config,
26+
// use the former recipient
27+
if (!string.IsNullOrWhiteSpace(_currentSite.AccountApprovalEmailCsv) && string.IsNullOrWhiteSpace(form.NotificationEmailCsv))
2528
{
2629
var newForm = new ContactFormSettings
2730
{
@@ -36,6 +39,5 @@ public override async Task<ContactFormSettings> GetCurrentContactForm()
3639

3740
return form;
3841
}
39-
4042
}
4143
}

src/cloudscribe.SimpleContactForm.CoreIntegration/cloudscribe.SimpleContactForm.CoreIntegration.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>Integration library for usingcloudscribe SimpleContactForm with cloudscribe.Core</Description>
5-
<Version>6.0.0</Version>
5+
<Version>6.0.1</Version>
66
<TargetFramework>net6.0</TargetFramework>
77
<Authors>Joe Audette</Authors>
88
<PackageTags>cloudscribe;contact form</PackageTags>
@@ -12,7 +12,11 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<None Include="icon.png" Pack="true" PackagePath="\"/>
15+
<Compile Remove="SiteContactFormService.cs" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<None Include="icon.png" Pack="true" PackagePath="\" />
1620
</ItemGroup>
1721

1822
<ItemGroup>

src/cloudscribe.SimpleContactForm/Components/ContactFormService.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Last Modified: 2018-03-18
66
//
77

8+
using cloudscribe.Email;
89
using cloudscribe.SimpleContactForm.Models;
910
using cloudscribe.SimpleContactForm.ViewModels;
1011
using cloudscribe.Web.Common.Models;
@@ -19,22 +20,25 @@ public class ContactFormService
1920
{
2021
public ContactFormService(
2122
IEnumerable<IProcessContactForm> messageProcessors,
22-
IContactFormResolver contactFormResolver,
23-
IRecaptchaKeysProvider recaptchaKeysProvider,
24-
ILogger<ContactFormService> logger
23+
IContactFormResolver contactFormResolver,
24+
IRecaptchaKeysProvider recaptchaKeysProvider,
25+
ILogger<ContactFormService> logger,
26+
IEmailSenderResolver emailSenderResolver
2527
)
2628
{
2729
_contactFormResolver = contactFormResolver;
28-
_recaptchaKeys = recaptchaKeysProvider;
29-
_messageProcessors = messageProcessors;
30-
_log = logger;
31-
}
30+
_recaptchaKeys = recaptchaKeysProvider;
31+
_messageProcessors = messageProcessors;
32+
_log = logger;
33+
_emailSenderResolver = emailSenderResolver;
34+
}
3235

33-
private IContactFormResolver _contactFormResolver;
34-
private IRecaptchaKeysProvider _recaptchaKeys;
35-
private ContactFormSettings _form = null;
36+
private IContactFormResolver _contactFormResolver;
37+
private IRecaptchaKeysProvider _recaptchaKeys;
38+
private ContactFormSettings _form = null;
3639
private IEnumerable<IProcessContactForm> _messageProcessors;
37-
private ILogger _log;
40+
private ILogger _log;
41+
private IEmailSenderResolver _emailSenderResolver;
3842

3943
public async Task<ContactFormSettings> GetFormSettings()
4044
{
@@ -46,13 +50,15 @@ public async Task<ContactFormSettings> GetFormSettings()
4650
return _form;
4751
}
4852

49-
public async Task<bool> IsConfigured()
53+
public virtual async Task<bool> IsConfigured()
5054
{
5155
var form = await GetFormSettings().ConfigureAwait(false);
52-
if(string.IsNullOrEmpty(form.NotificationEmailCsv)) { return false; }
56+
// if(string.IsNullOrEmpty(form.NotificationEmailCsv)) { return false; }
57+
58+
var sender = await _emailSenderResolver.GetEmailSender();
59+
if(sender == null) { return false; }
5360

54-
//var smtpSettings = await smtpOptionsProvider.GetSmtpOptions().ConfigureAwait(false);
55-
//if (string.IsNullOrEmpty(smtpSettings.Server)) { return false; }
61+
if (!await sender.IsConfigured()) { return false; }
5662

5763
return true;
5864
}

src/cloudscribe.SimpleContactForm/StartupExtensions.cs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,19 @@ public static IServiceCollection AddCloudscribeSimpleContactForm(
2121
IConfiguration configuration,
2222
bool includeDefaultMessageProcessor = true)
2323
{
24-
2524

2625
services.Configure<RecaptchaKeys>(configuration.GetSection("RecaptchaKeys"));
2726
services.Configure<ContactFormMessageOptions>(configuration.GetSection("ContactFormMessageOptions"));
2827
services.Configure<ContactFormSettings>(configuration.GetSection("ContactFormSettings"));
2928

30-
3129

3230
services.TryAddScoped<IRecaptchaKeysProvider, ConfigRecaptchaKeysProvider>();
3331
services.AddScoped<ContactFormService, ContactFormService>();
3432

3533
services.TryAddScoped<IContactFormResolver, ConfigContactFormResolver>();
3634
services.TryAddScoped<ITenantResolver, NullTenantResolver>();
3735
services.TryAddScoped<IPrePopulateContactForm, NotImplementedContactFromPopulator>();
36+
3837
// pass in false if you want to implement custom logic for notification
3938
// instead of the built in logic
4039
// there can be multiple registered IProcessMessages implementations and all of them will be invoked
@@ -44,31 +43,10 @@ public static IServiceCollection AddCloudscribeSimpleContactForm(
4443
{
4544
services.AddScoped<IProcessContactForm, ContactFormProcessor>();
4645
}
47-
4846

4947

5048
return services;
5149
}
5250

53-
//[Obsolete("AddEmbeddedViewsForCloudscribeSimpleContactForm is deprecated, please use AddCloudscribeSimpleContactFormViews instead.")]
54-
//public static RazorViewEngineOptions AddEmbeddedViewsForCloudscribeSimpleContactForm(this RazorViewEngineOptions options)
55-
//{
56-
// options.FileProviders.Add(new EmbeddedFileProvider(
57-
// typeof(ContactFormService).GetTypeInfo().Assembly,
58-
// "cloudscribe.SimpleContactForm"
59-
// ));
60-
61-
// return options;
62-
//}
63-
64-
//public static RazorViewEngineOptions AddCloudscribeSimpleContactFormViews(this RazorViewEngineOptions options)
65-
//{
66-
// options.FileProviders.Add(new EmbeddedFileProvider(
67-
// typeof(ContactFormService).GetTypeInfo().Assembly,
68-
// "cloudscribe.SimpleContactForm"
69-
// ));
70-
71-
// return options;
72-
//}
7351
}
7452
}

src/cloudscribe.SimpleContactForm/cloudscribe.SimpleContactForm.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>A simple contact form for ASP.NET Core</Description>
5-
<Version>6.0.0</Version>
5+
<Version>6.0.1</Version>
66
<TargetFramework>net6.0</TargetFramework>
77
<Authors>Joe Audette</Authors>
88
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>

0 commit comments

Comments
 (0)