blob: 796298a5b8fd9d3cfa0e348374b1713827d6dd50 [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);
15 const [theme, setTheme] = useColorMode()
16
17 if (clicked) {
18 Router.push('/nucleus/verify/alreadyVerified', '/nucleus/verify/success');
19 }
20
21 const { reward: reward, isAnimating: isAnimating } = useReward('confetti', 'confetti', {
22 elementSize: 10,
23 elementCount: 150,
24 startVelocity: 35,
25 lifetime: 300,
26 decay: 0.94,
27 spread: 170,
28 position: "absolute",
29 colors: ["#68D49E"]
30 });
31
32 async function submitForm(tkn) {
33 if ( clicked ) {
34 return
35 }
36 setClicked(true);
37 reward();
38 let code = await Axios.post('/api/nucleus/verify/complete', {
39 code: props.code,
40 tkn: tkn
41 });
42 setTimeout(() => {
43 if (code.data.success === true ) return Router.push('/nucleus/verify/success','/nucleus/verify')
44 else return Router.push('/nucleus/verify/failure','/nucleus/verify')
45 }, 2500);
46 }
47
48 return <>
49 <Header
50 name={props.guild_name}
51 customImage={props.guild_icon_url}
52 roundImage={true}
53 subtext={`${props.memberCount} members`}
54 gradient={["F27878", "D96B6B"]}
55 wave="web/waves/header/nucleus"
56 buttons={[]}
57 />
58 <AutoLayout>
59 <Panel>
60 <Title>Verify</Title>
61 <Divider name="commands"/>
62 <Text>Complete the check below to join {props.guild_name}</Text>
63 <div style={{height: "125px"}}>
64 <HCaptcha
65 id="Captchas mitigate problems"
66 sitekey="85074411-fa13-4d9b-b901-53095c6d1fc6"
67 onVerify={tkn => submitForm(tkn)}
68 theme="dark"
69 />
70 </div>
71 <List colour="F27878">
72 <ListItem>This is an automatic check performed by Nucleus.</ListItem>
73 <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 +010074 <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 +010075 </List>
76 <div id="confetti" />
77 </Panel>
78 <Panel halfSize={false} id="invite">
79 <Title>Invite</Title>
80 <Divider />
81 <CardRow>
82 <Card
83 wave="nucleus"
84 icon="bots/nucleus/circle"
85 buttonText={"FFFFFF"} gradient={["F27878", "D96B6B"]}
86 title="Nucleus"
87 subtext="Invite Nucleus to your server"
88 buttons={[
89 {color: "424242", link: "https://discord.com/api/oauth2/authorize?client_id=715989276382462053&permissions=121295465718&scope=bot%20applications.commands", text: "Invite"}
90 ]}
91 url="https://discord.com/api/oauth2/authorize?client_id=715989276382462053&permissions=121295465718&scope=bot%20applications.commands"
92 />
93 </CardRow>
94 </Panel>
95 </AutoLayout>
96 </>
97}
98
99export default Verify;
100export async function getServerSideProps(ctx) {
101 if(!ctx.query.code) {
102 return {
103 redirect: {
104 destination: '/nucleus/verify/about',
105 permanent: true
106 }
107 }
108 }
109 let code;
110 try {
111 await Axios.patch(`http://localhost:10000/verify/${ctx.query.code}`);
112 code = await Axios.get(`http://localhost:10000/verify/${ctx.query.code}`, {code:ctx.query.code});
113 } catch (e) {
114 return {
115 redirect: {
116 destination: '/nucleus/verify/failure',
117 permanent: true
118 }
119 }
120 }
121 let headers = ctx.req.headers;
122 return {
123 props: {
124 uID: code.data.uID,
125 role_name: code.data.rName,
126 gID: code.data.gID,
127 guild_name: code.data.gName,
128 guild_icon_url: code.data.gIcon,
129 memberCount: code.data.mCount,
130 headers: headers,
131 code: ctx.query.code
132 }
133 }
134}