1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 23:52:50 -05:00

Refactor email attributes (#1458)

* Add StrictEmailAddress attribute

* Remove duplicate checks, use attributes instead

* Rename EmailAddressListAttribute
This commit is contained in:
Thomas Rittson
2021-07-16 08:01:51 +10:00
committed by GitHub
parent 752aa70924
commit 7abb053914
7 changed files with 43 additions and 23 deletions

View File

@ -2,36 +2,24 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Models.Table;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api.Public
{
public class MemberCreateRequestModel : MemberUpdateRequestModel, IValidatableObject
public class MemberCreateRequestModel : MemberUpdateRequestModel
{
/// <summary>
/// The member's email address.
/// </summary>
/// <example>jsmith@example.com</example>
[Required]
[EmailAddress]
[StringLength(256)]
[StrictEmailAddress]
public string Email { get; set; }
public override OrganizationUser ToOrganizationUser(OrganizationUser existingUser)
{
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 > 256)
{
yield return new ValidationResult($"Email is longer than 256 characters.",
new string[] { nameof(Email) });
}
}
}
}

View File

@ -1,12 +1,13 @@
using System;
using System.ComponentModel.DataAnnotations;
using Bit.Core.Utilities;
namespace Bit.Core.Models.Api
{
public class EmailRequestModel
{
[Required]
[EmailAddress]
[StrictEmailAddress]
[StringLength(256)]
public string NewEmail { get; set; }
[Required]

View File

@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations;
using Bit.Core.Enums;
using Bit.Core.Models.Business;
using Bit.Core.Models.Table;
using Bit.Core.Utilities;
using Newtonsoft.Json;
namespace Bit.Core.Models.Api
@ -13,7 +14,7 @@ namespace Bit.Core.Models.Api
[StringLength(50)]
public string Name { get; set; }
[Required]
[EmailAddress]
[StrictEmailAddress]
[StringLength(256)]
public string Email { get; set; }
[Required]

View File

@ -12,7 +12,7 @@ namespace Bit.Core.Models.Api
public class OrganizationUserInviteRequestModel
{
[Required]
[EmailAddressList]
[StrictEmailAddressList]
public IEnumerable<string> Emails { get; set; }
[Required]
public Enums.OrganizationUserType? Type { get; set; }

View File

@ -11,7 +11,7 @@ namespace Bit.Core.Models.Api
public class ProviderUserInviteRequestModel
{
[Required]
[EmailAddressList]
[StrictEmailAddressList]
public IEnumerable<string> Emails { get; set; }
[Required]
public ProviderUserType? Type { get; set; }