Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add authentication system (#4)
* fix: this context in controller instance undefined * feat: add cookie management * feat: add sidebar * feat:add searchbar * feat: fix searchbar * feat:finish searchbar ♥ * feat:add layout home page , TwobarChart, AreaChart * refactor: cookie implementation and document * feat:add headless ui and add responesive * feat:fix MachineLog error * feat:fix case bug * feat:delete MachineLog and and Progressing circle * feat: remove gridline form areachart and twobar * feat:add Pagination Errorlog but dont no type of pagination * feat:fix misspell * refactor: eliminate type 'any * feat:fix prevent loading component * feat: reuse components * feat:add Loginpage * feat: add database connector and prepared auth service (#3) * build: add devDependencies 'dotenv' * build: preload environment variables * build: add dependencies 'mysql2' * feat: add mysql database connection * chore: add example environment variable * refactor: eliminate type 'any' * refactor: add missing modifier * feat: adds Address, Branch model * feat: adds Address,Branch,Machine,Staff,Zone model * feat:adds MainrenanceLog, MaintenanceParts * feat: fix Branch * feat:add MachinePart model * feat: adds Order, Bill model * feat: removes useless constructor, adds pk getter * feat: add pk getter, assign readonly only for pk * refactor: remove unit testing (base code) * refactor: use MYSQL_PASSWORD instead * build: add redis dependency * refactor: database connection with mysql and redis * refactor: add generateRedisUri method * refactor: make some redis environment optional * build: remove unused environment variable * build: add redis's environment variable * feat: add DatabaseEntity Interface * feat: add set pk for Address, Bill, Branch * feat: add set pk for Machine, MachinePart, MLog * feat: add set pk for MPart, Order, Staff, Zone * style: add vscode setting for coding style * refactor: class naming and use path mapping * feat: add regex util * feat: add base code of auth service * feat: add auth service unit test Co-authored-by: XiaoXuxxxx <aonrok555@gmail.com> Co-authored-by: eltfshr <puntf2@gmail.com> Co-authored-by: Porping <porsteam@hotmail.com> * feat: add not found 404 fallback middleware * feat: add request decorator for basic validation * refactor: remove next function parameter * fix: missing get connection methods * refactor: login method return cookie with sid * refactor: invoke auth service instead of mock * refactor: call express url encoding & json parser * fix: wrong expect (forget to fix after changed) * feat: add auth controller unit test * feat: add DateUtil class * feat: add repository interface * feat: add staff repository, add password in staff * build: add bcrypt depedency * refactor: dependecy inversion for testability * refactor: complete auth service for logging in * refactor: auth service tester with new interface * refactor: entity interface * refactor: database connection for repository * fix: tsconfig annoying warning * feat: add parameter 'readOptions' to read method * refactor: convert to marker interface * feat: add test script on top-level module * feat: add address repository * feat: add zone repository * refactor: clean yarn.lock with yarn install * feat: add machine repository * fix: linting issue * fix: add dateutil * feat:add order repository * refactor: convert to marker interface * feat: add maintenancepart repository * feat: add maintenancelog repository * fix: variable same in database * fix: method typo * refactor: register all repositories * feat: add machinepart repository * feat: add branch repository * feat: add bill repository * refactor: change return type of update and delete * refactor: change return type of concrete classes * refactor: change return type related to interface * typo: fix misspelling words * feat: register alll repositories * refactor: pool typing as mysql like redis * fix: annoying new line * feat: add session entity/repository * fix: fix typos * fix: wrong casing on import * refactor: add sql builder for utility * refactor: use new sql builder for example * refactor: use new sql builder for example * refactor: remove unnecessary json parse * feat: add axios and login state * fix: easy fix when pass undefined into the method * refactor: implement session and logout * refactor: util raw cookie and signed cookie * refactor: controller registration for middleware * build: clean yarn.lock for ci * refactor: auth service unit test * feat: add get staff info route * feat: add validation for readoptions * refactor: remove unnecessary logging * fix: limit and offset must be integer * refactor: clean sourcecode * feat: add number utility class * feat: add optional request body * feat: implement authorization with decorator * refactor: throw meaningful exceception instead Co-authored-by: Porping <porsteam@hotmail.com> Co-authored-by: XiaoXuxxxx <aonrok555@gmail.com> Co-authored-by: eltfshr <puntf2@gmail.com>
- Loading branch information
1 parent
b39fa59
commit 51cd5cc
Showing
97 changed files
with
4,735 additions
and
344 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"typescript.preferences.importModuleSpecifier": "non-relative", | ||
"typescript.preferences.quoteStyle": "single", | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
MYSQL_HOST= | ||
MYSQL_PORT= | ||
MYSQL_USER= | ||
MYSQL_PASSWORD= | ||
MYSQL_DATABASE= | ||
|
||
REDIS_HOST= | ||
REDIS_PORT= | ||
REDIS_USER= | ||
REDIS_PASSWORD= |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
declare namespace Express { | ||
export interface Request { | ||
session?: { | ||
sessionId: string, | ||
staffId: number, | ||
} | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Controller } from '@/controllers/Controller'; | ||
import { Methods } from '@/controllers/Route'; | ||
import { ControllerMapping } from '@/decorators/ControllerDecorator'; | ||
import { RouteMapping } from '@/decorators/RouteDecorator'; | ||
import { CookieProvider } from '@/utils/cookie/CookieProvider'; | ||
import { Request, Response } from 'express'; | ||
import { RequestBody } from '@/decorators/RequestDecorator'; | ||
import { AuthService } from '@/services/AuthService'; | ||
|
||
@ControllerMapping('/auth') | ||
export class AuthController extends Controller { | ||
|
||
private readonly cookieProvider: CookieProvider; | ||
private readonly authService: AuthService; | ||
|
||
public constructor(cookieProvider: CookieProvider, authService: AuthService) { | ||
super(); | ||
this.cookieProvider = cookieProvider; | ||
this.authService = authService; | ||
} | ||
|
||
@RouteMapping('/login', Methods.POST) | ||
@RequestBody('username', 'password') | ||
private async loginRoute(req: Request, res: Response): Promise<void> { | ||
const { username, password } = req.body; | ||
|
||
const cookie = await this.authService.login(username, password); | ||
|
||
if (cookie) { | ||
this.cookieProvider.setSignedCookie(res, cookie); | ||
|
||
res.status(200).json({ | ||
message: 'Logged in successfully', | ||
}); | ||
} | ||
} | ||
|
||
@RouteMapping('/logout', Methods.GET) | ||
private async logoutRoute(req: Request, res: Response): Promise<void> { | ||
const sessionId = this.cookieProvider.getSignedCookie(req, 'sid'); | ||
|
||
await this.authService.logout(sessionId); | ||
|
||
res.status(200).json({ | ||
message: 'Logged out successfully', | ||
}); | ||
} | ||
|
||
} |
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
Oops, something went wrong.