Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/WebApp/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"CopySubmitterEmailOnSubmission": "true"
},
"SmtpOptions": {
"Server": "",
"Server": "www.test.com",
"Port": "25",
"User": "",
"Password": "",
"User": "test",
"Password": "test",
"UseSsl": "false",
"RequiresAuthentication": "false",
"DefaultEmailFromAddress": "",
"DefaultEmailFromAlias": ""
"DefaultEmailFromAddress": "test@test.com",
"DefaultEmailFromAlias": "test"
},
"RecaptchaKeys": {
"PublicKey": "",
Expand Down
22 changes: 22 additions & 0 deletions src/cloudscribe.SimpleContactForm/Components/NoUrlAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;

public class NoUrlAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (value != null)
{
var stringToValidate = value.ToString();
var urlPattern = @"((http|https|ftp|file)://)?([\w-]+(\.[\w-]+)+)(/[\w- ./?%&=]*)?";
var emailPattern = @"^[^@\s]+@[^@\s]+\.[^@\s]+$";

if (Regex.IsMatch(stringToValidate, urlPattern) && !Regex.IsMatch(stringToValidate, emailPattern, RegexOptions.IgnoreCase))
{
return new ValidationResult("URLs are not allowed.");
}
}

return ValidationResult.Success;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ public class MessageViewModel
public string FormId { get; set; }

[Required(ErrorMessage = "The Name field is required.")]
[NoUrl(ErrorMessage = "URLs are not allowed in the Name field.")]
public string Name { get; set; }

[Required(ErrorMessage = "The Email field is required.")]
[EmailAddress(ErrorMessage ="The Email field is not a valid email address.")]
[NoUrl(ErrorMessage = "URLs are not allowed in the Email field.")]
public string Email { get; set; }

[NoUrl(ErrorMessage = "URLs are not allowed in the Subject field.")]
public string Subject { get; set; }

[Required(ErrorMessage = "The Message field is required.")]
[NoUrl(ErrorMessage = "URLs are not allowed in the Message field.")]
public string Message { get; set; }

public string RecaptchaPublicKey { get; set; } = string.Empty;
Expand Down