[feature] 建立鉴权项目结构
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Data;
|
||||
using System.Security.Claims;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using SiteManagementSystem_SoftwareEngineering_.Model;
|
||||
using SiteManagementSystem_SoftwareEngineering_.Service;
|
||||
|
||||
namespace SiteManagementSystem_SoftwareEngineering_.Entity
|
||||
{
|
||||
public class User : ICloneable
|
||||
{
|
||||
public User() { }
|
||||
|
||||
public User(UserModel model)
|
||||
{
|
||||
Name = model.Name;
|
||||
RoleName = model.RoleName;
|
||||
Secret = model.Secret;
|
||||
}
|
||||
|
||||
public User(User user)
|
||||
{
|
||||
Id = user.Id;
|
||||
RoleName = user.RoleName;
|
||||
Role = user.Role;
|
||||
Name = user.Name;
|
||||
Secret = user.Secret;
|
||||
HashSecret = user.HashSecret;
|
||||
}
|
||||
|
||||
[Key]
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
[NotMapped]
|
||||
public string RoleName { get; set; } = null!;
|
||||
public IdentityPolicyNames Role
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Enum.TryParse<IdentityPolicyNames>(RoleName, out var result))
|
||||
return result;
|
||||
else
|
||||
return IdentityPolicyNames.NotSupport;
|
||||
}
|
||||
set => RoleName = Enum.GetName(value)!;
|
||||
}
|
||||
|
||||
[StringLength(50)]
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
[NotMapped]
|
||||
public string Secret { get; set; } = null!;
|
||||
|
||||
public string HashSecret { get; set; } = null!;
|
||||
|
||||
public object Clone() => new User(this);
|
||||
|
||||
public IEnumerable<Claim> GetUserClaims() =>
|
||||
[new Claim(nameof(Name), Name), new Claim(ClaimTypes.Role, RoleName)];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user