| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.ComponentModel.DataAnnotations.Schema;
- using Abp;
- using Abp.Domain.Entities;
- using Abp.Domain.Entities.Auditing;
- using Abp.Extensions;
- using IwbZero.Authorization.Base.SystemInfo;
- namespace IwbZero.Authorization.Base.Users
- {
- /// <summary>
- /// Base class for user.
- /// </summary>
- [Table("Sys_Users")]
- public abstract class UserBase : FullAuditedEntity<long>, IMayHaveTenant, IPassivable
- {
- public const string AdminUserName = "admin";
- public const string SystemUserName = "system";
- public const string HostAdminName = "administrator";
- public const string HostSystemName = "systemHost";
- /// <summary>
- /// Maximum length of the <see cref="UserName"/> property.
- /// </summary>
- public const int MaxUserNameLength = 256;
- /// <summary>
- /// Maximum length of the <see cref="AccountNo"/> property.
- /// </summary>
- public const int MaxAccountNoLength = 100;
- /// <summary>
- /// Maximum length of the <see cref="ImagePath"/> property.
- /// </summary>
- public const int MaxImagePathLength = 1000;
- /// <summary>
- /// Maximum length of the <see cref="EmailAddress"/> property.
- /// </summary>
- public const int MaxEmailAddressLength = 256;
- /// <summary>
- /// Maximum length of the <see cref="Name"/> property.
- /// </summary>
- public const int MaxNameLength = 64;
- /// <summary>
- /// Maximum length of the <see cref="Surname"/> property.
- /// </summary>
- public const int MaxSurnameLength = 64;
- public const int MaxAvatarImagePathLength = 500;
- /// <summary>
- /// Maximum length of the <see cref="AuthenticationSource"/> property.
- /// </summary>
- public const int MaxAuthenticationSourceLength = 64;
- /// <summary>
- /// Maximum length of the <see cref="Password"/> property.
- /// </summary>
- public const int MaxPasswordLength = 128;
- /// <summary>
- /// Maximum length of the <see cref="Password"/> without hashed.
- /// </summary>
- public const int MaxPlainPasswordLength = 32;
- /// <summary>
- /// Maximum length of the <see cref="EmailConfirmationCode"/> property.
- /// </summary>
- public const int MaxEmailConfirmationCodeLength = 328;
- /// <summary>
- /// Maximum length of the <see cref="PasswordResetCode"/> property.
- /// </summary>
- public const int MaxPasswordResetCodeLength = 328;
- /// <summary>
- /// Maximum length of the <see cref="PhoneNumber"/> property.
- /// </summary>
- public const int MaxPhoneNumberLength = 32;
- /// <summary>
- /// Maximum length of the <see cref="SecurityStamp"/> property.
- /// </summary>
- public const int MaxSecurityStampLength = 128;
- /// <summary>
- /// Authorization source name.
- /// It's set to external authentication source name if created by an external source.
- /// Default: null.
- /// </summary>
- [StringLength(MaxAuthenticationSourceLength)]
- public virtual string AuthenticationSource { get; set; }
- /// <summary>
- /// User name.
- /// User name must be unique for it's tenant.
- /// </summary>
- [Required]
- [StringLength(MaxUserNameLength)]
- [Index]
- public virtual string UserName { get; set; }
- [Index]
- public virtual int UserType { get; set; }
- [Index]
- public virtual int? AccountType { get; set; }
- [StringLength(MaxAccountNoLength)]
- public virtual string AccountNo { get; set; }
- [StringLength(MaxImagePathLength)]
- public virtual string ImagePath { get; set; }
- /// <summary>
- /// Tenant Id of this user.
- /// </summary>
- public virtual int? TenantId { get; set; }
- /// <summary>
- /// Email address of the user.
- /// Email address must be unique for it's tenant.
- /// </summary>
- [StringLength(MaxEmailAddressLength)]
- [Index]
- public virtual string EmailAddress { get; set; }
- /// <summary>
- /// Name of the user.
- /// </summary>
- [Required]
- [StringLength(MaxNameLength)]
- public virtual string Name { get; set; }
- /// <summary>
- /// Surname of the user.
- /// </summary>
- [StringLength(MaxSurnameLength)]
- public virtual string Surname { get; set; }
- /// <summary>
- /// Surname of the user.
- /// </summary>
- [StringLength(MaxAvatarImagePathLength)]
- public virtual string AvatarImagePath { get; set; }
- /// <summary>
- /// Return full name (Name Surname )
- /// </summary>
- [NotMapped]
- public virtual string FullName => Name + " " + Surname;
- /// <summary>
- /// Password of the user.
- /// </summary>
- [Required]
- [StringLength(MaxPasswordLength)]
- public virtual string Password { get; set; }
- /// <summary>
- /// Confirmation code for email.
- /// </summary>
- [StringLength(MaxEmailConfirmationCodeLength)]
- public virtual string EmailConfirmationCode { get; set; }
- /// <summary>
- /// Reset code for password.
- /// It's not valid if it's null.
- /// It's for one usage and must be set to null after reset.
- /// </summary>
- [StringLength(MaxPasswordResetCodeLength)]
- public virtual string PasswordResetCode { get; set; }
- /// <summary>
- /// Lockout end date.
- /// </summary>
- public virtual DateTime? LockoutEndDateUtc { get; set; }
- /// <summary>
- /// Gets or sets the access failed count.
- /// </summary>
- public virtual int AccessFailedCount { get; set; }
- /// <summary>
- /// Gets or sets the lockout enabled.
- /// </summary>
- public virtual bool IsLockoutEnabled { get; set; }
- /// <summary>
- /// Gets or sets the phone number.
- /// </summary>
- [StringLength(MaxPhoneNumberLength)]
- [Index]
- public virtual string PhoneNumber { get; set; }
- /// <summary>
- /// Is the <see cref="PhoneNumber"/> confirmed.
- /// </summary>
- public virtual bool IsPhoneNumberConfirmed { get; set; }
- /// <summary>
- /// Gets or sets the security stamp.
- /// </summary>
- [StringLength(MaxSecurityStampLength)]
- public virtual string SecurityStamp { get; set; }
- /// <summary>
- /// Is two factor auth enabled.
- /// </summary>
- public virtual bool IsTwoFactorEnabled { get; set; }
- /// <summary>
- /// Login definitions for this user.
- /// </summary>
- [ForeignKey("UserId")]
- public virtual ICollection<UserLogin> Logins { get; set; }
- /// <summary>
- /// Roles of this user.
- /// </summary>
- [ForeignKey("UserId")]
- public virtual ICollection<UserRole> Roles { get; set; }
- /// <summary>
- /// Claims of this user.
- /// </summary>
- [ForeignKey("UserId")]
- public virtual ICollection<UserClaim> Claims { get; set; }
- /// <summary>
- /// Settings for this user.
- /// </summary>
- [ForeignKey("UserId")]
- public virtual ICollection<SysSetting> Settings { get; set; }
- /// <summary>
- /// Is the <see cref="UserBase.EmailAddress"/> confirmed.
- /// </summary>
- public virtual bool IsEmailConfirmed { get; set; }
- /// <summary>
- /// Is this user active?
- /// If as user is not active, he/she can not use the application.
- /// </summary>
- public virtual bool IsActive { get; set; }
- protected UserBase()
- {
- // ReSharper disable VirtualMemberCallInConstructor
- IsActive = true;
- // ReSharper disable VirtualMemberCallInConstructor
- SecurityStamp = SequentialGuidGenerator.Instance.Create().ToString();
- }
- public virtual void SetNewPasswordResetCode()
- {
- PasswordResetCode = Guid.NewGuid().ToString("N").Truncate(MaxPasswordResetCodeLength);
- }
- public virtual void SetNewEmailConfirmationCode()
- {
- EmailConfirmationCode = Guid.NewGuid().ToString("N").Truncate(MaxEmailConfirmationCodeLength);
- }
- /// <summary>
- /// Creates <see cref="UserIdentifier"/> from this User.
- /// </summary>
- /// <returns></returns>
- public virtual UserIdentifier ToUserIdentifier()
- {
- return new UserIdentifier(TenantId, Id);
- }
- public override string ToString()
- {
- return $"[User {Id}] {UserName}";
- }
- }
- }
|