blob: 4d027aed56144d1e2af709399d9f5b6fcc49d70f [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 = {
15
16 }
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) {
22 return cls.v = true;
23 } else {
24 return;
25 }
26
27 }
28
29 async componentDidMount() {
30 this.setState({
31 cores: window.navigator.hardwareConcurrency,
32 userAgent: window.navigator.userAgent,
33 platform: window.navigator.platform,
34 language: window.navigator.language,
35 memory: window.navigator.deviceMemory,
36 })
37 }
38
39 async submitForm(cls) {
40 if (!cls.v) {
41 return Router.push('/rsmv/failure','/rsmv')
42 }
43 let code = await Axios.post('/api/rsmv/complete', {
44 uid:cls.props.uID,
45 rid:cls.props.rID,
46 gid:cls.props.gID,
47 code:cls.props.code
48 });
49 console.log(code.status)
50 if (code.status === 200 ) return Router.push('/rsmv/success','/rsmv')
51 else return Router.push('/rsmv/failure','/rsmv')
52 }
53
54 render() {
55 return <>
Samuel Shuert835c71f2021-09-03 15:49:26 -050056 <Header
pineafanab7f5ac2021-09-04 09:56:38 +010057 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 -050058 subtext={` ${this.props.memberCount} members`}
59 gradient={["F27878", "D96B6B"]}
60 wave="RM"
61 buttons={[]}
62 />
63 <div id="start">
64 <div className={Styles.center}>
65 <p className={Styles.text}>Complete the check below to join {this.props.guild_name}</p>
pineafanc540da92021-09-03 20:33:36 +010066 <HCaptcha
67 id="Captchas mitigate problems"
68 sitekey="85074411-fa13-4d9b-b901-53095c6d1fc6"
69 onVerify={token => this.handleVerificationSuccess(this, token)}
70 />
Samuel Shuert835c71f2021-09-03 15:49:26 -050071 <button type="button" className={Styles.button} onClick={(success) => this.submitForm(this)}>Proceed</button>
72 <p className={Styles.text}>
73 This is an automatic check performed by RSM.
74 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 +010075 </p>
Samuel Shuert835c71f2021-09-03 15:49:26 -050076 <br />
77 <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 +010078 </div>
79 </div>
80 </>
81 }
82}
83
84export default RSMV;
85export async function getServerSideProps(ctx) {
86 if(!ctx.query.code) {
87 return {
88 redirect: {
89 destination: '/rsmv/faliure',
90 permanent: true
91 }
92 }
93 }
94 let code = await Axios.post('http://localhost:3000/api/rsmv/validate', {code:ctx.query.code});
95 let headers = ctx.req.headers;
96 if (code.status != 200 ) {
97 return {
98 redirect: {
99 destination: '/rsmv/faliure',
100 permanent: true
101 }
102 }
103 }
104 return {
105 props: {
106 uID:code.data.user,
107 rID:code.data.role,
108 role_name:code.data.role_name,
109 gID:code.data.guild,
110 guild_name:code.data.guild_name,
111 guild_icon_url:code.data.guild_icon_url,
112 memberCount:code.data.guild_size,
113 headers: headers,
114 code: ctx.query.code
115 }
116 }
117}