ow
This commit is contained in:
1 parent
9b01c4a57a
commit
6417562c4f
37 files changed
+2767
-202
No files matched your search
@@ -11,10 +11,12 @@ namespace CloudBuilder.Security.Policy
|
||||
{
|
||||
public class SecurityUserTypePolicy : LocalePolicy, IPolicy
|
||||
{
|
||||
// 用户类型码(security_user.user_type):未认证 / 普通用户 / VIP / SVIP
|
||||
// 普通用户沿用历史 "N",存量普通用户零影响;旧审计码 I/S/K 已作废。
|
||||
public const string UNAUTHENTICATED_USERS = "U";
|
||||
public const string NORMAL_USERS = "N";
|
||||
public const string ICTI_USERS = "I";
|
||||
public const string SEDEX_USERS = "S";
|
||||
public const string KOHLS_USERS = "K";
|
||||
public const string VIP_USERS = "V";
|
||||
public const string SVIP_USERS = "S";
|
||||
|
||||
private readonly IContext context;
|
||||
private readonly ILocaleMessageManager localeMessageManager;
|
||||
@@ -28,30 +30,24 @@ namespace CloudBuilder.Security.Policy
|
||||
}
|
||||
|
||||
|
||||
public static bool IsUnauthenticated(string code)
|
||||
{
|
||||
return code == UNAUTHENTICATED_USERS;
|
||||
}
|
||||
|
||||
public static bool IsNormalUser(string code)
|
||||
{
|
||||
return code == NORMAL_USERS;
|
||||
}
|
||||
|
||||
public static bool IsIctiUser(string code)
|
||||
public static bool IsVipUser(string code)
|
||||
{
|
||||
return code == ICTI_USERS;
|
||||
return code == VIP_USERS;
|
||||
}
|
||||
|
||||
public static bool IsSedexUser(string code)
|
||||
public static bool IsSvipUser(string code)
|
||||
{
|
||||
return code == SEDEX_USERS;
|
||||
}
|
||||
|
||||
public static bool IsKohlsUser(string code)
|
||||
{
|
||||
return code == KOHLS_USERS;
|
||||
}
|
||||
|
||||
|
||||
public static bool IsAuditor(string code)
|
||||
{
|
||||
return IsIctiUser(code) || IsSedexUser(code) || IsKohlsUser(code);
|
||||
return code == SVIP_USERS;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,36 @@ namespace CloudBuilder.Security.Policy
|
||||
public const string FfmpegPictrue = "Ffmpeg:Pictrue";
|
||||
public const string FfmpegArguments = "Ffmpeg:Arguments";
|
||||
|
||||
// 网盘额度(appsettings.json:NetDiskQuota),按 user_type 码取档
|
||||
public const string NetDiskQuotaSection = "NetDiskQuota";
|
||||
|
||||
/// <summary>
|
||||
/// 取当前用户类型的网盘额度(KB)。类型码缺失/未知回退按未认证(U)最小权限档;
|
||||
/// 未配置或解析不出数值时返回 0(调用方据 0 判定"不限额"还是"不可用")。
|
||||
/// </summary>
|
||||
public static long GetNetDiskQuotaKB(IApplicationService service, string userType)
|
||||
{
|
||||
var code = string.IsNullOrWhiteSpace(userType) ? SecurityUserTypePolicy.UNAUTHENTICATED_USERS : userType.Trim().ToUpperInvariant();
|
||||
var raw = service.Configuration[$"{NetDiskQuotaSection}:{code}"];
|
||||
// 未知类型码回退未认证档,避免历史脏码绕过限额
|
||||
if (string.IsNullOrWhiteSpace(raw))
|
||||
raw = service.Configuration[$"{NetDiskQuotaSection}:{SecurityUserTypePolicy.UNAUTHENTICATED_USERS}"];
|
||||
return ParseSizeToKB(raw);
|
||||
}
|
||||
|
||||
/// <summary>解析 "2G"/"100G"/"500G"/"1T"/"512M"/"2048K"(大小写兼容,缺省按 KB)为 KB。</summary>
|
||||
private static long ParseSizeToKB(string raw)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(raw)) return 0;
|
||||
raw = raw.Trim().ToUpperInvariant();
|
||||
long unit = 1; // KB
|
||||
if (raw.EndsWith("T")) { unit = 1024L * 1024 * 1024; raw = raw.Substring(0, raw.Length - 1); }
|
||||
else if (raw.EndsWith("G")) { unit = 1024L * 1024; raw = raw.Substring(0, raw.Length - 1); }
|
||||
else if (raw.EndsWith("M")) { unit = 1024L; raw = raw.Substring(0, raw.Length - 1); }
|
||||
else if (raw.EndsWith("K")) { unit = 1; raw = raw.Substring(0, raw.Length - 1); }
|
||||
return long.TryParse(raw.Trim(), out var n) && n > 0 ? n * unit : 0;
|
||||
}
|
||||
|
||||
// 身份证 OCR 识别服务(server-to-server 调用,地址来自 appsettings.json,避免写死)
|
||||
public const string IdCardOcrApiUrl = "IdCardOcr:ApiUrl";
|
||||
public const string IdCardOcrApiKey = "IdCardOcr:ApiKey";
|
||||
|
||||
Reference in new issue
Block a user