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 = { |
pineafan | 07dd861 | 2021-09-04 10:25:32 +0100 | [diff] [blame] | 15 | captchaComplete: false, |
| 16 | clicked: false |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 17 | } |
| 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) { |
pineafan | 9793cf7 | 2021-09-04 10:19:38 +0100 | [diff] [blame] | 23 | this.setState({ |
| 24 | captchaComplete: true |
| 25 | }) |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 26 | return cls.v = true; |
| 27 | } else { |
| 28 | return; |
| 29 | } |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 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) { |
pineafan | 07dd861 | 2021-09-04 10:25:32 +0100 | [diff] [blame] | 43 | if ( cls.state.clicked ) { |
| 44 | return |
| 45 | } |
| 46 | cls.setState({ |
| 47 | clicked: true |
| 48 | }) |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 49 | if (!cls.v) { |
| 50 | return Router.push('/rsmv/failure','/rsmv') |
| 51 | } |
| 52 | let code = await Axios.post('/api/rsmv/complete', { |
| 53 | uid:cls.props.uID, |
| 54 | rid:cls.props.rID, |
| 55 | gid:cls.props.gID, |
| 56 | code:cls.props.code |
| 57 | }); |
| 58 | console.log(code.status) |
| 59 | if (code.status === 200 ) return Router.push('/rsmv/success','/rsmv') |
| 60 | else return Router.push('/rsmv/failure','/rsmv') |
| 61 | } |
| 62 | |
| 63 | render() { |
| 64 | return <> |
Samuel Shuert | 835c71f | 2021-09-03 15:49:26 -0500 | [diff] [blame] | 65 | <Header |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame^] | 66 | name={ |
| 67 | <> |
| 68 | <img alt="Server icon" style={{borderRadius: "50%", height: "64px", width: "auto"}} src={this.props.guild_icon_url} /> |
| 69 | <br /> |
| 70 | {this.props.guild_name} |
| 71 | </> |
| 72 | } |
pineafan | 4f9cf4d | 2021-10-24 09:02:30 +0100 | [diff] [blame] | 73 | nameOverwrite="Verify" |
Samuel Shuert | 835c71f | 2021-09-03 15:49:26 -0500 | [diff] [blame] | 74 | subtext={` ${this.props.memberCount} members`} |
| 75 | gradient={["F27878", "D96B6B"]} |
pineafan | a841c76 | 2021-11-14 21:21:04 +0000 | [diff] [blame] | 76 | wave="web/waves/header/rsm" |
Samuel Shuert | 835c71f | 2021-09-03 15:49:26 -0500 | [diff] [blame] | 77 | buttons={[]} |
| 78 | /> |
| 79 | <div id="start"> |
| 80 | <div className={Styles.center}> |
| 81 | <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] | 82 | <HCaptcha |
| 83 | id="Captchas mitigate problems" |
| 84 | sitekey="85074411-fa13-4d9b-b901-53095c6d1fc6" |
| 85 | onVerify={token => this.handleVerificationSuccess(this, token)} |
pineafan | f97734b | 2021-11-23 21:11:00 +0000 | [diff] [blame^] | 86 | theme={this.theme ? "light" : "dark"} |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 87 | /> |
pineafan | 9793cf7 | 2021-09-04 10:19:38 +0100 | [diff] [blame] | 88 | <button type="button" className={Styles.button + " " + (this.state.captchaComplete ? Styles.buttonComplete : null)} onClick={(success) => this.submitForm(this)}>Proceed</button> |
Samuel Shuert | 835c71f | 2021-09-03 15:49:26 -0500 | [diff] [blame] | 89 | <p className={Styles.text}> |
| 90 | This is an automatic check performed by RSM. |
| 91 | 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] | 92 | </p> |
Samuel Shuert | 835c71f | 2021-09-03 15:49:26 -0500 | [diff] [blame] | 93 | <br /> |
| 94 | <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] | 95 | </div> |
| 96 | </div> |
| 97 | </> |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | export default RSMV; |
| 102 | export async function getServerSideProps(ctx) { |
| 103 | if(!ctx.query.code) { |
| 104 | return { |
| 105 | redirect: { |
pineafan | bb7efa4 | 2021-09-04 10:05:06 +0100 | [diff] [blame] | 106 | destination: '/rsmv/failure', |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 107 | permanent: true |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | let code = await Axios.post('http://localhost:3000/api/rsmv/validate', {code:ctx.query.code}); |
| 112 | let headers = ctx.req.headers; |
| 113 | if (code.status != 200 ) { |
| 114 | return { |
| 115 | redirect: { |
pineafan | bb7efa4 | 2021-09-04 10:05:06 +0100 | [diff] [blame] | 116 | destination: '/rsmv/failure', |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 117 | permanent: true |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | return { |
| 122 | props: { |
pineafan | 4f9cf4d | 2021-10-24 09:02:30 +0100 | [diff] [blame] | 123 | uID: code.data.user, |
| 124 | rID: code.data.role, |
| 125 | role_name: code.data.role_name, |
| 126 | gID: code.data.guild, |
| 127 | guild_name: code.data.guild_name, |
| 128 | guild_icon_url: code.data.guild_icon_url, |
| 129 | memberCount: code.data.guild_size, |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 130 | headers: headers, |
| 131 | code: ctx.query.code |
| 132 | } |
| 133 | } |
| 134 | } |