feat(auth+desktop): 邮箱验证码登录 + 登录窗改版(微信/邮箱双方式,无边框)
ci / server (push) Failing after 10s
ci / design-system (push) Failing after 10s

后端(协议 → 存储 → 接口,E2E 测试全绿):
- protocol:AuthEmailCodeRequest / AuthEmailRequest DTO
- store:EmailIdentity 表(邮箱唯一索引)+ authmail:* Redis key
- auth/email.go:POST /v1/auth/email/code 发 6 位码(crypto/rand,
  60s 冷却 SetNX,10 分钟 TTL);POST /v1/auth/email 常量时间比对、
  码一次性、邮箱建号(昵称取前缀)→ JWT(与微信登录同响应形态)
- Mailer 接口 + MockMailer(验证码打日志供联调;SMTP 未配置自动降级,
  装配结果入启动日志,上线前须换真实实现)
- TestEmailLogin E2E:发码/冷却 429/错码拒绝/登录/token 可用/码防复用

桌面(Rust 命令 + UI 改版):
- api.rs:login_email_code / login_email(成功保存 token + ws 重连,
  与扫码登录同路径)
- 登录窗改版(原型 LoginPurchase 先行,dark 截图验收):logo + 分段
  切换(微信扫码 / 邮箱登录,与设置页同控件语言)+ 邮箱表单
  (60s 倒计时、错误文案、未注册自动建号提示)
- 二维码真渲染:qrcode 库画 canvas(前景/背景取主题 token),
  替换原 URL 文本占位;过期态半透明化
- 登录窗无边框化:transparent + Overlay 标题栏 + 原生贴形阴影;
  抽公共 WindowFrame 组件(设置窗同步重构复用)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-07-11 09:40:16 +08:00
parent 0ca1caa460
commit 19281d9c42
20 changed files with 871 additions and 86 deletions
+37
View File
@@ -109,6 +109,43 @@ pub async fn login_qr_poll(app: AppHandle, state: String) -> Option<Value> {
Some(v)
}
/// 发送邮箱登录验证码。返回 true=已发送,false=网络失败,
/// Some(json) 形式的错误码(如 RATE_LIMITED 冷却中)由前端据 status 判断。
#[tauri::command]
pub async fn login_email_code(app: AppHandle, email: String) -> Option<u16> {
let (url, _) = base(&app);
let resp = http()
.post(format!("{url}/v1/auth/email/code"))
.json(&serde_json::json!({ "email": email }))
.send()
.await
.ok()?;
Some(resp.status().as_u16())
}
/// 邮箱验证码登录:成功保存 token 并重连 ws(与扫码登录同路径)。
#[tauri::command]
pub async fn login_email(app: AppHandle, email: String, code: String) -> Option<Value> {
let (url, _) = base(&app);
let v: Value = http()
.post(format!("{url}/v1/auth/email"))
.json(&serde_json::json!({ "email": email, "code": code }))
.send()
.await
.ok()?
.json()
.await
.ok()?;
if let Some(token) = v.get("token").and_then(|t| t.as_str()) {
let store = app.state::<crate::settings::SettingsStore>();
let mut s = store.get();
s.token = token.to_string();
store.set(s);
let _ = app.state::<crate::ws::WsHandle>().send(crate::ws::WsCmd::Reconnect);
}
Some(v)
}
#[tauri::command]
pub async fn create_order(app: AppHandle, pack_id: String) -> Option<Value> {
let (url, token) = base(&app);
+2
View File
@@ -152,6 +152,8 @@ pub fn run() {
api::fetch_packs,
api::login_qr_create,
api::login_qr_poll,
api::login_email_code,
api::login_email,
api::create_order,
api::order_status,
api::submit_feedback,
+9 -1
View File
@@ -49,7 +49,15 @@
"width": 400,
"height": 520,
"resizable": false,
"visible": false
"visible": false,
"transparent": true,
"shadow": true,
"titleBarStyle": "Overlay",
"hiddenTitle": true,
"trafficLightPosition": {
"x": 18,
"y": 18
}
},
{
"label": "tray",