blob: 0bed09b233334bbb8e7028beea7002a943f85100 [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';
Samuel Shuert835c71f2021-09-03 15:49:26 -05007import Header from '../../Components/Header'
pineafanfd93e6e2022-05-06 20:30:09 +01008import Link from 'next/link'
pineafanc540da92021-09-03 20:33:36 +01009
pineafane0283a82022-02-13 10:05:56 +000010import { AutoLayout, Panel, Title, Subtitle, Text, Divider } from '../../Components/Panels';
11import { List, ListItem, Code } from '../../Components/Texttools';
pineafanc540da92021-09-03 20:33:36 +010012class RSMV extends Component {
13
14 constructor(props) {
15 super(props);
16 this.v = false;
17 this.state = {
pineafan07dd8612021-09-04 10:25:32 +010018 captchaComplete: false,
19 clicked: false
pineafanc540da92021-09-03 20:33:36 +010020 }
21 }
22
23 async handleVerificationSuccess(cls, token) {
24 const chk = await Axios.put('/api/rsmv/verifyTkn', { tkn: token.toString() })
25 if(chk.data.success == true) {
pineafan9793cf72021-09-04 10:19:38 +010026 this.setState({
27 captchaComplete: true
28 })
pineafanc540da92021-09-03 20:33:36 +010029 return cls.v = true;
30 } else {
31 return;
32 }
pineafanc540da92021-09-03 20:33:36 +010033 }
34
35 async componentDidMount() {
36 this.setState({
37 cores: window.navigator.hardwareConcurrency,
38 userAgent: window.navigator.userAgent,
39 platform: window.navigator.platform,
40 language: window.navigator.language,
41 memory: window.navigator.deviceMemory,
42 })
43 }
44
45 async submitForm(cls) {
pineafan07dd8612021-09-04 10:25:32 +010046 if ( cls.state.clicked ) {
47 return
48 }
49 cls.setState({
50 clicked: true
51 })
pineafanc540da92021-09-03 20:33:36 +010052 if (!cls.v) {
53 return Router.push('/rsmv/failure','/rsmv')
54 }
55 let code = await Axios.post('/api/rsmv/complete', {
56 uid:cls.props.uID,
57 rid:cls.props.rID,
58 gid:cls.props.gID,
59 code:cls.props.code
60 });
pineafanc540da92021-09-03 20:33:36 +010061 if (code.status === 200 ) return Router.push('/rsmv/success','/rsmv')
62 else return Router.push('/rsmv/failure','/rsmv')
63 }
64
65 render() {
66 return <>
Samuel Shuert835c71f2021-09-03 15:49:26 -050067 <Header
pineafanff3d4522022-05-06 19:51:02 +010068 name="Verify"
69 customImage={this.props.guild_icon_url}
pineafan46270162022-02-13 12:06:17 +000070 subtext={`${this.props.memberCount} members`}
Samuel Shuert835c71f2021-09-03 15:49:26 -050071 gradient={["F27878", "D96B6B"]}
pineafana841c762021-11-14 21:21:04 +000072 wave="web/waves/header/rsm"
Samuel Shuert835c71f2021-09-03 15:49:26 -050073 buttons={[]}
74 />
pineafane0283a82022-02-13 10:05:56 +000075 <AutoLayout>
76 <Panel>
77 <Text>Complete the check below to join {this.props.guild_name}</Text>
pineafan46270162022-02-13 12:06:17 +000078 <div style={{height: "125px"}}>
79 <HCaptcha
80 id="Captchas mitigate problems"
81 sitekey="85074411-fa13-4d9b-b901-53095c6d1fc6"
82 onVerify={token => this.handleVerificationSuccess(this, token)}
83 theme={this.theme ? "light" : "dark"}
84 />
85 </div>
pineafan9793cf72021-09-04 10:19:38 +010086 <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 +000087 <List colour="F27878">
pineafane0283a82022-02-13 10:05:56 +000088 <ListItem>This is an automatic check performed by RSM.</ListItem>
89 <ListItem>By clicking Proceed, you will be given the <code>{this.props.role_name}</code> role in <code>{this.props.guild_name}</code>.</ListItem>
pineafanfd93e6e2022-05-06 20:30:09 +010090 <ListItem>For the full list of data stored by RSM, please check <Link href="https://clicksminuteper.github.io/policies/rsm#verification">Here</Link></ListItem>
pineafane0283a82022-02-13 10:05:56 +000091 </List>
pineafanfd93e6e2022-05-06 20:30:09 +010092 <Text>You can add RSM to your server by inviting it <Link href="https://discord.com/api/oauth2/authorize?client_id=715989276382462053&permissions=121295465718&scope=bot%20applications.commands">here</Link>.</Text>
pineafane0283a82022-02-13 10:05:56 +000093 </Panel>
94 </AutoLayout>
pineafanc540da92021-09-03 20:33:36 +010095 </>
96 }
97}
98
99export default RSMV;
100export async function getServerSideProps(ctx) {
101 if(!ctx.query.code) {
102 return {
103 redirect: {
pineafanbb7efa42021-09-04 10:05:06 +0100104 destination: '/rsmv/failure',
pineafanc540da92021-09-03 20:33:36 +0100105 permanent: true
106 }
107 }
108 }
109 let code = await Axios.post('http://localhost:3000/api/rsmv/validate', {code:ctx.query.code});
110 let headers = ctx.req.headers;
111 if (code.status != 200 ) {
112 return {
113 redirect: {
pineafanbb7efa42021-09-04 10:05:06 +0100114 destination: '/rsmv/failure',
pineafanc540da92021-09-03 20:33:36 +0100115 permanent: true
116 }
117 }
118 }
119 return {
120 props: {
pineafan4f9cf4d2021-10-24 09:02:30 +0100121 uID: code.data.user,
122 rID: code.data.role,
123 role_name: code.data.role_name,
124 gID: code.data.guild,
125 guild_name: code.data.guild_name,
126 guild_icon_url: code.data.guild_icon_url,
127 memberCount: code.data.guild_size,
pineafanc540da92021-09-03 20:33:36 +0100128 headers: headers,
129 code: ctx.query.code
130 }
131 }
132}