blob: f46c46eb4b24c4cd1342e0f0dd7a61f659c17331 [file] [log] [blame]
pineafanc540da92021-09-03 20:33:36 +01001import { Component } from 'react';
2import Styles from '../../styles/rsmv/rsmv.module.css'
Samuel Shuert835c71f2021-09-03 15:49:26 -05003import HCaptcha from 'react-hcaptcha';
pineafanc540da92021-09-03 20:33:36 +01004import Axios from 'axios';
5import Router from 'next/router';
6import React from 'react';
pineafan3b0852d2022-05-06 20:39:59 +01007import Header from '../../Components/Header';
pineafanc540da92021-09-03 20:33:36 +01008
pineafane0283a82022-02-13 10:05:56 +00009import { AutoLayout, Panel, Title, Subtitle, Text, Divider } from '../../Components/Panels';
10import { List, ListItem, Code } from '../../Components/Texttools';
pineafanc540da92021-09-03 20:33:36 +010011class RSMV extends Component {
12
13 constructor(props) {
14 super(props);
15 this.v = false;
16 this.state = {
pineafan07dd8612021-09-04 10:25:32 +010017 captchaComplete: false,
18 clicked: false
pineafanc540da92021-09-03 20:33:36 +010019 }
20 }
21
22 async handleVerificationSuccess(cls, token) {
23 const chk = await Axios.put('/api/rsmv/verifyTkn', { tkn: token.toString() })
24 if(chk.data.success == true) {
pineafan9793cf72021-09-04 10:19:38 +010025 this.setState({
26 captchaComplete: true
27 })
pineafanc540da92021-09-03 20:33:36 +010028 return cls.v = true;
29 } else {
30 return;
31 }
pineafanc540da92021-09-03 20:33:36 +010032 }
33
34 async componentDidMount() {
35 this.setState({
36 cores: window.navigator.hardwareConcurrency,
37 userAgent: window.navigator.userAgent,
38 platform: window.navigator.platform,
39 language: window.navigator.language,
40 memory: window.navigator.deviceMemory,
41 })
42 }
43
44 async submitForm(cls) {
pineafan07dd8612021-09-04 10:25:32 +010045 if ( cls.state.clicked ) {
46 return
47 }
48 cls.setState({
49 clicked: true
50 })
pineafanc540da92021-09-03 20:33:36 +010051 if (!cls.v) {
52 return Router.push('/rsmv/failure','/rsmv')
53 }
54 let code = await Axios.post('/api/rsmv/complete', {
55 uid:cls.props.uID,
56 rid:cls.props.rID,
57 gid:cls.props.gID,
58 code:cls.props.code
59 });
pineafanc540da92021-09-03 20:33:36 +010060 if (code.status === 200 ) return Router.push('/rsmv/success','/rsmv')
61 else return Router.push('/rsmv/failure','/rsmv')
62 }
63
64 render() {
65 return <>
Samuel Shuert835c71f2021-09-03 15:49:26 -050066 <Header
pineafanff3d4522022-05-06 19:51:02 +010067 name="Verify"
68 customImage={this.props.guild_icon_url}
pineafan46270162022-02-13 12:06:17 +000069 subtext={`${this.props.memberCount} members`}
Samuel Shuert835c71f2021-09-03 15:49:26 -050070 gradient={["F27878", "D96B6B"]}
pineafana841c762021-11-14 21:21:04 +000071 wave="web/waves/header/rsm"
Samuel Shuert835c71f2021-09-03 15:49:26 -050072 buttons={[]}
73 />
pineafane0283a82022-02-13 10:05:56 +000074 <AutoLayout>
75 <Panel>
76 <Text>Complete the check below to join {this.props.guild_name}</Text>
pineafan46270162022-02-13 12:06:17 +000077 <div style={{height: "125px"}}>
78 <HCaptcha
79 id="Captchas mitigate problems"
80 sitekey="85074411-fa13-4d9b-b901-53095c6d1fc6"
81 onVerify={token => this.handleVerificationSuccess(this, token)}
82 theme={this.theme ? "light" : "dark"}
83 />
84 </div>
pineafan9793cf72021-09-04 10:19:38 +010085 <button type="button" className={Styles.button + " " + (this.state.captchaComplete ? Styles.buttonComplete : null)} onClick={(success) => this.submitForm(this)}>Proceed</button>
pineafan46270162022-02-13 12:06:17 +000086 <List colour="F27878">
pineafane0283a82022-02-13 10:05:56 +000087 <ListItem>This is an automatic check performed by RSM.</ListItem>
88 <ListItem>By clicking Proceed, you will be given the <code>{this.props.role_name}</code> role in <code>{this.props.guild_name}</code>.</ListItem>
pineafan3b0852d2022-05-06 20:39:59 +010089 <ListItem>For the full list of data stored by RSM, please check <a href="https://clicksminuteper.github.io/policies/rsm#verification">Here</a></ListItem>
pineafane0283a82022-02-13 10:05:56 +000090 </List>
pineafan3b0852d2022-05-06 20:39:59 +010091 <Text>You can add RSM to your server by inviting it <a href="https://discord.com/api/oauth2/authorize?client_id=715989276382462053&permissions=121295465718&scope=bot%20applications.commands">here</a>.</Text>
pineafane0283a82022-02-13 10:05:56 +000092 </Panel>
93 </AutoLayout>
pineafanc540da92021-09-03 20:33:36 +010094 </>
95 }
96}
97
98export default RSMV;
99export async function getServerSideProps(ctx) {
100 if(!ctx.query.code) {
101 return {
102 redirect: {
pineafanbb7efa42021-09-04 10:05:06 +0100103 destination: '/rsmv/failure',
pineafanc540da92021-09-03 20:33:36 +0100104 permanent: true
105 }
106 }
107 }
108 let code = await Axios.post('http://localhost:3000/api/rsmv/validate', {code:ctx.query.code});
109 let headers = ctx.req.headers;
110 if (code.status != 200 ) {
111 return {
112 redirect: {
pineafanbb7efa42021-09-04 10:05:06 +0100113 destination: '/rsmv/failure',
pineafanc540da92021-09-03 20:33:36 +0100114 permanent: true
115 }
116 }
117 }
118 return {
119 props: {
pineafan4f9cf4d2021-10-24 09:02:30 +0100120 uID: code.data.user,
121 rID: code.data.role,
122 role_name: code.data.role_name,
123 gID: code.data.guild,
124 guild_name: code.data.guild_name,
125 guild_icon_url: code.data.guild_icon_url,
126 memberCount: code.data.guild_size,
pineafanc540da92021-09-03 20:33:36 +0100127 headers: headers,
128 code: ctx.query.code
129 }
130 }
131}