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); |
| 15 | const [theme, setTheme] = useColorMode() |
| 16 | |
pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame] | 17 | const { reward: reward, isAnimating: isAnimating } = useReward('confetti', 'confetti', { |
| 18 | elementSize: 10, |
| 19 | elementCount: 150, |
| 20 | startVelocity: 35, |
| 21 | lifetime: 300, |
| 22 | decay: 0.94, |
| 23 | spread: 170, |
| 24 | position: "absolute", |
| 25 | colors: ["#68D49E"] |
| 26 | }); |
| 27 | |
| 28 | async function submitForm(tkn) { |
| 29 | if ( clicked ) { |
pineafan | aa9c4fd | 2022-06-10 19:58:10 +0100 | [diff] [blame] | 30 | Router.push('/nucleus/verify/alreadyVerified', '/nucleus/verify/success'); |
pineafan | fd93e6e | 2022-05-06 20:30:09 +0100 | [diff] [blame] | 31 | } |
| 32 | setClicked(true); |
| 33 | reward(); |
| 34 | let code = await Axios.post('/api/nucleus/verify/complete', { |
| 35 | code: props.code, |
| 36 | tkn: tkn |
| 37 | }); |
| 38 | setTimeout(() => { |
| 39 | if (code.data.success === true ) return Router.push('/nucleus/verify/success','/nucleus/verify') |
| 40 | else return Router.push('/nucleus/verify/failure','/nucleus/verify') |
| 41 | }, 2500); |
| 42 | } |
| 43 | |
| 44 | return <> |
| 45 | <Header |
| 46 | name={props.guild_name} |
| 47 | customImage={props.guild_icon_url} |
| 48 | roundImage={true} |
| 49 | subtext={`${props.memberCount} members`} |
| 50 | gradient={["F27878", "D96B6B"]} |
| 51 | wave="web/waves/header/nucleus" |
| 52 | buttons={[]} |
| 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> |
| 74 | <Panel halfSize={false} id="invite"> |
| 75 | <Title>Invite</Title> |
| 76 | <Divider /> |
| 77 | <CardRow> |
| 78 | <Card |
| 79 | wave="nucleus" |
| 80 | icon="bots/nucleus/circle" |
| 81 | buttonText={"FFFFFF"} gradient={["F27878", "D96B6B"]} |
| 82 | title="Nucleus" |
| 83 | subtext="Invite Nucleus to your server" |
| 84 | buttons={[ |
| 85 | {color: "424242", link: "https://discord.com/api/oauth2/authorize?client_id=715989276382462053&permissions=121295465718&scope=bot%20applications.commands", text: "Invite"} |
| 86 | ]} |
| 87 | url="https://discord.com/api/oauth2/authorize?client_id=715989276382462053&permissions=121295465718&scope=bot%20applications.commands" |
| 88 | /> |
| 89 | </CardRow> |
| 90 | </Panel> |
| 91 | </AutoLayout> |
| 92 | </> |
| 93 | } |
| 94 | |
| 95 | export default Verify; |
| 96 | export async function getServerSideProps(ctx) { |
| 97 | if(!ctx.query.code) { |
| 98 | return { |
| 99 | redirect: { |
| 100 | destination: '/nucleus/verify/about', |
| 101 | permanent: true |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | let code; |
| 106 | try { |
| 107 | await Axios.patch(`http://localhost:10000/verify/${ctx.query.code}`); |
| 108 | code = await Axios.get(`http://localhost:10000/verify/${ctx.query.code}`, {code:ctx.query.code}); |
| 109 | } catch (e) { |
| 110 | return { |
| 111 | redirect: { |
| 112 | destination: '/nucleus/verify/failure', |
| 113 | permanent: true |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | let headers = ctx.req.headers; |
| 118 | return { |
| 119 | props: { |
| 120 | uID: code.data.uID, |
| 121 | role_name: code.data.rName, |
| 122 | gID: code.data.gID, |
| 123 | guild_name: code.data.gName, |
| 124 | guild_icon_url: code.data.gIcon, |
| 125 | memberCount: code.data.mCount, |
| 126 | headers: headers, |
| 127 | code: ctx.query.code |
| 128 | } |
| 129 | } |
| 130 | } |