mirror of
https://github.com/koreanbots/core.git
synced 2025-12-16 14:30:22 +00:00
feat(api): blocking blocked user
This commit is contained in:
parent
306d9118a9
commit
e5a5f0534d
@ -56,7 +56,8 @@ const Callback = RequestHandler().get(async (req: ApiRequest, res) => {
|
|||||||
verified: user.verified
|
verified: user.verified
|
||||||
})
|
})
|
||||||
|
|
||||||
if(!userToken) return res.redirect(301, 'https://docs.koreanbots.dev/bots/account/unverified')
|
if(userToken === 1) return res.redirect(301, 'https://docs.koreanbots.dev/bots/account/unverified')
|
||||||
|
else if(userToken === 2) return res.redirect(301, 'https://docs.koreanbots.dev/bots/account/blocked')
|
||||||
const info = verify(userToken)
|
const info = verify(userToken)
|
||||||
res.setHeader(
|
res.setHeader(
|
||||||
'set-cookie',
|
'set-cookie',
|
||||||
|
|||||||
@ -324,15 +324,22 @@ async function getDiscordUser(id: string):Promise<DiscordUser> {
|
|||||||
return DiscordBot.users.cache.get(id) ?? await DiscordBot.users.fetch(id, false, true).then(u => u.toJSON()).catch(()=>null)
|
return DiscordBot.users.cache.get(id) ?? await DiscordBot.users.fetch(id, false, true).then(u => u.toJSON()).catch(()=>null)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function assignToken(info: TokenRegister):Promise<string|null> {
|
/**
|
||||||
let token = await knex('users').select(['token']).where({ id: info.id })
|
*
|
||||||
|
* @param info
|
||||||
|
* @returns 1 - UnVerified
|
||||||
|
* @returns 2 - Blocked
|
||||||
|
*/
|
||||||
|
async function assignToken(info: TokenRegister):Promise<string|1|2> {
|
||||||
|
let token = await knex('users').select(['token', 'perm']).where({ id: info.id })
|
||||||
let t: string
|
let t: string
|
||||||
if(!info.verified) return null
|
if(!info.verified) return 1
|
||||||
if(token.length === 0) {
|
if(token.length === 0) {
|
||||||
t = sign({ id: info.id }, { expiresIn: '30d' })
|
t = sign({ id: info.id }, { expiresIn: '30d' })
|
||||||
await knex('users').insert({ token: t, date: Math.round(Number(new Date()) / 1000), id: info.id, email: info.email, tag: info.discriminator, username: info.username, discord: sign({ access_token: info.access_token, expires_in: info.expires_in, refresh_token: info.refresh_token }) })
|
await knex('users').insert({ token: t, date: Math.round(Number(new Date()) / 1000), id: info.id, email: info.email, tag: info.discriminator, username: info.username, discord: sign({ access_token: info.access_token, expires_in: info.expires_in, refresh_token: info.refresh_token }) })
|
||||||
token = await knex('users').select(['token']).where({ id: info.id })
|
token = await knex('users').select(['token']).where({ id: info.id })
|
||||||
} else await knex('users').update({ email: info.email, tag: info.discriminator, username: info.username, discord: sign({ access_token: info.access_token, expires_in: info.expires_in, refresh_token: info.refresh_token }) }).where({ id: info.id })
|
} else await knex('users').update({ email: info.email, tag: info.discriminator, username: info.username, discord: sign({ access_token: info.access_token, expires_in: info.expires_in, refresh_token: info.refresh_token }) }).where({ id: info.id })
|
||||||
|
if(token[0].perm !== 'user') return 2
|
||||||
if(!verify(token[0]?.token ?? '')) {
|
if(!verify(token[0]?.token ?? '')) {
|
||||||
t = sign({ id: info.id }, { expiresIn: '30d' })
|
t = sign({ id: info.id }, { expiresIn: '30d' })
|
||||||
await knex('users').update({ token: t }).where({ id: info.id })
|
await knex('users').update({ token: t }).where({ id: info.id })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user