pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame] | 1 | import HCaptcha from 'react-hcaptcha'; |
| 2 | import Axios from 'axios'; |
| 3 | import Router from 'next/router'; |
| 4 | import React from 'react'; |
| 5 | import Header from '../../../Components/Header' |
| 6 | import { useReward } from 'react-rewards'; |
pineafan | 3b0852d | 2022-05-06 20:39:59 +0100 | [diff] [blame] | 7 | import { Card, CardRow } from '../../../Components/Card'; |
pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame] | 8 | |
| 9 | import { AutoLayout, Panel, Title, Text, Divider } from '../../../Components/Panels'; |
| 10 | import { List, ListItem } from '../../../Components/Texttools'; |
| 11 | import { useColorMode } from 'theme-ui'; |
| 12 | |
| 13 | function Verify(props) { |
| 14 | const [clicked, setClicked] = React.useState(false); |
pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame] | 15 | |
pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame] | 16 | const { reward: reward, isAnimating: isAnimating } = useReward('confetti', 'confetti', { |
| 17 | elementSize: 10, |
| 18 | elementCount: 150, |
| 19 | startVelocity: 35, |
| 20 | lifetime: 300, |
| 21 | decay: 0.94, |
| 22 | spread: 170, |
| 23 | position: "absolute", |
| 24 | colors: ["#68D49E"] |
| 25 | }); |
| 26 | |
| 27 | async function submitForm(tkn) { |
| 28 | if ( clicked ) { |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 29 | Router.push('/nucleus/verify/alreadyVerified', '/nucleus/verify/success'); |
pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame] | 30 | } |
| 31 | setClicked(true); |
| 32 | reward(); |
| 33 | let code = await Axios.post('/api/nucleus/verify/complete', { |
| 34 | code: props.code, |
| 35 | tkn: tkn |
| 36 | }); |
| 37 | setTimeout(() => { |
| 38 | if (code.data.success === true ) return Router.push('/nucleus/verify/success','/nucleus/verify') |
| 39 | else return Router.push('/nucleus/verify/failure','/nucleus/verify') |
| 40 | }, 2500); |
| 41 | } |
| 42 | |
| 43 | return <> |
| 44 | <Header |
| 45 | name={props.guild_name} |
| 46 | customImage={props.guild_icon_url} |
| 47 | roundImage={true} |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 48 | subtext={`Welcome, ${props.username}`} |
pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame] | 49 | gradient={["F27878", "D96B6B"]} |
| 50 | wave="web/waves/header/nucleus" |
| 51 | buttons={[]} |
PineaFan | a465f35 | 2023-02-05 16:45:01 +0000 | [diff] [blame] | 52 | season={props.season} |
pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame] | 53 | /> |
| 54 | <AutoLayout> |
| 55 | <Panel> |
| 56 | <Title>Verify</Title> |
| 57 | <Divider name="commands"/> |
| 58 | <Text>Complete the check below to join {props.guild_name}</Text> |
| 59 | <div style={{height: "125px"}}> |
| 60 | <HCaptcha |
| 61 | id="Captchas mitigate problems" |
| 62 | sitekey="85074411-fa13-4d9b-b901-53095c6d1fc6" |
| 63 | onVerify={tkn => submitForm(tkn)} |
| 64 | theme="dark" |
| 65 | /> |
| 66 | </div> |
| 67 | <List colour="F27878"> |
| 68 | <ListItem>This is an automatic check performed by Nucleus.</ListItem> |
| 69 | <ListItem>By clicking Proceed, you will be given the <code>{props.role_name}</code> role in <code>{props.guild_name}</code>.</ListItem> |
pineafan | 3b0852d | 2022-05-06 20:39:59 +0100 | [diff] [blame] | 70 | <ListItem>For the full list of data stored by Nucleus, please check <a href="https://clicksminuteper.github.io/policies/nucleus#verification">here</a></ListItem> |
pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame] | 71 | </List> |
| 72 | <div id="confetti" /> |
| 73 | </Panel> |
pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame] | 74 | </AutoLayout> |
| 75 | </> |
| 76 | } |
| 77 | |
| 78 | export default Verify; |
| 79 | export async function getServerSideProps(ctx) { |
| 80 | if(!ctx.query.code) { |
| 81 | return { |
| 82 | redirect: { |
| 83 | destination: '/nucleus/verify/about', |
| 84 | permanent: true |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | let code; |
| 89 | try { |
Skyler Grey | 6c3d463 | 2023-03-06 09:51:21 +0000 | [diff] [blame] | 90 | code = await Axios.get(`${process.env.NUCLEUS_CALLBACK}verify/${ctx.query.code}`); |
pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame] | 91 | } catch (e) { |
| 92 | return { |
| 93 | redirect: { |
| 94 | destination: '/nucleus/verify/failure', |
| 95 | permanent: true |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | let headers = ctx.req.headers; |
| 100 | return { |
| 101 | props: { |
| 102 | uID: code.data.uID, |
| 103 | role_name: code.data.rName, |
| 104 | gID: code.data.gID, |
| 105 | guild_name: code.data.gName, |
| 106 | guild_icon_url: code.data.gIcon, |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 107 | username: code.data.uName, |
pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame] | 108 | headers: headers, |
| 109 | code: ctx.query.code |
| 110 | } |
| 111 | } |
Skyler Grey | 6c3d463 | 2023-03-06 09:51:21 +0000 | [diff] [blame] | 112 | } |