blob: b05f5813f89cd7c3333dd065dcf5ea8fc023da66 [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'
pineafanc540da92021-09-03 20:33:36 +01008
9class RSMV extends Component {
10
11 constructor(props) {
12 super(props);
13 this.v = false;
14 this.state = {
pineafan9793cf72021-09-04 10:19:38 +010015 captchaComplete: false
pineafanc540da92021-09-03 20:33:36 +010016 }
17 }
18
19 async handleVerificationSuccess(cls, token) {
20 const chk = await Axios.put('/api/rsmv/verifyTkn', { tkn: token.toString() })
21 if(chk.data.success == true) {
pineafan9793cf72021-09-04 10:19:38 +010022 this.setState({
23 captchaComplete: true
24 })
pineafanc540da92021-09-03 20:33:36 +010025 return cls.v = true;
26 } else {
27 return;
28 }
29
30 }
31
32 async componentDidMount() {
33 this.setState({
34 cores: window.navigator.hardwareConcurrency,
35 userAgent: window.navigator.userAgent,
36 platform: window.navigator.platform,
37 language: window.navigator.language,
38 memory: window.navigator.deviceMemory,
39 })
40 }
41
42 async submitForm(cls) {
43 if (!cls.v) {
44 return Router.push('/rsmv/failure','/rsmv')
45 }
46 let code = await Axios.post('/api/rsmv/complete', {
47 uid:cls.props.uID,
48 rid:cls.props.rID,
49 gid:cls.props.gID,
50 code:cls.props.code
51 });
52 console.log(code.status)
53 if (code.status === 200 ) return Router.push('/rsmv/success','/rsmv')
54 else return Router.push('/rsmv/failure','/rsmv')
55 }
56
57 render() {
58 return <>
Samuel Shuert835c71f2021-09-03 15:49:26 -050059 <Header
pineafanab7f5ac2021-09-04 09:56:38 +010060 name={<><img alt="Server icon" style={{borderRadius: "50%", height: "128px", width: "auto"}} src={this.props.guild_icon_url} /><br />{this.props.guild_name}</>}
Samuel Shuert835c71f2021-09-03 15:49:26 -050061 subtext={` ${this.props.memberCount} members`}
62 gradient={["F27878", "D96B6B"]}
63 wave="RM"
64 buttons={[]}
65 />
66 <div id="start">
67 <div className={Styles.center}>
68 <p className={Styles.text}>Complete the check below to join {this.props.guild_name}</p>
pineafanc540da92021-09-03 20:33:36 +010069 <HCaptcha
70 id="Captchas mitigate problems"
71 sitekey="85074411-fa13-4d9b-b901-53095c6d1fc6"
72 onVerify={token => this.handleVerificationSuccess(this, token)}
73 />
pineafan9793cf72021-09-04 10:19:38 +010074 <button type="button" className={Styles.button + " " + (this.state.captchaComplete ? Styles.buttonComplete : null)} onClick={(success) => this.submitForm(this)}>Proceed</button>
Samuel Shuert835c71f2021-09-03 15:49:26 -050075 <p className={Styles.text}>
76 This is an automatic check performed by RSM.
77 By clicking Proceed, you will be given the <code>{this.props.role_name}</code> role in <code>{this.props.guild_name}</code>.
pineafanc540da92021-09-03 20:33:36 +010078 </p>
Samuel Shuert835c71f2021-09-03 15:49:26 -050079 <br />
80 <p>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>.</p>
pineafanc540da92021-09-03 20:33:36 +010081 </div>
82 </div>
83 </>
84 }
85}
86
87export default RSMV;
88export async function getServerSideProps(ctx) {
89 if(!ctx.query.code) {
90 return {
91 redirect: {
pineafanbb7efa42021-09-04 10:05:06 +010092 destination: '/rsmv/failure',
pineafanc540da92021-09-03 20:33:36 +010093 permanent: true
94 }
95 }
96 }
97 let code = await Axios.post('http://localhost:3000/api/rsmv/validate', {code:ctx.query.code});
98 let headers = ctx.req.headers;
99 if (code.status != 200 ) {
100 return {
101 redirect: {
pineafanbb7efa42021-09-04 10:05:06 +0100102 destination: '/rsmv/failure',
pineafanc540da92021-09-03 20:33:36 +0100103 permanent: true
104 }
105 }
106 }
107 return {
108 props: {
109 uID:code.data.user,
110 rID:code.data.role,
111 role_name:code.data.role_name,
112 gID:code.data.guild,
113 guild_name:code.data.guild_name,
114 guild_icon_url:code.data.guild_icon_url,
115 memberCount:code.data.guild_size,
116 headers: headers,
117 code: ctx.query.code
118 }
119 }
120}