Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 5b39e41

Browse files
authored
Merge pull request #21 from redpwn/feature/login-page
Added registration page and clientside framework
2 parents 73ffedd + 913a42f commit 5b39e41

File tree

11 files changed

+10469
-10275
lines changed

11 files changed

+10469
-10275
lines changed

client/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<meta name="viewport" content="width=device-width,initial-scale=1">
77
<meta name="mobile-web-app-capable" content="yes">
88
<meta name="apple-mobile-web-app-capable" content="yes">
9+
<link href="https://fonts.googleapis.com/css?family=Nunito+Sans:200,300,400,600,700" rel="stylesheet">
10+
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet">
911
</head>
1012
<body>
1113
<script src="<%= htmlWebpackPlugin.options.view.assetsPrefix %><%= htmlWebpackPlugin.files.chunks['bundle'].entry %>"></script>

client/src/api/auth.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { request } from './index'
2+
3+
export const login = ({ teamToken }) => {
4+
return request('POST', '/auth/verify', {
5+
teamToken
6+
})
7+
}
8+
9+
export const signup = ({ email, name, division, register }) => {
10+
return request('POST', '/auth/submit', {
11+
email,
12+
name,
13+
division
14+
})
15+
}

client/src/api/challenges.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const getChallenges = () => {
2+
return []
3+
}

client/src/api/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { route } from 'preact-router'
2+
import config from '../config'
3+
4+
const badToken = () => {
5+
localStorage.removeItem('token')
6+
route('/login')
7+
}
8+
9+
export const request = (method, endpoint, data) => {
10+
return fetch(config.apiEndpoint + endpoint, {
11+
method,
12+
headers: {
13+
'Content-Type': 'application/json',
14+
Authorization: 'Bearer ' + localStorage.getItem('token')
15+
},
16+
body: JSON.stringify(data)
17+
})
18+
.json()
19+
.catch(err => {
20+
console.debug(err)
21+
badToken()
22+
})
23+
}

client/src/components/header.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Component } from 'preact'
2+
import withStyles from './jss'
3+
4+
export default withStyles({
5+
6+
}, class Header extends Component {
7+
render ({ classes }) {
8+
return (
9+
<div class='tab-container tabs-center'>
10+
<ul>
11+
<li><a>Home</a></li>
12+
<li><a>About</a></li>
13+
<li><a>Register</a></li>
14+
<li><a>Login</a></li>
15+
</ul>
16+
</div>
17+
)
18+
}
19+
})
File renamed without changes.

client/src/components/registration.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { Component } from 'preact'
2+
import config from '../config'
3+
import withStyles from './jss'
4+
5+
export default withStyles({
6+
root: {
7+
padding: '25px'
8+
},
9+
submit: {
10+
marginTop: '25px'
11+
}
12+
}, class Register extends Component {
13+
componentDidMount () {
14+
document.title = 'Registration' + config.ctfTitle
15+
}
16+
17+
render ({ classes }) {
18+
return (
19+
<div class='row u-center'>
20+
<div class={classes.root + ' col-6'}>
21+
<div class='form-section'>
22+
<div class='input-control'>
23+
<input class='input-contains-icon' id='name' name='name' placeholder='Team Name' type='text' value='' />
24+
<span class='icon'>
25+
<i class='fa fa-wrapper fa-user-circle small' />
26+
</span>
27+
</div>
28+
<div class='input-control'>
29+
<input class='input-contains-icon' id='email' name='email' placeholder='Email' type='text' value='' />
30+
<span class='icon'>
31+
<i class='fa fa-wrapper fa-envelope-open small' />
32+
</span>
33+
</div>
34+
<div class='input-control'>
35+
<select class='select'>
36+
<option value='' disabled selected>Division</option>
37+
<option value='0'>High School</option>
38+
<option value='1'>College</option>
39+
<option value='2'>Other</option>
40+
</select>
41+
</div>
42+
</div>
43+
<button class={classes.submit + ' btn-info u-center'} name='btn' value='register' type='submit'>Sign Up</button>
44+
<span class='fg-danger info' />
45+
</div>
46+
</div>
47+
)
48+
}
49+
})

client/src/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
apiEndpoint: '/api/v1',
3+
ctfTitle: ' | redpwnCTF 2020'
4+
}

client/src/index.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1+
import Router from 'preact-router'
2+
import Registration from './components/registration'
3+
import Header from './components/header'
14
import 'promise-polyfill/src/polyfill'
25
import 'unfetch/polyfill/index'
36
import 'regenerator-runtime/runtime'
47
import { Component } from 'preact'
5-
import withStyles from './jss'
68

7-
export default withStyles({
8-
root: {
9-
color: 'red'
10-
}
11-
}, class App extends Component {
12-
render ({ classes }) {
9+
import 'cirrus-ui'
10+
import 'font-awesome/css/font-awesome.css'
11+
12+
export default class App extends Component {
13+
render () {
1314
return (
14-
<h1 class={classes.root}>test</h1>
15+
<div id='app'>
16+
<Header />
17+
<Router>
18+
<Registration path='/register' />
19+
</Router>
20+
</div>
1521
)
1622
}
17-
})
23+
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "MIT",
66
"private": true,
77
"scripts": {
8-
"lint": "standard",
8+
"lint": "standard --env browser",
99
"start": "node index.js",
1010
"migrate": "node-pg-migrate --database-url-var=RCTF_DATABASE_URL",
1111
"build": "sh client/build.sh",
@@ -22,6 +22,7 @@
2222
},
2323
"dependencies": {
2424
"ajv": "^6.11.0",
25+
"cirrus-ui": "^0.5.5",
2526
"email-validator": "^2.0.4",
2627
"express": "^4.17.1",
2728
"mustache": "^4.0.0",
@@ -35,6 +36,7 @@
3536
"devDependencies": {
3637
"ava": "^3.3.0",
3738
"dotenv": "^8.2.0",
39+
"font-awesome": "^4.7.0",
3840
"husky": "^4.2.1",
3941
"jss": "^10.0.4",
4042
"jss-camel-case": "^6.1.0",
@@ -44,6 +46,7 @@
4446
"nyc": "^15.0.0",
4547
"preact": "^10.3.1",
4648
"preact-cli": "^2.2.1",
49+
"preact-router": "^3.2.1",
4750
"promise-polyfill": "^8.1.3",
4851
"regenerator-runtime": "^0.13.3",
4952
"standard": "^14.3.1",

0 commit comments

Comments
 (0)