forked from noxious/server
Added extra logging to HTTP endpoints
This commit is contained in:
parent
bf75ad001b
commit
6a76c4797a
@ -5,6 +5,7 @@ import prisma from '../utilities/prisma'
|
||||
import { User, PasswordResetToken } from '@prisma/client'
|
||||
import config from '../utilities/config'
|
||||
import NodeMailer from 'nodemailer'
|
||||
import { gameLogger, httpLogger } from '../utilities/logger'
|
||||
|
||||
/**
|
||||
* User service
|
||||
@ -18,6 +19,7 @@ class UserService {
|
||||
* @param password
|
||||
*/
|
||||
async login(username: string, password: string): Promise<boolean | User> {
|
||||
try {
|
||||
const user = await UserRepository.getByUsername(username)
|
||||
if (!user) {
|
||||
return false
|
||||
@ -25,10 +27,15 @@ class UserService {
|
||||
|
||||
const passwordMatch = await bcrypt.compare(password, user.password)
|
||||
if (!passwordMatch) {
|
||||
httpLogger.error(`Failed to login user: ${username}`)
|
||||
return false
|
||||
}
|
||||
|
||||
return user
|
||||
} catch (error: any) {
|
||||
httpLogger.error(`Error logging in user: ${error instanceof Error ? error.message : String(error)}`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,6 +45,7 @@ class UserService {
|
||||
* @param password
|
||||
*/
|
||||
async register(username: string, email: string, password: string): Promise<boolean | User> {
|
||||
try {
|
||||
const user = await UserRepository.getByUsername(username)
|
||||
if (user) {
|
||||
return false
|
||||
@ -45,6 +53,7 @@ class UserService {
|
||||
|
||||
const userByEmail = await UserRepository.getByEmail(email)
|
||||
if (userByEmail) {
|
||||
httpLogger.error(`User already exists: ${email}`)
|
||||
return false
|
||||
}
|
||||
|
||||
@ -56,6 +65,10 @@ class UserService {
|
||||
password: hashedPassword
|
||||
}
|
||||
})
|
||||
} catch (error: any) {
|
||||
httpLogger.error(`Error registering user: ${error instanceof Error ? error.message : String(error)}`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,6 +124,7 @@ class UserService {
|
||||
|
||||
return true
|
||||
} catch (error: any) {
|
||||
httpLogger.error(`Error sending password reset email: ${error instanceof Error ? error.message : String(error)}`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -121,6 +135,7 @@ class UserService {
|
||||
* @param password
|
||||
*/
|
||||
async newPassword(urlToken: string, password: string): Promise<boolean | User> {
|
||||
try {
|
||||
const tokenData = await PasswordResetTokenRepository.getByToken(urlToken)
|
||||
if (!tokenData) {
|
||||
return false
|
||||
@ -133,6 +148,10 @@ class UserService {
|
||||
password: hashedPassword
|
||||
}
|
||||
})
|
||||
} catch (error: any) {
|
||||
httpLogger.error(`Error setting new password: ${error instanceof Error ? error.message : String(error)}`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user