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' |
| 3 | import HCaptcha from '@hcaptcha/react-hcaptcha'; |
| 4 | import Axios from 'axios'; |
| 5 | import Router from 'next/router'; |
| 6 | import React from 'react'; |
| 7 | |
| 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 <> |
| 56 | <div className={Styles.container}> |
| 57 | <div className={Styles.ServerHeader}> |
| 58 | <div className={Styles.ServerHeaderCenter}> |
| 59 | <img src={this.props.guild_icon_url} className={Styles.ServerHeaderImage}/> |
| 60 | </div> |
| 61 | </div> |
| 62 | <div className={Styles.ServerHeader}> |
| 63 | <div className={Styles.ServerHeaderCenter}> |
| 64 | <h1>{this.props.guild_name}</h1> |
| 65 | <h3>{this.props.memberCount} members</h3> |
| 66 | </div> |
| 67 | </div> |
| 68 | <div className={Styles.ServerHeader}> |
| 69 | <h4> |
| 70 | Complete the check below to join {this.props.guild_name}. |
| 71 | </h4> |
| 72 | </div> |
| 73 | <div className={Styles.form}> |
| 74 | <HCaptcha |
| 75 | id="Captchas mitigate problems" |
| 76 | sitekey="85074411-fa13-4d9b-b901-53095c6d1fc6" |
| 77 | onVerify={token => this.handleVerificationSuccess(this, token)} |
| 78 | /> |
| 79 | <div className={Styles.buttonContainer}> |
| 80 | <button type="button" className={Styles.button} onClick={(success) => this.submitForm(this)}>Proceed</button> |
| 81 | </div> |
| 82 | </div> |
| 83 | <div className={Styles.BottomText}> |
| 84 | <p>This is an automatic check performed by RSM.<br/> |
| 85 | <br/> |
| 86 | By clicking Proceed, you will be given the <highlight>{this.props.role_name}</highlight> role in <highlight>{this.props.guild_name}</highlight>.<br/> |
| 87 | {/* <br/> |
| 88 | By Proceeding, you consent to our use of cookies described in our <highlight>policy</highlight>. */} |
| 89 | </p> |
| 90 | </div> |
| 91 | </div> |
| 92 | </> |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | export default RSMV; |
| 97 | export async function getServerSideProps(ctx) { |
| 98 | if(!ctx.query.code) { |
| 99 | return { |
| 100 | redirect: { |
| 101 | destination: '/rsmv/faliure', |
| 102 | permanent: true |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | let code = await Axios.post('http://localhost:3000/api/rsmv/validate', {code:ctx.query.code}); |
| 107 | let headers = ctx.req.headers; |
| 108 | if (code.status != 200 ) { |
| 109 | return { |
| 110 | redirect: { |
| 111 | destination: '/rsmv/faliure', |
| 112 | permanent: true |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | return { |
| 117 | props: { |
| 118 | uID:code.data.user, |
| 119 | rID:code.data.role, |
| 120 | role_name:code.data.role_name, |
| 121 | gID:code.data.guild, |
| 122 | guild_name:code.data.guild_name, |
| 123 | guild_icon_url:code.data.guild_icon_url, |
| 124 | memberCount:code.data.guild_size, |
| 125 | headers: headers, |
| 126 | code: ctx.query.code |
| 127 | } |
| 128 | } |
| 129 | } |