feat: add RegionCode by UserIdentity.

This commit is contained in:
AnonymousDotNet 2024-10-23 14:57:57 +08:00
parent 0f930b4c46
commit 0fbe0e6f0c
3 changed files with 9 additions and 3 deletions

View file

@ -17,4 +17,5 @@ public interface IUserIdentity
string? EmployeeId { get; }
string Type { get; }
string Role { get; }
string? RegionCode { get; }
}

View file

@ -63,7 +63,7 @@ public class UserIdentity : IUserIdentity
get
{
_contextAccessor.HttpContext.Request.Headers.TryGetValue("User-Language", out var languages);
return languages.FirstOrDefault() ?? "en-US";
return languages.FirstOrDefault() ?? "en-US";
}
}
@ -81,4 +81,7 @@ public class UserIdentity : IUserIdentity
[JsonPropertyName("role")]
public string? Role => _claims?.FirstOrDefault(x => x.Type == ClaimTypes.Role)?.Value;
[JsonPropertyName("regionCode")]
public string? RegionCode => _claims?.FirstOrDefault(x => x.Type == "regionCode")?.Value;
}

View file

@ -267,7 +267,8 @@ public class UserService : IUserService
ExternalId = user.ExternalId,
Password = user.Password,
Type = user.Type,
Role = user.Role
Role = user.Role,
RegionCode = user.RegionCode
};
await CreateUser(record);
}
@ -317,7 +318,8 @@ public class UserService : IUserService
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim("phone", user.Phone ?? string.Empty),
new Claim("affiliateId", user.AffiliateId ?? string.Empty),
new Claim("employeeId", user.EmployeeId ?? string.Empty)
new Claim("employeeId", user.EmployeeId ?? string.Empty),
new Claim("regionCode", user.RegionCode ?? "CN")
};
var validators = _services.GetServices<IAuthenticationHook>();