mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
Improve email settings validation and UX (#3891)
This commit is contained in:
25
BTCPayServer/Validation/MailboxAddressAttribute.cs
Normal file
25
BTCPayServer/Validation/MailboxAddressAttribute.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BTCPayServer.Validation
|
||||
{
|
||||
/// <summary>
|
||||
/// Validate address in the format "Firstname Lastname <blah@example.com>" See rfc822
|
||||
/// </summary>
|
||||
public class MailboxAddressAttribute : ValidationAttribute
|
||||
{
|
||||
public MailboxAddressAttribute()
|
||||
{
|
||||
ErrorMessage = ErrorMessageConst;
|
||||
}
|
||||
public const string ErrorMessageConst = "Invalid mailbox address. Some valid examples are: 'test@example.com' or 'Firstname Lastname <test@example.com>'";
|
||||
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
||||
{
|
||||
if (value is null)
|
||||
return ValidationResult.Success;
|
||||
var str = value as string;
|
||||
if (MailboxAddressValidator.IsMailboxAddress(str))
|
||||
return ValidationResult.Success;
|
||||
return new ValidationResult(ErrorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user