feat: add register page and logout button

This commit is contained in:
shinya
2025-07-02 23:34:07 +08:00
parent 2d066d5d26
commit 2027322a98
8 changed files with 229 additions and 17 deletions

View File

@@ -54,6 +54,8 @@ export interface IStorage {
// 用户相关
registerUser(userName: string, password: string): Promise<void>;
verifyUser(userName: string, password: string): Promise<boolean>;
// 检查用户是否存在(无需密码)
checkUserExist(userName: string): Promise<boolean>;
// 搜索历史相关
getSearchHistory(): Promise<string[]>;
@@ -171,6 +173,13 @@ class RedisStorage implements IStorage {
return stored === password;
}
// 检查用户是否存在
async checkUserExist(userName: string): Promise<boolean> {
// 使用 EXISTS 判断 key 是否存在
const exists = await this.client.exists(this.userPwdKey(userName));
return exists === 1;
}
// ---------- 搜索历史 ----------
private shKey = 'moontv:search_history';
@@ -342,6 +351,11 @@ export class DbManager {
return this.storage.verifyUser(userName, password);
}
// 检查用户是否已存在
async checkUserExist(userName: string): Promise<boolean> {
return this.storage.checkUserExist(userName);
}
// ---------- 搜索历史 ----------
async getSearchHistory(): Promise<string[]> {
return this.storage.getSearchHistory();