import { Request , Response , NextFunction } from 'express' ; import { get , controller , bodyValidator , post } from './decorators' ; @ controller ( '/auth' ) class LoginController { @ get ( '/login' ) getLogin ( req , res ) { res . send ( `
      <form method="POST">
        <div>
          <label>Email</label>
          <input name="email" />
        </div>
        <div>
          <label>Password</label>
          <input name="password" type="password" />
        </div>
        <button>Submit</button>
      </form>
    ` ) ; } @ post ( '/login' ) @ bodyValidator ( 'email' , 'password' ) postLogin ( req , res ) { const { email , password } = req . body ; if ( email === 'hi@hi.com' && password === 'password' ) { req . session = { loggedIn : true } ; res . redirect ( '/' ) ; } else { res . send ( 'Invalid email or password' ) ; } } @ get ( '/logout' ) getLogout ( req , res ) { req . session = undefined ; res . redirect ( '/' ) ; } }