Move endpoints
This commit is contained in:
@@ -3,9 +3,9 @@ import {
|
||||
getClientIp,
|
||||
getDatabaseConnection,
|
||||
jsonResponse
|
||||
} from '../../../../lib/util'
|
||||
import { checkAuthorization } from '../../../../lib/auth'
|
||||
import { users } from '../../../../lib/tables'
|
||||
} from '../../../lib/util'
|
||||
import { checkAuthorization } from '../../../lib/auth'
|
||||
import { users } from '../../../lib/tables'
|
||||
import { eq } from 'drizzle-orm'
|
||||
import bcrypt from 'bcryptjs'
|
||||
|
||||
@@ -23,7 +23,6 @@ export async function handler (context: Context) {
|
||||
500
|
||||
)
|
||||
const { connection: connection0, db: db0 } = dbInfo0
|
||||
const { connection: connection1, db: db1 } = dbInfo1
|
||||
|
||||
const ip = getClientIp(context)
|
||||
const authorizationToken = context.headers.authorization
|
||||
@@ -34,7 +33,6 @@ export async function handler (context: Context) {
|
||||
)
|
||||
if (!authResult.valid) {
|
||||
connection0.end()
|
||||
connection1.end()
|
||||
return jsonResponse({ success: false, message: 'Unauthorized' }, 401)
|
||||
}
|
||||
const userId = authResult.id
|
||||
@@ -42,7 +40,6 @@ export async function handler (context: Context) {
|
||||
const body = context.body as Body
|
||||
if (!body.newPassword) {
|
||||
connection0.end()
|
||||
connection1.end()
|
||||
return jsonResponse(
|
||||
{ success: false, message: 'No new password provided' },
|
||||
400
|
||||
@@ -55,7 +52,6 @@ export async function handler (context: Context) {
|
||||
)
|
||||
) {
|
||||
connection0.end()
|
||||
connection1.end()
|
||||
return jsonResponse(
|
||||
{
|
||||
success: false,
|
||||
@@ -3,9 +3,9 @@ import {
|
||||
getClientIp,
|
||||
getDatabaseConnection,
|
||||
jsonResponse
|
||||
} from '../../../../lib/util'
|
||||
import { checkAuthorization } from '../../../../lib/auth'
|
||||
import { users } from '../../../../lib/tables'
|
||||
} from '../../../lib/util'
|
||||
import { checkAuthorization } from '../../../lib/auth'
|
||||
import { users } from '../../../lib/tables'
|
||||
import { eq } from 'drizzle-orm'
|
||||
|
||||
type Body = {
|
||||
@@ -22,7 +22,6 @@ export async function handler (context: Context) {
|
||||
500
|
||||
)
|
||||
const { connection: connection0, db: db0 } = dbInfo0
|
||||
const { connection: connection1, db: db1 } = dbInfo1
|
||||
|
||||
const ip = getClientIp(context)
|
||||
const authorizationToken = context.headers.authorization
|
||||
@@ -33,7 +32,6 @@ export async function handler (context: Context) {
|
||||
)
|
||||
if (!authResult.valid) {
|
||||
connection0.end()
|
||||
connection1.end()
|
||||
return jsonResponse({ success: false, message: 'Unauthorized' }, 401)
|
||||
}
|
||||
const userId = authResult.id
|
||||
@@ -41,7 +39,6 @@ export async function handler (context: Context) {
|
||||
const body = context.body as Body
|
||||
if (!body.newUsername) {
|
||||
connection0.end()
|
||||
connection1.end()
|
||||
return jsonResponse(
|
||||
{ success: false, message: 'No new username provided' },
|
||||
400
|
||||
@@ -50,7 +47,6 @@ export async function handler (context: Context) {
|
||||
|
||||
if (!/^[a-zA-Z0-9]{3,16}$/.test(body.newUsername)) {
|
||||
connection0.end()
|
||||
connection1.end()
|
||||
return jsonResponse(
|
||||
{
|
||||
success: false,
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Context } from 'elysia'
|
||||
import { getDatabaseConnection, jsonResponse } from '../../../../lib/util'
|
||||
import { berryDashUserData, users } from '../../../../lib/tables'
|
||||
import { getDatabaseConnection, jsonResponse } from '../../../lib/util'
|
||||
import { users } from '../../../lib/tables'
|
||||
import { eq } from 'drizzle-orm'
|
||||
import bcrypt from 'bcryptjs'
|
||||
|
||||
@@ -19,12 +19,10 @@ export async function handler (context: Context) {
|
||||
500
|
||||
)
|
||||
const { connection: connection0, db: db0 } = dbInfo0
|
||||
const { connection: connection1, db: db1 } = dbInfo1
|
||||
|
||||
const body = context.body as Body
|
||||
if (!body.username || !body.password) {
|
||||
connection0.end()
|
||||
connection1.end()
|
||||
return jsonResponse(
|
||||
{
|
||||
success: false,
|
||||
@@ -48,7 +46,6 @@ export async function handler (context: Context) {
|
||||
.execute()
|
||||
if (!user[0]) {
|
||||
connection0.end()
|
||||
connection1.end()
|
||||
return jsonResponse(
|
||||
{
|
||||
success: false,
|
||||
@@ -60,7 +57,6 @@ export async function handler (context: Context) {
|
||||
}
|
||||
if (!(await bcrypt.compare(body.password, user[0].password))) {
|
||||
connection0.end()
|
||||
connection1.end()
|
||||
return jsonResponse(
|
||||
{
|
||||
success: false,
|
||||
@@ -3,10 +3,10 @@ import {
|
||||
getClientIp,
|
||||
getDatabaseConnection,
|
||||
jsonResponse
|
||||
} from '../../../../lib/util'
|
||||
} from '../../../lib/util'
|
||||
import isEmail from 'validator/lib/isEmail'
|
||||
import { berryDashUserData, users, verifyCodes } from '../../../../lib/tables'
|
||||
import { and, desc, eq, or, sql } from 'drizzle-orm'
|
||||
import { berryDashUserData, users, verifyCodes } from '../../../lib/tables'
|
||||
import { and, desc, eq, sql } from 'drizzle-orm'
|
||||
import bcrypt from 'bcryptjs'
|
||||
import { randomBytes } from 'crypto'
|
||||
|
||||
@@ -23,7 +23,7 @@ export async function handler (context: Context) {
|
||||
|
||||
if (!dbInfo0 || !dbInfo1)
|
||||
return jsonResponse(
|
||||
{ success: false, message: 'Failed to connect to database', data: null },
|
||||
{ success: false, message: 'Failed to connect to database' },
|
||||
500
|
||||
)
|
||||
const { connection: connection0, db: db0 } = dbInfo0
|
||||
@@ -36,9 +36,7 @@ export async function handler (context: Context) {
|
||||
return jsonResponse(
|
||||
{
|
||||
success: false,
|
||||
message:
|
||||
'Username, password, email and verifyCode must be in POST data',
|
||||
data: null
|
||||
message: 'Username, password, email and verifyCode must be in POST data'
|
||||
},
|
||||
400
|
||||
)
|
||||
@@ -49,8 +47,7 @@ export async function handler (context: Context) {
|
||||
return jsonResponse(
|
||||
{
|
||||
success: false,
|
||||
message: 'Invalid verify code (codes can only be used once)',
|
||||
data: null
|
||||
message: 'Invalid verify code (codes can only be used once)'
|
||||
},
|
||||
400
|
||||
)
|
||||
@@ -62,8 +59,7 @@ export async function handler (context: Context) {
|
||||
return jsonResponse(
|
||||
{
|
||||
success: false,
|
||||
message: 'Failed to get required info',
|
||||
data: null
|
||||
message: 'Failed to get required info'
|
||||
},
|
||||
400
|
||||
)
|
||||
@@ -99,8 +95,7 @@ export async function handler (context: Context) {
|
||||
return jsonResponse(
|
||||
{
|
||||
success: false,
|
||||
message: 'Invalid verify code (codes can only be used once)',
|
||||
data: null
|
||||
message: 'Invalid verify code (codes can only be used once)'
|
||||
},
|
||||
400
|
||||
)
|
||||
@@ -111,8 +106,7 @@ export async function handler (context: Context) {
|
||||
return jsonResponse(
|
||||
{
|
||||
success: false,
|
||||
message: 'Username must be 3-16 characters, letters and numbers only',
|
||||
data: null
|
||||
message: 'Username must be 3-16 characters, letters and numbers only'
|
||||
},
|
||||
400
|
||||
)
|
||||
@@ -124,8 +118,7 @@ export async function handler (context: Context) {
|
||||
return jsonResponse(
|
||||
{
|
||||
success: false,
|
||||
message: 'Email is invalid',
|
||||
data: null
|
||||
message: 'Email is invalid'
|
||||
},
|
||||
400
|
||||
)
|
||||
@@ -140,8 +133,7 @@ export async function handler (context: Context) {
|
||||
{
|
||||
success: false,
|
||||
message:
|
||||
'Password must be at least 8 characters with at least one letter and one number',
|
||||
data: null
|
||||
'Password must be at least 8 characters with at least one letter and one number'
|
||||
},
|
||||
400
|
||||
)
|
||||
@@ -172,8 +164,7 @@ export async function handler (context: Context) {
|
||||
return jsonResponse(
|
||||
{
|
||||
success: true,
|
||||
message: null,
|
||||
data: null
|
||||
message: null
|
||||
},
|
||||
200
|
||||
)
|
||||
Reference in New Issue
Block a user