Files
Umbraco-CMS/src/Umbraco.Core/Models/ContentEditing/UserInvite.cs

42 lines
1.5 KiB
C#
Raw Normal View History

2017-09-23 10:08:18 +02:00
using System.Collections.Generic;
2017-09-12 16:22:16 +02:00
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;
2020-02-17 09:15:48 +01:00
using Umbraco.Composing;
2017-09-19 15:51:47 +02:00
using Umbraco.Core;
2017-09-12 16:22:16 +02:00
namespace Umbraco.Web.Models.ContentEditing
{
/// <summary>
/// Represents the data used to invite a user
/// </summary>
[DataContract(Name = "user", Namespace = "")]
public class UserInvite : EntityBasic, IValidatableObject
{
[DataMember(Name = "userGroups")]
[Required]
public IEnumerable<string> UserGroups { get; set; }
[DataMember(Name = "email", IsRequired = true)]
[Required]
[EmailAddress]
2017-09-19 15:51:47 +02:00
public string Email { get; set; }
2017-09-23 10:08:18 +02:00
[DataMember(Name = "username")]
2017-09-19 15:51:47 +02:00
public string Username { get; set; }
2017-09-12 16:22:16 +02:00
[DataMember(Name = "message")]
public string Message { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (UserGroups.Any() == false)
2020-01-20 15:20:21 +01:00
yield return new ValidationResult("A user must be assigned to at least one group", new[] { nameof(UserGroups) });
2017-09-19 15:51:47 +02:00
2020-08-25 12:30:43 +02:00
// TODO: this will need another way of retrieving this setting if and when Configs are removed from Current.
2020-09-08 13:03:43 +02:00
if (Current.SecuritySettings.UsernameIsEmail == false && Username.IsNullOrWhiteSpace())
2020-01-20 15:20:21 +01:00
yield return new ValidationResult("A username cannot be empty", new[] { nameof(Username) });
2017-09-12 16:22:16 +02:00
}
}
2017-09-23 10:08:18 +02:00
}