1
0
forked from noxious/server

Continuation of refactor

This commit is contained in:
2024-12-28 20:40:05 +01:00
parent 6dda79f8b2
commit e1a6f650fb
27 changed files with 158 additions and 236 deletions

View File

@ -7,13 +7,6 @@ import { loginAccountSchema, registerAccountSchema, resetPasswordSchema, newPass
import UserService from '#services/userService'
export class AuthController extends BaseController {
private userService: UserService
constructor() {
super()
this.userService = new UserService()
}
/**
* Login user
* @param req
@ -24,7 +17,7 @@ export class AuthController extends BaseController {
try {
loginAccountSchema.parse({ username, password })
const user = await this.userService.login(username, password)
const user = await UserService.login(username, password)
if (user && typeof user !== 'boolean') {
const token = jwt.sign({ id: user.getId() }, config.JWT_SECRET, { expiresIn: '4h' })
@ -47,7 +40,7 @@ export class AuthController extends BaseController {
try {
registerAccountSchema.parse({ username, email, password })
const user = await this.userService.register(username, email, password)
const user = await UserService.register(username, email, password)
if (user) {
return this.sendSuccess(res, null, 'User registered successfully')
@ -69,7 +62,7 @@ export class AuthController extends BaseController {
try {
resetPasswordSchema.parse({ email })
const sentEmail = await this.userService.requestPasswordReset(email)
const sentEmail = await UserService.requestPasswordReset(email)
if (sentEmail) {
return this.sendSuccess(res, null, 'Password reset email sent')
@ -91,7 +84,7 @@ export class AuthController extends BaseController {
try {
newPasswordSchema.parse({ urlToken, password })
const resetPassword = await this.userService.resetPassword(urlToken, password)
const resetPassword = await UserService.resetPassword(urlToken, password)
if (resetPassword) {
return this.sendSuccess(res, null, 'Password has been reset')