Created
May 2, 2021 14:16
-
-
Save Caballerog/5f53f114d7df6274f3bd6ad290620373 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Middleware } from "./middlewares"; | |
import { User } from "./interfaces"; | |
export class Server { | |
private users: Map<string, User> = new Map<string, User>(); | |
private middleware: Middleware; | |
public setMiddleware(middleware: Middleware): void { | |
this.middleware = middleware; | |
} | |
public logIn(email: string, password: string): boolean { | |
if (this.middleware.execute({ email, password })) { | |
console.log("Authorization have been successful!"); | |
return true; | |
} | |
return false; | |
} | |
public register(email: string, password: string): void { | |
const user: User = { | |
email, | |
password, | |
}; | |
this.users.set(email, user); | |
} | |
public hasEmail(email: string): boolean { | |
return this.users.has(email); | |
} | |
public isValidPassword(email: string, password: string): boolean { | |
const user = this.users.get(email); | |
return user.password === password; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment