mirror of
https://github.com/koreanbots/core.git
synced 2025-12-17 06:40:24 +00:00
feat(api): blocking unverified user
This commit is contained in:
parent
86621cc4a5
commit
306d9118a9
@ -53,7 +53,10 @@ const Callback = RequestHandler().get(async (req: ApiRequest, res) => {
|
|||||||
email: user.email,
|
email: user.email,
|
||||||
username: user.username,
|
username: user.username,
|
||||||
discriminator: user.discriminator,
|
discriminator: user.discriminator,
|
||||||
|
verified: user.verified
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if(!userToken) return res.redirect(301, 'https://docs.koreanbots.dev/bots/account/unverified')
|
||||||
const info = verify(userToken)
|
const info = verify(userToken)
|
||||||
res.setHeader(
|
res.setHeader(
|
||||||
'set-cookie',
|
'set-cookie',
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { NextPage} from 'next'
|
import { NextPage } from 'next'
|
||||||
import dynamic from 'next/dynamic'
|
import dynamic from 'next/dynamic'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
|
|||||||
@ -130,6 +130,7 @@ export interface TokenRegister {
|
|||||||
email: string
|
email: string
|
||||||
username: string
|
username: string
|
||||||
discriminator: string
|
discriminator: string
|
||||||
|
verified: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DiscordUserInfo {
|
export interface DiscordUserInfo {
|
||||||
|
|||||||
@ -324,9 +324,10 @@ 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> {
|
async function assignToken(info: TokenRegister):Promise<string|null> {
|
||||||
let token = await knex('users').select(['token']).where({ id: info.id })
|
let token = await knex('users').select(['token']).where({ id: info.id })
|
||||||
let t: string
|
let t: string
|
||||||
|
if(!info.verified) return null
|
||||||
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 }) })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user