mirror of
https://github.com/koreanbots/core.git
synced 2025-12-17 06:40:24 +00:00
feat: added reset token button
This commit is contained in:
parent
baf13c2c9e
commit
501c33c137
@ -23,8 +23,9 @@ const ResetApplication = RequestHandler
|
|||||||
const bot = await get.bot.load(req.query.id)
|
const bot = await get.bot.load(req.query.id)
|
||||||
if(!bot) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 봇입니다.' })
|
if(!bot) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 봇입니다.' })
|
||||||
if(!(bot.owners as User[]).find(el => el.id === user)) return ResponseWrapper(res, { code: 403 })
|
if(!(bot.owners as User[]).find(el => el.id === user)) return ResponseWrapper(res, { code: 403 })
|
||||||
await update.resetBotToken(req.query.id, validated.token)
|
const d = await update.resetBotToken(req.query.id, validated.token)
|
||||||
return ResponseWrapper(res, { code: 200 })
|
if(!d) return ResponseWrapper(res, { code: 500, message: '무언가 잘못되었습니다.' })
|
||||||
|
return ResponseWrapper(res, { code: 200, data: { token: d }})
|
||||||
})
|
})
|
||||||
|
|
||||||
interface ApiRequest extends NextApiRequest {
|
interface ApiRequest extends NextApiRequest {
|
||||||
|
|||||||
@ -17,7 +17,6 @@ import { Bot, BotSpec, ResponseProps, Theme } from '@types'
|
|||||||
import NotFound from 'pages/404'
|
import NotFound from 'pages/404'
|
||||||
|
|
||||||
const Button = dynamic(() => import('@components/Button'))
|
const Button = dynamic(() => import('@components/Button'))
|
||||||
const Divider = dynamic(() => import('@components/Divider'))
|
|
||||||
const Input = dynamic(() => import('@components/Form/Input'))
|
const Input = dynamic(() => import('@components/Form/Input'))
|
||||||
const DeveloperLayout = dynamic(() => import('@components/DeveloperLayout'))
|
const DeveloperLayout = dynamic(() => import('@components/DeveloperLayout'))
|
||||||
const DiscordAvatar = dynamic(() => import('@components/DiscordAvatar'))
|
const DiscordAvatar = dynamic(() => import('@components/DiscordAvatar'))
|
||||||
@ -40,6 +39,16 @@ const BotApplication: NextPage<BotApplicationProps> = ({ user, spec, bot, theme,
|
|||||||
setData(res)
|
setData(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function resetToken() {
|
||||||
|
const res = await Fetch<{ token: string }>(`/applications/bots/${bot.id}/reset`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ token: spec.token, _csrf: csrfToken })
|
||||||
|
})
|
||||||
|
setData(res)
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
if(!user) {
|
if(!user) {
|
||||||
localStorage.redirectTo = window.location.href
|
localStorage.redirectTo = window.location.href
|
||||||
redirectTo(router, 'login')
|
redirectTo(router, 'login')
|
||||||
@ -76,13 +85,7 @@ const BotApplication: NextPage<BotApplicationProps> = ({ user, spec, bot, theme,
|
|||||||
<Button onClick={() => setShowToken(!showToken)}>{showToken ? '숨기기' : '보기'}</Button>
|
<Button onClick={() => setShowToken(!showToken)}>{showToken ? '숨기기' : '보기'}</Button>
|
||||||
<Button onClick={setTokenCopied} className={tokenCopied ? 'bg-green-400 text-white' : null}>{tokenCopied ? '복사됨' : '복사'}</Button>
|
<Button onClick={setTokenCopied} className={tokenCopied ? 'bg-green-400 text-white' : null}>{tokenCopied ? '복사됨' : '복사'}</Button>
|
||||||
<Button onClick={()=> setModalOpen(true)}>재발급</Button>
|
<Button onClick={()=> setModalOpen(true)}>재발급</Button>
|
||||||
<Modal isOpen={modalOpened} onClose={() => setModalOpen(false)} dark={theme === 'dark'} header='정말로 토큰을 재발급하시겠습니까?'>
|
|
||||||
<p>기존에 사용중이시던 토큰은 더 이상 사용하실 수 없습니다</p>
|
|
||||||
<div className='text-right pt-6'>
|
|
||||||
<Button className='bg-gray-500 hover:opacity-90' onClick={()=> setModalOpen(false)}>취소</Button>
|
|
||||||
<Button>재발급</Button>
|
|
||||||
</div>
|
|
||||||
</Modal>
|
|
||||||
</div>
|
</div>
|
||||||
<Formik validationSchema={DeveloperBotSchema} initialValues={{
|
<Formik validationSchema={DeveloperBotSchema} initialValues={{
|
||||||
webhook: spec.webhook || '',
|
webhook: spec.webhook || '',
|
||||||
@ -98,6 +101,17 @@ const BotApplication: NextPage<BotApplicationProps> = ({ user, spec, bot, theme,
|
|||||||
{touched.webhook && errors.webhook ? <div className='text-red-500 text-xs font-light mt-1'>{errors.webhook}</div> : null}
|
{touched.webhook && errors.webhook ? <div className='text-red-500 text-xs font-light mt-1'>{errors.webhook}</div> : null}
|
||||||
</div>
|
</div>
|
||||||
<Button type='submit'><i className='far fa-save'/> 저장</Button>
|
<Button type='submit'><i className='far fa-save'/> 저장</Button>
|
||||||
|
<Modal isOpen={modalOpened} onClose={() => setModalOpen(false)} dark={theme === 'dark'} header='정말로 토큰을 재발급하시겠습니까?'>
|
||||||
|
<p>기존에 사용중이시던 토큰은 더 이상 사용하실 수 없습니다</p>
|
||||||
|
<div className='text-right pt-6'>
|
||||||
|
<Button className='bg-gray-500 hover:opacity-90' onClick={()=> setModalOpen(false)}>취소</Button>
|
||||||
|
<Button onClick={async ()=> {
|
||||||
|
const res = await resetToken()
|
||||||
|
spec.token = res.data.token
|
||||||
|
setModalOpen(false)
|
||||||
|
}}>재발급</Button>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
</Form>
|
</Form>
|
||||||
)}
|
)}
|
||||||
</Formik>
|
</Formik>
|
||||||
|
|||||||
@ -226,8 +226,16 @@ async function getBotSpec(id: string, userID: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function updateBotApplication(id: string, value: { webhook: string }) {
|
async function updateBotApplication(id: string, value: { webhook: string }) {
|
||||||
const res = await knex('bots').update({ webhook: value.webhook }).where({ id })
|
const bot = await knex('bots').update({ webhook: value.webhook }).where({ id })
|
||||||
return
|
if(bot !== 1) return false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resetBotToken(id: string, beforeToken: string) {
|
||||||
|
const token = sign({ id })
|
||||||
|
const bot = await knex('bots').update({ token }).where({ id, token: beforeToken })
|
||||||
|
if(bot !== 1) return null
|
||||||
|
return token
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getImage(url: string) {
|
async function getImage(url: string) {
|
||||||
@ -343,7 +351,8 @@ export const get = {
|
|||||||
|
|
||||||
export const update = {
|
export const update = {
|
||||||
assignToken,
|
assignToken,
|
||||||
updateBotApplication
|
updateBotApplication,
|
||||||
|
resetBotToken
|
||||||
}
|
}
|
||||||
|
|
||||||
export const put = {
|
export const put = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user