1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-21 21:15:10 -05:00

further validate email for org users

This commit is contained in:
Kyle Spearrin 2019-11-25 10:57:55 -05:00
parent 2cf8b88fbb
commit 654eb5e15f
2 changed files with 21 additions and 4 deletions

View File

@ -1,10 +1,11 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Bit.Core.Models.Table; using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api.Public namespace Bit.Core.Models.Api.Public
{ {
public class MemberCreateRequestModel : MemberUpdateRequestModel public class MemberCreateRequestModel : MemberUpdateRequestModel, IValidatableObject
{ {
/// <summary> /// <summary>
/// The member's email address. /// The member's email address.
@ -18,5 +19,19 @@ namespace Bit.Core.Models.Api.Public
{ {
throw new NotImplementedException(); 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) });
}
}
} }
} }

View File

@ -31,13 +31,15 @@ namespace Bit.Core.Models.Api
for(var i = 0; i < Emails.Count(); i++) for(var i = 0; i < Emails.Count(); i++)
{ {
var email = Emails.ElementAt(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) 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) });
} }
} }
} }