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'; |
pineafan | 3b0852d | 2022-05-06 20:39:59 +0100 | [diff] [blame] | 7 | import Header from '../../Components/Header'; |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 8 | |
pineafan | e0283a8 | 2022-02-13 10:05:56 +0000 | [diff] [blame] | 9 | import { AutoLayout, Panel, Title, Subtitle, Text, Divider } from '../../Components/Panels'; |
| 10 | import { List, ListItem, Code } from '../../Components/Texttools'; |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 11 | class RSMV extends Component { |
| 12 | |
| 13 | constructor(props) { |
| 14 | super(props); |
| 15 | this.v = false; |
| 16 | this.state = { |
pineafan | 07dd861 | 2021-09-04 10:25:32 +0100 | [diff] [blame] | 17 | captchaComplete: false, |
| 18 | clicked: false |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 19 | } |
| 20 | } |
| 21 | |
| 22 | async handleVerificationSuccess(cls, token) { |
| 23 | const chk = await Axios.put('/api/rsmv/verifyTkn', { tkn: token.toString() }) |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 24 | if(chk.data.success === true) { |
pineafan | 9793cf7 | 2021-09-04 10:19:38 +0100 | [diff] [blame] | 25 | this.setState({ |
| 26 | captchaComplete: true |
| 27 | }) |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 28 | return cls.v = true; |
| 29 | } else { |
| 30 | return; |
| 31 | } |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | async componentDidMount() { |
| 35 | this.setState({ |
| 36 | cores: window.navigator.hardwareConcurrency, |
| 37 | userAgent: window.navigator.userAgent, |
| 38 | platform: window.navigator.platform, |
| 39 | language: window.navigator.language, |
| 40 | memory: window.navigator.deviceMemory, |
| 41 | }) |
| 42 | } |
| 43 | |
| 44 | async submitForm(cls) { |
pineafan | 07dd861 | 2021-09-04 10:25:32 +0100 | [diff] [blame] | 45 | if ( cls.state.clicked ) { |
| 46 | return |
| 47 | } |
| 48 | cls.setState({ |
| 49 | clicked: true |
| 50 | }) |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 51 | if (!cls.v) { |
| 52 | return Router.push('/rsmv/failure','/rsmv') |
| 53 | } |
| 54 | let code = await Axios.post('/api/rsmv/complete', { |
| 55 | uid:cls.props.uID, |
| 56 | rid:cls.props.rID, |
| 57 | gid:cls.props.gID, |
| 58 | code:cls.props.code |
| 59 | }); |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 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 Shuert | 835c71f | 2021-09-03 15:49:26 -0500 | [diff] [blame] | 66 | <Header |
pineafan | ff3d452 | 2022-05-06 19:51:02 +0100 | [diff] [blame] | 67 | name="Verify" |
| 68 | customImage={this.props.guild_icon_url} |
pineafan | 4627016 | 2022-02-13 12:06:17 +0000 | [diff] [blame] | 69 | subtext={`${this.props.memberCount} members`} |
Samuel Shuert | 835c71f | 2021-09-03 15:49:26 -0500 | [diff] [blame] | 70 | gradient={["F27878", "D96B6B"]} |
pineafan | a841c76 | 2021-11-14 21:21:04 +0000 | [diff] [blame] | 71 | wave="web/waves/header/rsm" |
Samuel Shuert | 835c71f | 2021-09-03 15:49:26 -0500 | [diff] [blame] | 72 | buttons={[]} |
PineaFan | a465f35 | 2023-02-05 16:45:01 +0000 | [diff] [blame] | 73 | season={this.props.season} |
Samuel Shuert | 835c71f | 2021-09-03 15:49:26 -0500 | [diff] [blame] | 74 | /> |
pineafan | e0283a8 | 2022-02-13 10:05:56 +0000 | [diff] [blame] | 75 | <AutoLayout> |
| 76 | <Panel> |
| 77 | <Text>Complete the check below to join {this.props.guild_name}</Text> |
pineafan | 4627016 | 2022-02-13 12:06:17 +0000 | [diff] [blame] | 78 | <div style={{height: "125px"}}> |
| 79 | <HCaptcha |
| 80 | id="Captchas mitigate problems" |
| 81 | sitekey="85074411-fa13-4d9b-b901-53095c6d1fc6" |
| 82 | onVerify={token => this.handleVerificationSuccess(this, token)} |
| 83 | theme={this.theme ? "light" : "dark"} |
| 84 | /> |
| 85 | </div> |
pineafan | 9793cf7 | 2021-09-04 10:19:38 +0100 | [diff] [blame] | 86 | <button type="button" className={Styles.button + " " + (this.state.captchaComplete ? Styles.buttonComplete : null)} onClick={(success) => this.submitForm(this)}>Proceed</button> |
pineafan | 4627016 | 2022-02-13 12:06:17 +0000 | [diff] [blame] | 87 | <List colour="F27878"> |
pineafan | e0283a8 | 2022-02-13 10:05:56 +0000 | [diff] [blame] | 88 | <ListItem>This is an automatic check performed by RSM.</ListItem> |
| 89 | <ListItem>By clicking Proceed, you will be given the <code>{this.props.role_name}</code> role in <code>{this.props.guild_name}</code>.</ListItem> |
PineaFan | 4141862 | 2023-10-14 21:36:48 +0100 | [diff] [blame^] | 90 | <ListItem>For the full list of data stored by RSM, please check <a href="https://clickscodes.github.io/policies/rsm#verification">Here</a></ListItem> |
pineafan | e0283a8 | 2022-02-13 10:05:56 +0000 | [diff] [blame] | 91 | </List> |
pineafan | 3b0852d | 2022-05-06 20:39:59 +0100 | [diff] [blame] | 92 | <Text>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>.</Text> |
pineafan | e0283a8 | 2022-02-13 10:05:56 +0000 | [diff] [blame] | 93 | </Panel> |
| 94 | </AutoLayout> |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 95 | </> |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | export default RSMV; |
| 100 | export async function getServerSideProps(ctx) { |
| 101 | if(!ctx.query.code) { |
| 102 | return { |
| 103 | redirect: { |
pineafan | bb7efa4 | 2021-09-04 10:05:06 +0100 | [diff] [blame] | 104 | destination: '/rsmv/failure', |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 105 | permanent: true |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | let code = await Axios.post('http://localhost:3000/api/rsmv/validate', {code:ctx.query.code}); |
| 110 | let headers = ctx.req.headers; |
pineafan | 9babd75 | 2022-10-21 21:47:52 +0100 | [diff] [blame] | 111 | if (code.status !== 200 ) { |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 112 | return { |
| 113 | redirect: { |
pineafan | bb7efa4 | 2021-09-04 10:05:06 +0100 | [diff] [blame] | 114 | destination: '/rsmv/failure', |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 115 | permanent: true |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | return { |
| 120 | props: { |
pineafan | 4f9cf4d | 2021-10-24 09:02:30 +0100 | [diff] [blame] | 121 | uID: code.data.user, |
| 122 | rID: code.data.role, |
| 123 | role_name: code.data.role_name, |
| 124 | gID: code.data.guild, |
| 125 | guild_name: code.data.guild_name, |
| 126 | guild_icon_url: code.data.guild_icon_url, |
| 127 | memberCount: code.data.guild_size, |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 128 | headers: headers, |
| 129 | code: ctx.query.code |
| 130 | } |
| 131 | } |
| 132 | } |