mirror of
https://github.com/bitwarden/server.git
synced 2025-04-11 08:08:14 -05:00
further validate email for org users
This commit is contained in:
parent
2cf8b88fbb
commit
654eb5e15f
@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Core.Models.Api.Public
|
||||
{
|
||||
public class MemberCreateRequestModel : MemberUpdateRequestModel
|
||||
public class MemberCreateRequestModel : MemberUpdateRequestModel, IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// The member's email address.
|
||||
@ -18,5 +19,19 @@ namespace Bit.Core.Models.Api.Public
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(Email.Contains(" ") || Email.Contains("<"))
|
||||
{
|
||||
yield return new ValidationResult($"Email is not valid.",
|
||||
new string[] { nameof(Email) });
|
||||
}
|
||||
else if(Email.Length > 50)
|
||||
{
|
||||
yield return new ValidationResult($"Email is longer than 50 characters.",
|
||||
new string[] { nameof(Email) });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,13 +31,15 @@ namespace Bit.Core.Models.Api
|
||||
for(var i = 0; i < Emails.Count(); i++)
|
||||
{
|
||||
var email = Emails.ElementAt(i);
|
||||
if(!attr.IsValid(email))
|
||||
if(!attr.IsValid(email) || email.Contains(" ") || email.Contains("<"))
|
||||
{
|
||||
yield return new ValidationResult($"Email #{i + 1} is not valid.", new string[] { nameof(Emails) });
|
||||
yield return new ValidationResult($"Email #{i + 1} is not valid.",
|
||||
new string[] { nameof(Emails) });
|
||||
}
|
||||
else if(email.Length > 50)
|
||||
{
|
||||
yield return new ValidationResult($"Email #{i + 1} is longer than 50 characters.", new string[] { nameof(Emails) });
|
||||
yield return new ValidationResult($"Email #{i + 1} is longer than 50 characters.",
|
||||
new string[] { nameof(Emails) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user