blob: ce1a8ad5a754564b600522444b438b3253752974 [file] [log] [blame]
import HCaptcha from 'react-hcaptcha';
import Axios from 'axios';
import Router from 'next/router';
import React from 'react';
import Header from '../../../Components/Header'
import { useReward } from 'react-rewards';
import { Card, CardRow } from '../../../Components/Card';
import { AutoLayout, Panel, Title, Text, Divider } from '../../../Components/Panels';
import { List, ListItem } from '../../../Components/Texttools';
import { useColorMode } from 'theme-ui';
function Verify(props) {
const [clicked, setClicked] = React.useState(false);
const { reward: reward, isAnimating: isAnimating } = useReward('confetti', 'confetti', {
elementSize: 10,
elementCount: 150,
startVelocity: 35,
lifetime: 300,
decay: 0.94,
spread: 170,
position: "absolute",
colors: ["#68D49E"]
});
async function submitForm(tkn) {
if ( clicked ) {
Router.push('/nucleus/verify/alreadyVerified', '/nucleus/verify/success');
}
setClicked(true);
reward();
let code = await Axios.post('/api/nucleus/verify/complete', {
code: props.code,
tkn: tkn
});
setTimeout(() => {
if (code.data.success === true ) return Router.push('/nucleus/verify/success','/nucleus/verify')
else return Router.push('/nucleus/verify/failure','/nucleus/verify')
}, 2500);
}
return <>
<Header
name={props.guild_name}
customImage={props.guild_icon_url}
roundImage={true}
subtext={`Welcome, ${props.username}`}
gradient={["F27878", "D96B6B"]}
wave="web/waves/header/nucleus"
buttons={[]}
season={props.season}
/>
<AutoLayout>
<Panel>
<Title>Verify</Title>
<Divider name="commands"/>
<Text>Complete the check below to join {props.guild_name}</Text>
<div style={{height: "125px"}}>
<HCaptcha
id="Captchas mitigate problems"
sitekey="85074411-fa13-4d9b-b901-53095c6d1fc6"
onVerify={tkn => submitForm(tkn)}
theme="dark"
/>
</div>
<List colour="F27878">
<ListItem>This is an automatic check performed by Nucleus.</ListItem>
<ListItem>By clicking Proceed, you will be given the <code>{props.role_name}</code> role in <code>{props.guild_name}</code>.</ListItem>
<ListItem>For the full list of data stored by Nucleus, please check <a href="https://clickscodes.github.io/policies/nucleus#verification">here</a></ListItem>
</List>
<div id="confetti" />
</Panel>
</AutoLayout>
</>
}
export default Verify;
export async function getServerSideProps(ctx) {
if(!ctx.query.code) {
return {
redirect: {
destination: '/nucleus/verify/about',
permanent: true
}
}
}
let code;
try {
code = await Axios.get(`${process.env.NUCLEUS_CALLBACK}verify/${ctx.query.code}`);
} catch (e) {
return {
redirect: {
destination: '/nucleus/verify/failure',
permanent: true
}
}
}
let headers = ctx.req.headers;
return {
props: {
uID: code.data.uID,
role_name: code.data.rName,
gID: code.data.gID,
guild_name: code.data.gName,
guild_icon_url: code.data.gIcon,
username: code.data.uName,
headers: headers,
code: ctx.query.code
}
}
}