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