mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
feat(auth): /me 接口返回 has_password 字段,前端 Profile 类型同步调整
This commit is contained in:
@@ -176,6 +176,10 @@ fn build_auth_me_payload(
|
|||||||
wallet: Option<&aether_data::repository::wallet::StoredWalletSnapshot>,
|
wallet: Option<&aether_data::repository::wallet::StoredWalletSnapshot>,
|
||||||
) -> serde_json::Value {
|
) -> serde_json::Value {
|
||||||
let billing = build_auth_wallet_summary_payload(wallet);
|
let billing = build_auth_wallet_summary_payload(wallet);
|
||||||
|
let has_password = user
|
||||||
|
.password_hash
|
||||||
|
.as_deref()
|
||||||
|
.is_some_and(|value| !value.is_empty());
|
||||||
json!({
|
json!({
|
||||||
"id": user.id,
|
"id": user.id,
|
||||||
"email": user.email,
|
"email": user.email,
|
||||||
@@ -189,6 +193,7 @@ fn build_auth_me_payload(
|
|||||||
"created_at": user.created_at.map(|value| value.to_rfc3339()),
|
"created_at": user.created_at.map(|value| value.to_rfc3339()),
|
||||||
"last_login_at": user.last_login_at.map(|value| value.to_rfc3339()),
|
"last_login_at": user.last_login_at.map(|value| value.to_rfc3339()),
|
||||||
"auth_source": user.auth_source,
|
"auth_source": user.auth_source,
|
||||||
|
"has_password": has_password,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4187,6 +4187,8 @@ async fn gateway_updates_users_me_detail_locally_without_proxying_upstream() {
|
|||||||
let get_payload: serde_json::Value = get_response.json().await.expect("json body should parse");
|
let get_payload: serde_json::Value = get_response.json().await.expect("json body should parse");
|
||||||
assert_eq!(get_payload["email"], "alice+updated@example.com");
|
assert_eq!(get_payload["email"], "alice+updated@example.com");
|
||||||
assert_eq!(get_payload["username"], "alice-updated");
|
assert_eq!(get_payload["username"], "alice-updated");
|
||||||
|
assert_eq!(get_payload["auth_source"], "local");
|
||||||
|
assert_eq!(get_payload["has_password"], true);
|
||||||
assert_eq!(*upstream_hits.lock().expect("mutex should lock"), 0);
|
assert_eq!(*upstream_hits.lock().expect("mutex should lock"), 0);
|
||||||
|
|
||||||
gateway_handle.abort();
|
gateway_handle.abort();
|
||||||
@@ -7352,6 +7354,8 @@ async fn gateway_handles_users_me_detail_locally_without_proxying_upstream() {
|
|||||||
assert_eq!(payload["id"], "user-auth-1");
|
assert_eq!(payload["id"], "user-auth-1");
|
||||||
assert_eq!(payload["email"], "alice@example.com");
|
assert_eq!(payload["email"], "alice@example.com");
|
||||||
assert_eq!(payload["username"], "alice");
|
assert_eq!(payload["username"], "alice");
|
||||||
|
assert_eq!(payload["auth_source"], "local");
|
||||||
|
assert_eq!(payload["has_password"], true);
|
||||||
assert_eq!(payload["billing"]["id"], "wallet-auth-1");
|
assert_eq!(payload["billing"]["id"], "wallet-auth-1");
|
||||||
assert_eq!(payload["billing"]["balance"], 15.5);
|
assert_eq!(payload["billing"]["balance"], 15.5);
|
||||||
assert_eq!(*upstream_hits.lock().expect("mutex should lock"), 0);
|
assert_eq!(*upstream_hits.lock().expect("mutex should lock"), 0);
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ export interface Profile {
|
|||||||
created_at: string
|
created_at: string
|
||||||
updated_at?: string
|
updated_at?: string
|
||||||
last_login_at?: string
|
last_login_at?: string
|
||||||
auth_source?: 'local' | 'ldap' | 'oauth'
|
auth_source: 'local' | 'ldap' | 'oauth'
|
||||||
has_password?: boolean
|
has_password: boolean
|
||||||
preferences?: UserPreferences
|
preferences?: UserPreferences
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,8 @@ export const MOCK_ADMIN_PROFILE: Profile = {
|
|||||||
role: 'admin',
|
role: 'admin',
|
||||||
is_active: true,
|
is_active: true,
|
||||||
billing: MOCK_ADMIN_BILLING,
|
billing: MOCK_ADMIN_BILLING,
|
||||||
|
auth_source: 'local',
|
||||||
|
has_password: true,
|
||||||
created_at: '2024-01-01T00:00:00Z',
|
created_at: '2024-01-01T00:00:00Z',
|
||||||
updated_at: new Date().toISOString(),
|
updated_at: new Date().toISOString(),
|
||||||
last_login_at: new Date().toISOString(),
|
last_login_at: new Date().toISOString(),
|
||||||
@@ -119,6 +121,8 @@ export const MOCK_USER_PROFILE: Profile = {
|
|||||||
role: 'user',
|
role: 'user',
|
||||||
is_active: true,
|
is_active: true,
|
||||||
billing: MOCK_USER_BILLING,
|
billing: MOCK_USER_BILLING,
|
||||||
|
auth_source: 'local',
|
||||||
|
has_password: true,
|
||||||
created_at: '2024-06-01T00:00:00Z',
|
created_at: '2024-06-01T00:00:00Z',
|
||||||
updated_at: new Date().toISOString(),
|
updated_at: new Date().toISOString(),
|
||||||
last_login_at: new Date().toISOString(),
|
last_login_at: new Date().toISOString(),
|
||||||
|
|||||||
@@ -518,7 +518,7 @@ const mockHandlers: Record<string, (config: AxiosRequestConfig) => Promise<Axios
|
|||||||
// ========== 用户信息 ==========
|
// ========== 用户信息 ==========
|
||||||
'GET /api/users/me': async () => {
|
'GET /api/users/me': async () => {
|
||||||
await delay()
|
await delay()
|
||||||
return createMockResponse(getCurrentUser())
|
return createMockResponse(getCurrentProfile())
|
||||||
},
|
},
|
||||||
|
|
||||||
'PUT /api/users/me': async () => {
|
'PUT /api/users/me': async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user