Changes to support Sessions better
This commit is contained in:
parent
9a3be1cfe0
commit
85da2dbdc6
@ -4,7 +4,7 @@ export interface IUserBroker {
|
||||
createUser(username: string, password: string): Promise<User>
|
||||
getUser(username: string, password: string): Promise<User|null>
|
||||
updatePassword(username: string, password: string, newPassword: string): Promise<void>
|
||||
getUserFromSession(session: string): User
|
||||
getUserFromSession(sessionID: number): User
|
||||
|
||||
|
||||
|
||||
@ -45,24 +45,24 @@ export class UserApp {
|
||||
|
||||
}
|
||||
|
||||
public static getUserFromSession(session: string): User {
|
||||
public static getUserFromSession(sessionID: number): User {
|
||||
UserApp.assertInitialized()
|
||||
return UserApp.broker.getUserFromSession(session)
|
||||
return UserApp.broker.getUserFromSession(sessionID)
|
||||
}
|
||||
|
||||
public static createUser(username: string, password: string) {
|
||||
public static async createUser(username: string, password: string): Promise<User> {
|
||||
UserApp.assertInitialized()
|
||||
return UserApp.broker.createUser(username, password)
|
||||
return await UserApp.broker.createUser(username, password)
|
||||
}
|
||||
|
||||
public static getUser(username: string, password: string): User {
|
||||
public static async getUser(username: string, password: string): Promise<User|null> {
|
||||
UserApp.assertInitialized()
|
||||
return UserApp.broker.getUser(username, password)
|
||||
return await UserApp.broker.getUser(username, password)
|
||||
}
|
||||
|
||||
public static updatePassword(username: string, password: string, newPassword: string) {
|
||||
public static async updatePassword(username: string, password: string, newPassword: string) {
|
||||
UserApp.assertInitialized()
|
||||
return UserApp.broker.updatePassword(username, password, newPassword)
|
||||
return await UserApp.broker.updatePassword(username, password, newPassword)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
user_id INTEGER PRIMARY KEY,
|
||||
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT UNIQUE NOT NULL ,
|
||||
password_hash TEXT NOT NULL
|
||||
);
|
||||
|
||||
@ -19,12 +19,13 @@ class UserDB {
|
||||
this.password_hash = password_hash
|
||||
}
|
||||
}
|
||||
|
||||
export class UserDBBroker implements IUserBroker {
|
||||
|
||||
private static initialized = false
|
||||
|
||||
constructor() {
|
||||
if (UserDB.initialized) {
|
||||
if (UserDBBroker.initialized) {
|
||||
// UGLY: make more specific
|
||||
throw Error("UserDB has been already initialized")
|
||||
}
|
||||
@ -35,7 +36,7 @@ export class UserDBBroker implements IUserBroker {
|
||||
const stmt = SSLSnifferApp.prepare(
|
||||
`
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
user_id INTEGER PRIMARY KEY,
|
||||
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT UNIQUE NOT NULL ,
|
||||
password_hash TEXT NOT NULL
|
||||
);
|
||||
@ -138,7 +139,7 @@ export class UserDBBroker implements IUserBroker {
|
||||
}
|
||||
|
||||
// TODO: implement this
|
||||
public getUserFromSession(session: string): User {
|
||||
public getUserFromSession(sessionID: number): User {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user