RegisterInput.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections.Generic;
  2. using System.ComponentModel.DataAnnotations;
  3. using Abp.Auditing;
  4. using Abp.Authorization.Users;
  5. using Abp.Extensions;
  6. using YGNT.Exam.Validation;
  7. namespace YGNT.Exam.Authorization.Accounts.Dto
  8. {
  9. public class RegisterInput : IValidatableObject
  10. {
  11. [Required]
  12. [StringLength(AbpUserBase.MaxNameLength)]
  13. public string Name { get; set; }
  14. [Required]
  15. [StringLength(AbpUserBase.MaxSurnameLength)]
  16. public string Surname { get; set; }
  17. [Required]
  18. [StringLength(AbpUserBase.MaxUserNameLength)]
  19. public string UserName { get; set; }
  20. [Required]
  21. [EmailAddress]
  22. [StringLength(AbpUserBase.MaxEmailAddressLength)]
  23. public string EmailAddress { get; set; }
  24. [Required]
  25. [StringLength(AbpUserBase.MaxPlainPasswordLength)]
  26. [DisableAuditing]
  27. public string Password { get; set; }
  28. /// <summary>
  29. /// 验证码
  30. /// </summary>
  31. [DisableAuditing]
  32. public string CaptchaResponse { get; set; }
  33. public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
  34. {
  35. if (!UserName.IsNullOrEmpty())
  36. {
  37. if (!UserName.Equals(EmailAddress) && ValidationHelper.IsEmail(UserName))
  38. {
  39. yield return new ValidationResult("Username cannot be an email address unless it's the same as your email address!");
  40. }
  41. }
  42. }
  43. }
  44. }