blob: 6bb71cec0ab682f30e48d2f575ee348e1aa54d2e [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 = {
pineafan07dd8612021-09-04 10:25:32 +010015 captchaComplete: false,
16 clicked: false
pineafanc540da92021-09-03 20:33:36 +010017 }
18 }
19
20 async handleVerificationSuccess(cls, token) {
21 const chk = await Axios.put('/api/rsmv/verifyTkn', { tkn: token.toString() })
22 if(chk.data.success == true) {
pineafan9793cf72021-09-04 10:19:38 +010023 this.setState({
24 captchaComplete: true
25 })
pineafanc540da92021-09-03 20:33:36 +010026 return cls.v = true;
27 } else {
28 return;
29 }
30
31 }
32
33 async componentDidMount() {
34 this.setState({
35 cores: window.navigator.hardwareConcurrency,
36 userAgent: window.navigator.userAgent,
37 platform: window.navigator.platform,
38 language: window.navigator.language,
39 memory: window.navigator.deviceMemory,
40 })
41 }
42
43 async submitForm(cls) {
pineafan07dd8612021-09-04 10:25:32 +010044 if ( cls.state.clicked ) {
45 return
46 }
47 cls.setState({
48 clicked: true
49 })
pineafanc540da92021-09-03 20:33:36 +010050 if (!cls.v) {
51 return Router.push('/rsmv/failure','/rsmv')
52 }
53 let code = await Axios.post('/api/rsmv/complete', {
54 uid:cls.props.uID,
55 rid:cls.props.rID,
56 gid:cls.props.gID,
57 code:cls.props.code
58 });
59 console.log(code.status)
60 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
pineafanab7f5ac2021-09-04 09:56:38 +010067 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 -050068 subtext={` ${this.props.memberCount} members`}
69 gradient={["F27878", "D96B6B"]}
70 wave="RM"
71 buttons={[]}
72 />
73 <div id="start">
74 <div className={Styles.center}>
75 <p className={Styles.text}>Complete the check below to join {this.props.guild_name}</p>
pineafanc540da92021-09-03 20:33:36 +010076 <HCaptcha
77 id="Captchas mitigate problems"
78 sitekey="85074411-fa13-4d9b-b901-53095c6d1fc6"
79 onVerify={token => this.handleVerificationSuccess(this, token)}
80 />
pineafan9793cf72021-09-04 10:19:38 +010081 <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 -050082 <p className={Styles.text}>
83 This is an automatic check performed by RSM.
84 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 +010085 </p>
Samuel Shuert835c71f2021-09-03 15:49:26 -050086 <br />
87 <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 +010088 </div>
89 </div>
90 </>
91 }
92}
93
94export default RSMV;
95export async function getServerSideProps(ctx) {
96 if(!ctx.query.code) {
97 return {
98 redirect: {
pineafanbb7efa42021-09-04 10:05:06 +010099 destination: '/rsmv/failure',
pineafanc540da92021-09-03 20:33:36 +0100100 permanent: true
101 }
102 }
103 }
104 let code = await Axios.post('http://localhost:3000/api/rsmv/validate', {code:ctx.query.code});
105 let headers = ctx.req.headers;
106 if (code.status != 200 ) {
107 return {
108 redirect: {
pineafanbb7efa42021-09-04 10:05:06 +0100109 destination: '/rsmv/failure',
pineafanc540da92021-09-03 20:33:36 +0100110 permanent: true
111 }
112 }
113 }
114 return {
115 props: {
116 uID:code.data.user,
117 rID:code.data.role,
118 role_name:code.data.role_name,
119 gID:code.data.guild,
120 guild_name:code.data.guild_name,
121 guild_icon_url:code.data.guild_icon_url,
122 memberCount:code.data.guild_size,
123 headers: headers,
124 code: ctx.query.code
125 }
126 }
127}