pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 1 | import { Component } from 'react'; |
| 2 | import Styles from '../../styles/rsmv/rsmv.module.css' |
Samuel Shuert | 835c71f | 2021-09-03 15:49:26 -0500 | [diff] [blame] | 3 | import HCaptcha from 'react-hcaptcha'; |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 4 | import Axios from 'axios'; |
| 5 | import Router from 'next/router'; |
| 6 | import React from 'react'; |
Samuel Shuert | 835c71f | 2021-09-03 15:49:26 -0500 | [diff] [blame] | 7 | import Header from '../../Components/Header' |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 8 | |
| 9 | class 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 Shuert | 835c71f | 2021-09-03 15:49:26 -0500 | [diff] [blame] | 56 | <Header |
pineafan | aed3024 | 2021-09-04 09:33:40 +0100 | [diff] [blame] | 57 | name={<><img alt="Server icon" style={{borderRadius: "50%"}} src={this.props.guild_icon_url} /><br />{this.props.guild_name}</>} |
Samuel Shuert | 835c71f | 2021-09-03 15:49:26 -0500 | [diff] [blame] | 58 | 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> |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 66 | <HCaptcha |
| 67 | id="Captchas mitigate problems" |
| 68 | sitekey="85074411-fa13-4d9b-b901-53095c6d1fc6" |
| 69 | onVerify={token => this.handleVerificationSuccess(this, token)} |
| 70 | /> |
Samuel Shuert | 835c71f | 2021-09-03 15:49:26 -0500 | [diff] [blame] | 71 | <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>. |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 75 | </p> |
Samuel Shuert | 835c71f | 2021-09-03 15:49:26 -0500 | [diff] [blame] | 76 | <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> |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 78 | </div> |
| 79 | </div> |
| 80 | </> |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | export default RSMV; |
| 85 | export 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 | } |