34
34
using RecaptchaV2 . NET ;
35
35
using DotNetNuke . Security ;
36
36
using Satrabel . OpenContent . Components ;
37
+ using Satrabel . OpenContent . Components . Form ;
37
38
using Satrabel . OpenContent . Components . Logging ;
38
39
39
40
#endregion
@@ -63,8 +64,11 @@ public HttpResponseMessage Form()
63
64
string templateFilename = HostingEnvironment . MapPath ( "~/" + template ) ;
64
65
string schemaFilename = Path . GetDirectoryName ( templateFilename ) + "\\ " + "schema.json" ;
65
66
66
- JObject schemaJson = JsonUtils . GetJsonFromFile ( schemaFilename ) ;
67
- json [ "schema" ] = schemaJson ;
67
+ json [ "schema" ] = JsonUtils . GetJsonFromFile ( schemaFilename ) ;
68
+ if ( UserInfo . UserID > 0 && json [ "schema" ] is JObject )
69
+ {
70
+ json [ "schema" ] = FormUtils . InitFields ( json [ "schema" ] as JObject , UserInfo ) ;
71
+ }
68
72
69
73
// default options
70
74
string optionsFilename = Path . GetDirectoryName ( templateFilename ) + "\\ " + "options.json" ;
@@ -99,6 +103,8 @@ public HttpResponseMessage Form()
99
103
json [ "view" ] = viewJson ;
100
104
}
101
105
}
106
+
107
+
102
108
}
103
109
return Request . CreateResponse ( HttpStatusCode . OK , json ) ;
104
110
}
@@ -188,10 +194,40 @@ public HttpResponseMessage Submit(JObject form)
188
194
form . Remove ( "recaptcha" ) ;
189
195
}
190
196
191
- data = OpenFormUtils . GenerateFormData ( form . ToString ( ) , out formData ) ;
197
+
198
+ string template = ( string ) ActiveModule . ModuleSettings [ "template" ] ;
199
+ string templateFilename = HostingEnvironment . MapPath ( "~/" + template ) ;
200
+ string schemaFilename = Path . GetDirectoryName ( templateFilename ) + "\\ " + "schema.json" ;
201
+ JObject schemaJson = JsonUtils . GetJsonFromFile ( schemaFilename ) ;
202
+ //form["schema"] = schemaJson;
203
+ // default options
204
+ string optionsFilename = Path . GetDirectoryName ( templateFilename ) + "\\ " + "options.json" ;
205
+ JObject optionsJson = null ;
206
+ if ( File . Exists ( optionsFilename ) )
207
+ {
208
+ string fileContent = File . ReadAllText ( optionsFilename ) ;
209
+ if ( ! string . IsNullOrWhiteSpace ( fileContent ) )
210
+ {
211
+ optionsJson = JObject . Parse ( fileContent ) ;
212
+ //form["options"] = optionsJson;
213
+ }
214
+ }
215
+ // language options
216
+ optionsFilename = Path . GetDirectoryName ( templateFilename ) + "\\ " + "options." + DnnUtils . GetCurrentCultureCode ( ) + ".json" ;
217
+ if ( File . Exists ( optionsFilename ) )
218
+ {
219
+ string fileContent = File . ReadAllText ( optionsFilename ) ;
220
+ if ( ! string . IsNullOrWhiteSpace ( fileContent ) )
221
+ {
222
+ optionsJson = JObject . Parse ( fileContent ) ;
223
+ //form["options"] = optionsJson;
224
+ }
225
+ }
226
+ var enhancedForm = form . DeepClone ( ) as JObject ;
227
+ OpenFormUtils . ResolveLabels ( enhancedForm , schemaJson , optionsJson ) ;
228
+ data = OpenFormUtils . GenerateFormData ( enhancedForm . ToString ( ) , out formData ) ;
192
229
}
193
230
194
-
195
231
if ( settings != null && settings . Notifications != null )
196
232
{
197
233
foreach ( var notification in settings . Notifications )
@@ -208,6 +244,7 @@ public HttpResponseMessage Submit(JObject form)
208
244
string body = formData ;
209
245
if ( ! string . IsNullOrEmpty ( notification . EmailBody ) )
210
246
{
247
+
211
248
body = hbs . Execute ( notification . EmailBody , data ) ;
212
249
}
213
250
@@ -287,19 +324,22 @@ public HttpResponseMessage UpdateBuilder(JObject json)
287
324
{
288
325
string templateFilename = HostingEnvironment . MapPath ( "~/" + Template ) ;
289
326
string dataDirectory = Path . GetDirectoryName ( templateFilename ) + "\\ " ;
290
- if ( json [ "data" ] != null && json [ "schema" ] != null && json [ "options" ] != null )
327
+ if ( json [ "data" ] != null && json [ "schema" ] != null && json [ "options" ] != null && json [ "view" ] != null )
291
328
{
292
329
var schema = json [ "schema" ] . ToString ( ) ;
293
330
var options = json [ "options" ] . ToString ( ) ;
331
+ var view = json [ "view" ] . ToString ( ) ;
294
332
var data = json [ "data" ] . ToString ( ) ;
295
333
var datafile = dataDirectory + "builder.json" ;
296
334
var schemafile = dataDirectory + "schema.json" ;
297
335
var optionsfile = dataDirectory + "options.json" ;
336
+ var viewfile = dataDirectory + "view.json" ;
298
337
try
299
338
{
300
339
File . WriteAllText ( datafile , data ) ;
301
340
File . WriteAllText ( schemafile , schema ) ;
302
341
File . WriteAllText ( optionsfile , options ) ;
342
+ File . WriteAllText ( viewfile , view ) ;
303
343
}
304
344
catch ( Exception ex )
305
345
{
@@ -334,12 +374,14 @@ private MailAddress GenerateMailAddress(string TypeOfAddress, string Email, stri
334
374
335
375
if ( TypeOfAddress == "host" )
336
376
{
337
- adr = new MailAddress ( Host . HostEmail , Host . HostTitle ) ;
377
+ if ( Validate . IsValidEmail ( Host . HostEmail ) )
378
+ adr = new MailAddress ( Host . HostEmail , Host . HostTitle ) ;
338
379
}
339
380
else if ( TypeOfAddress == "admin" )
340
381
{
341
382
var user = UserController . GetUserById ( PortalSettings . PortalId , PortalSettings . AdministratorId ) ;
342
- adr = new MailAddress ( user . Email , user . DisplayName ) ;
383
+ if ( Validate . IsValidEmail ( user . Email ) )
384
+ adr = new MailAddress ( user . Email , user . DisplayName ) ;
343
385
}
344
386
else if ( TypeOfAddress == "form" )
345
387
{
@@ -348,19 +390,21 @@ private MailAddress GenerateMailAddress(string TypeOfAddress, string Email, stri
348
390
if ( string . IsNullOrEmpty ( FormEmailField ) )
349
391
FormEmailField = "email" ;
350
392
351
- string FormEmail = GetProperty ( form , FormEmailField ) ;
352
- string FormName = GetProperty ( form , FormNameField ) ;
353
- adr = new MailAddress ( FormEmail , FormName ) ;
393
+ string formEmail = GetProperty ( form , FormEmailField ) ;
394
+ string formName = GetProperty ( form , FormNameField ) ;
395
+ if ( Validate . IsValidEmail ( formEmail ) )
396
+ adr = new MailAddress ( formEmail , formName ) ;
354
397
}
355
398
else if ( TypeOfAddress == "custom" )
356
399
{
357
- adr = new MailAddress ( Email , Name ) ;
400
+ if ( Validate . IsValidEmail ( Email ) )
401
+ adr = new MailAddress ( Email , Name ) ;
358
402
}
359
403
else if ( TypeOfAddress == "current" )
360
404
{
361
405
if ( UserInfo == null )
362
406
throw new Exception ( string . Format ( "Can't send email to current user, as there is no current user. Parameters were TypeOfAddress: [{0}], Email: [{1}], Name: [{2}], FormEmailField: [{3}], FormNameField: [{4}], FormNameField: [{5}]" , TypeOfAddress , Email , Name , FormEmailField , FormNameField , form ) ) ;
363
- if ( string . IsNullOrEmpty ( UserInfo . Email ) )
407
+ if ( Validate . IsValidEmail ( UserInfo . Email ) )
364
408
throw new Exception ( string . Format ( "Can't send email to current user, as email address of current user is unknown. Parameters were TypeOfAddress: [{0}], Email: [{1}], Name: [{2}], FormEmailField: [{3}], FormNameField: [{4}], FormNameField: [{5}]" , TypeOfAddress , Email , Name , FormEmailField , FormNameField , form ) ) ;
365
409
366
410
adr = new MailAddress ( UserInfo . Email , UserInfo . DisplayName ) ;
0 commit comments