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>
|
createUser(username: string, password: string): Promise<User>
|
||||||
getUser(username: string, password: string): Promise<User|null>
|
getUser(username: string, password: string): Promise<User|null>
|
||||||
updatePassword(username: string, password: string, newPassword: string): Promise<void>
|
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()
|
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()
|
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()
|
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()
|
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 (
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
user_id INTEGER PRIMARY KEY,
|
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
username TEXT UNIQUE NOT NULL ,
|
username TEXT UNIQUE NOT NULL ,
|
||||||
password_hash TEXT NOT NULL
|
password_hash TEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|||||||
@ -18,13 +18,14 @@ class UserDB {
|
|||||||
this.username = username
|
this.username = username
|
||||||
this.password_hash = password_hash
|
this.password_hash = password_hash
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UserDBBroker implements IUserBroker {
|
export class UserDBBroker implements IUserBroker {
|
||||||
|
|
||||||
private static initialized = false
|
private static initialized = false
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
if (UserDB.initialized) {
|
if (UserDBBroker.initialized) {
|
||||||
// UGLY: make more specific
|
// UGLY: make more specific
|
||||||
throw Error("UserDB has been already initialized")
|
throw Error("UserDB has been already initialized")
|
||||||
}
|
}
|
||||||
@ -35,7 +36,7 @@ export class UserDBBroker implements IUserBroker {
|
|||||||
const stmt = SSLSnifferApp.prepare(
|
const stmt = SSLSnifferApp.prepare(
|
||||||
`
|
`
|
||||||
CREATE TABLE IF NOT EXISTS users (
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
user_id INTEGER PRIMARY KEY,
|
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
username TEXT UNIQUE NOT NULL ,
|
username TEXT UNIQUE NOT NULL ,
|
||||||
password_hash TEXT NOT NULL
|
password_hash TEXT NOT NULL
|
||||||
);
|
);
|
||||||
@ -138,7 +139,7 @@ export class UserDBBroker implements IUserBroker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implement this
|
// TODO: implement this
|
||||||
public getUserFromSession(session: string): User {
|
public getUserFromSession(sessionID: number): User {
|
||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user