|
|
|
@ -33,7 +33,7 @@ public class AspNetUser : IUser
|
|
|
|
|
if (_userId == null)
|
|
|
|
|
{
|
|
|
|
|
var claimValue = GetClaimValueByType("jti").FirstOrDefault();
|
|
|
|
|
_userId = claimValue != null ? claimValue.ObjToString() : "1288018625843826688";
|
|
|
|
|
_userId = claimValue != null ? claimValue.ObjToString() : GetUserId().ToString();
|
|
|
|
|
}
|
|
|
|
|
return _userId;
|
|
|
|
|
}
|
|
|
|
@ -82,19 +82,19 @@ public class AspNetUser : IUser
|
|
|
|
|
var token = GetToken();
|
|
|
|
|
if (string.IsNullOrEmpty(token))
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var jwtHandler = new JwtSecurityTokenHandler();
|
|
|
|
|
if (!jwtHandler.CanReadToken(token))
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JwtSecurityToken jwtToken = jwtHandler.ReadJwtToken(token);
|
|
|
|
|
var tenantIdClaim = jwtToken.Claims.FirstOrDefault(x => x.Type == "TenantId");
|
|
|
|
|
|
|
|
|
|
return tenantIdClaim != null ? Convert.ToInt64(tenantIdClaim.Value) : 0;
|
|
|
|
|
return tenantIdClaim != null ? Convert.ToInt64(tenantIdClaim.Value) : 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//public long GetTenantId()
|
|
|
|
@ -119,12 +119,49 @@ public class AspNetUser : IUser
|
|
|
|
|
|
|
|
|
|
public long GetOrgId()
|
|
|
|
|
{
|
|
|
|
|
if (_orgId == 0)
|
|
|
|
|
//if (_orgId == 0)
|
|
|
|
|
//{
|
|
|
|
|
// var claimValue = GetClaimValueByType("OrgId").FirstOrDefault();
|
|
|
|
|
// _orgId = claimValue != null ? long.Parse(claimValue) : 0;
|
|
|
|
|
//}
|
|
|
|
|
//return _orgId;
|
|
|
|
|
|
|
|
|
|
var token = GetToken();
|
|
|
|
|
if (string.IsNullOrEmpty(token))
|
|
|
|
|
{
|
|
|
|
|
return 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var jwtHandler = new JwtSecurityTokenHandler();
|
|
|
|
|
if (!jwtHandler.CanReadToken(token))
|
|
|
|
|
{
|
|
|
|
|
return 6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JwtSecurityToken jwtToken = jwtHandler.ReadJwtToken(token);
|
|
|
|
|
var orgIdClaim = jwtToken.Claims.FirstOrDefault(x => x.Type == "OrgId");
|
|
|
|
|
|
|
|
|
|
return orgIdClaim != null ? Convert.ToInt64(orgIdClaim.Value) : 7;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long GetUserId()
|
|
|
|
|
{
|
|
|
|
|
var token = GetToken();
|
|
|
|
|
if (string.IsNullOrEmpty(token))
|
|
|
|
|
{
|
|
|
|
|
return 8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var jwtHandler = new JwtSecurityTokenHandler();
|
|
|
|
|
if (!jwtHandler.CanReadToken(token))
|
|
|
|
|
{
|
|
|
|
|
var claimValue = GetClaimValueByType("OrgId").FirstOrDefault();
|
|
|
|
|
_orgId = claimValue != null ? long.Parse(claimValue) : 0;
|
|
|
|
|
return 9;
|
|
|
|
|
}
|
|
|
|
|
return _orgId;
|
|
|
|
|
|
|
|
|
|
JwtSecurityToken jwtToken = jwtHandler.ReadJwtToken(token);
|
|
|
|
|
var userIdClaim = jwtToken.Claims.FirstOrDefault(x => x.Type == "jti");
|
|
|
|
|
|
|
|
|
|
return userIdClaim != null ? Convert.ToInt64(userIdClaim.Value) : 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//public long GetOrgId()
|
|
|
|
@ -195,7 +232,7 @@ public class AspNetUser : IUser
|
|
|
|
|
if (_tenantId == null)
|
|
|
|
|
{
|
|
|
|
|
var tenantIdClaim = GetClaimValueByType("TenantId").FirstOrDefault();
|
|
|
|
|
_tenantId = tenantIdClaim != null ? tenantIdClaim.ObjToString() : "00000000000001";
|
|
|
|
|
_tenantId = tenantIdClaim != null ? tenantIdClaim.ObjToString() : GetTenantId().ToString();
|
|
|
|
|
}
|
|
|
|
|
return _tenantId;
|
|
|
|
|
}
|
|
|
|
@ -235,7 +272,7 @@ public class AspNetUser : IUser
|
|
|
|
|
if (_orgId == 0)
|
|
|
|
|
{
|
|
|
|
|
var orgIdClaim = GetClaimValueByType("OrgId").FirstOrDefault();
|
|
|
|
|
_orgId = orgIdClaim != null ? long.Parse(orgIdClaim) : 0;
|
|
|
|
|
_orgId = orgIdClaim != null ? long.Parse(orgIdClaim) : GetOrgId();
|
|
|
|
|
}
|
|
|
|
|
return _orgId;
|
|
|
|
|
}
|
|
|
|
@ -275,19 +312,6 @@ public class AspNetUser : IUser
|
|
|
|
|
return userInfo ?? null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UserInfo GetDefaultUserInfo()
|
|
|
|
|
{
|
|
|
|
|
return new UserInfo()
|
|
|
|
|
{
|
|
|
|
|
CompanyId = "000001",
|
|
|
|
|
CompanyName = "东胜软件",
|
|
|
|
|
Token = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiIsImFkbWluIjp0cnVlfQ",
|
|
|
|
|
UserCode = "0000001",
|
|
|
|
|
UserId = "00000000",
|
|
|
|
|
UserName = "东胜软件",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetToken()
|
|
|
|
|
{
|
|
|
|
|
if (_accessor == null || _accessor.HttpContext == null)
|
|
|
|
|