refactor: is_paid→is_member, paid_expires_at→membership_expires_at 全局重命名
This commit is contained in:
@@ -498,8 +498,8 @@ pub struct WebLoginConfirmRequest {
|
||||
pub struct WebLoginConfirmResponse {
|
||||
pub success: bool,
|
||||
pub token: Option<String>,
|
||||
pub is_paid_active: bool,
|
||||
pub paid_expires_at: Option<String>,
|
||||
pub is_active_member: bool,
|
||||
pub membership_expires_at: Option<String>,
|
||||
}
|
||||
|
||||
#[post("/api/web-login/confirm")]
|
||||
@@ -529,8 +529,8 @@ pub async fn web_login_confirm(
|
||||
return HttpResponse::Ok().json(WebLoginConfirmResponse {
|
||||
success: false,
|
||||
token: None,
|
||||
is_paid_active: false,
|
||||
paid_expires_at: None,
|
||||
is_active_member: false,
|
||||
membership_expires_at: None,
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -548,12 +548,12 @@ pub async fn web_login_confirm(
|
||||
return HttpResponse::Ok().json(WebLoginConfirmResponse {
|
||||
success: false,
|
||||
token: None,
|
||||
is_paid_active: false,
|
||||
paid_expires_at: None,
|
||||
is_active_member: false,
|
||||
membership_expires_at: None,
|
||||
});
|
||||
}
|
||||
|
||||
// 如果已有用户,验证并获取最新 is_paid 信息
|
||||
// 如果已有用户,验证并获取最新 is_member 信息
|
||||
let user_id = if let Some(uid) = existing_user_id {
|
||||
uid
|
||||
} else {
|
||||
@@ -588,16 +588,16 @@ pub async fn web_login_confirm(
|
||||
};
|
||||
|
||||
// 查询付费状态
|
||||
let (is_paid_active, paid_expires_at): (bool, Option<String>) =
|
||||
let (is_active_member, membership_expires_at): (bool, Option<String>) =
|
||||
match sqlx::query_as::<_, (bool, Option<chrono::DateTime<chrono::Utc>>)>(
|
||||
"SELECT is_paid, paid_expires_at FROM users WHERE id = $1",
|
||||
"SELECT is_member, membership_expires_at FROM users WHERE id = $1",
|
||||
)
|
||||
.bind(user_id)
|
||||
.fetch_optional(pool.get_ref())
|
||||
.await
|
||||
{
|
||||
Ok(Some((is_paid, expires))) => {
|
||||
let active = is_paid && expires.map_or(true, |e| e > Utc::now());
|
||||
Ok(Some((is_member, expires))) => {
|
||||
let active = is_member && expires.map_or(true, |e| e > Utc::now());
|
||||
(active, expires.map(|e| e.to_rfc3339()))
|
||||
}
|
||||
_ => (false, None),
|
||||
@@ -613,12 +613,12 @@ pub async fn web_login_confirm(
|
||||
tracing::warn!("更新登录码 token 失败: {}", e);
|
||||
}
|
||||
|
||||
info!("[WEB LOGIN CONFIRM] user_id={} is_paid={}", user_id, is_paid_active);
|
||||
info!("[WEB LOGIN CONFIRM] user_id={} is_member={}", user_id, is_active_member);
|
||||
HttpResponse::Ok().json(WebLoginConfirmResponse {
|
||||
success: true,
|
||||
token: Some(token),
|
||||
is_paid_active,
|
||||
paid_expires_at,
|
||||
is_active_member,
|
||||
membership_expires_at,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -631,8 +631,8 @@ pub struct AutoConfirmRequest {
|
||||
pub struct AutoConfirmResponse {
|
||||
pub success: bool,
|
||||
pub token: Option<String>,
|
||||
pub is_paid_active: bool,
|
||||
pub paid_expires_at: Option<String>,
|
||||
pub is_active_member: bool,
|
||||
pub membership_expires_at: Option<String>,
|
||||
pub payment_url: Option<String>,
|
||||
}
|
||||
|
||||
@@ -719,7 +719,7 @@ pub async fn web_login_auto_confirm(
|
||||
};
|
||||
|
||||
let paid_info = sqlx::query_as::<_, (bool, Option<chrono::DateTime<chrono::Utc>>)>(
|
||||
"SELECT is_paid, paid_expires_at FROM users WHERE id = $1",
|
||||
"SELECT is_member, membership_expires_at FROM users WHERE id = $1",
|
||||
)
|
||||
.bind(user_id)
|
||||
.fetch_optional(pool.get_ref())
|
||||
@@ -727,9 +727,9 @@ pub async fn web_login_auto_confirm(
|
||||
.ok()
|
||||
.flatten();
|
||||
|
||||
let (is_paid_active, paid_expires_at): (bool, Option<String>) = match paid_info {
|
||||
Some((is_paid, expires)) => {
|
||||
let active = is_paid && expires.map_or(true, |e| e > Utc::now());
|
||||
let (is_active_member, membership_expires_at): (bool, Option<String>) = match paid_info {
|
||||
Some((is_member, expires)) => {
|
||||
let active = is_member && expires.map_or(true, |e| e > Utc::now());
|
||||
(active, expires.map(|e| e.to_rfc3339()))
|
||||
}
|
||||
None => (false, None),
|
||||
@@ -737,18 +737,18 @@ pub async fn web_login_auto_confirm(
|
||||
|
||||
let base_url = std::env::var("APP_BASE_URL")
|
||||
.unwrap_or_else(|_| "https://dev.xmclassmate.top".to_string());
|
||||
let payment_url = if is_paid_active {
|
||||
let payment_url = if is_active_member {
|
||||
None
|
||||
} else {
|
||||
Some(format!("{}/payment?jwt={}", base_url, token))
|
||||
};
|
||||
|
||||
info!("[WEB LOGIN AUTO-CONFIRM] user_id={} is_paid={}", user_id, is_paid_active);
|
||||
info!("[WEB LOGIN AUTO-CONFIRM] user_id={} is_member={}", user_id, is_active_member);
|
||||
HttpResponse::Ok().json(AutoConfirmResponse {
|
||||
success: true,
|
||||
token: Some(token),
|
||||
is_paid_active,
|
||||
paid_expires_at,
|
||||
is_active_member,
|
||||
membership_expires_at,
|
||||
payment_url,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user