blob: 38a3aeafc726c2b864698dce540ca6eb8ad86064 [file] [log] [blame]
pineafanfd93e6e2022-05-06 20:30:09 +01001import HCaptcha from 'react-hcaptcha';
2import Axios from 'axios';
3import Router from 'next/router';
4import React from 'react';
5import Header from '../../../Components/Header'
6import { useReward } from 'react-rewards';
pineafan3b0852d2022-05-06 20:39:59 +01007import { Card, CardRow } from '../../../Components/Card';
pineafanfd93e6e2022-05-06 20:30:09 +01008
9import { AutoLayout, Panel, Title, Text, Divider } from '../../../Components/Panels';
10import { List, ListItem } from '../../../Components/Texttools';
11import { useColorMode } from 'theme-ui';
12
13function Verify(props) {
14 const [clicked, setClicked] = React.useState(false);
pineafanfd93e6e2022-05-06 20:30:09 +010015
pineafanfd93e6e2022-05-06 20:30:09 +010016 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 ) {
pineafanaa9c4fd2022-06-10 19:58:10 +010029 Router.push('/nucleus/verify/alreadyVerified', '/nucleus/verify/success');
pineafanfd93e6e2022-05-06 20:30:09 +010030 }
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}
pineafan9babd752022-10-21 21:47:52 +010048 subtext={`Welcome, ${props.username}`}
pineafanfd93e6e2022-05-06 20:30:09 +010049 gradient={["F27878", "D96B6B"]}
50 wave="web/waves/header/nucleus"
51 buttons={[]}
52 />
53 <AutoLayout>
54 <Panel>
55 <Title>Verify</Title>
56 <Divider name="commands"/>
57 <Text>Complete the check below to join {props.guild_name}</Text>
58 <div style={{height: "125px"}}>
59 <HCaptcha
60 id="Captchas mitigate problems"
61 sitekey="85074411-fa13-4d9b-b901-53095c6d1fc6"
62 onVerify={tkn => submitForm(tkn)}
63 theme="dark"
64 />
65 </div>
66 <List colour="F27878">
67 <ListItem>This is an automatic check performed by Nucleus.</ListItem>
68 <ListItem>By clicking Proceed, you will be given the <code>{props.role_name}</code> role in <code>{props.guild_name}</code>.</ListItem>
pineafan3b0852d2022-05-06 20:39:59 +010069 <ListItem>For the full list of data stored by Nucleus, please check <a href="https://clicksminuteper.github.io/policies/nucleus#verification">here</a></ListItem>
pineafanfd93e6e2022-05-06 20:30:09 +010070 </List>
71 <div id="confetti" />
72 </Panel>
pineafanfd93e6e2022-05-06 20:30:09 +010073 </AutoLayout>
74 </>
75}
76
77export default Verify;
78export async function getServerSideProps(ctx) {
79 if(!ctx.query.code) {
80 return {
81 redirect: {
82 destination: '/nucleus/verify/about',
83 permanent: true
84 }
85 }
86 }
87 let code;
88 try {
pineafan9babd752022-10-21 21:47:52 +010089 code = await Axios.get(`http://localhost:10000/verify/${ctx.query.code}`);
pineafanfd93e6e2022-05-06 20:30:09 +010090 } catch (e) {
91 return {
92 redirect: {
93 destination: '/nucleus/verify/failure',
94 permanent: true
95 }
96 }
97 }
98 let headers = ctx.req.headers;
99 return {
100 props: {
101 uID: code.data.uID,
102 role_name: code.data.rName,
103 gID: code.data.gID,
104 guild_name: code.data.gName,
105 guild_icon_url: code.data.gIcon,
pineafan9babd752022-10-21 21:47:52 +0100106 username: code.data.uName,
pineafanfd93e6e2022-05-06 20:30:09 +0100107 headers: headers,
108 code: ctx.query.code
109 }
110 }
111}