Skip to content

Commit 484f2ca

Browse files
committed
0.9
Profile Pics!!!
1 parent 62ec799 commit 484f2ca

12 files changed

+84
-30
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.vscode
22
node_modules
3-
lc
3+
lc
4+
uploads

api/package-lock.json

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
"dependencies": {
2121
"argon2": "^0.28.2",
2222
"cors": "^2.8.5",
23+
"dotenv": "^10.0.0",
2324
"express": "^4.17.1",
2425
"express-fileupload": "^1.2.1",
2526
"express-mongo-sanitize": "^2.1.0",
2627
"mongodb": "^3.6.10",
27-
"reallydangerous": "^2.1.0"
28+
"reallydangerous": "^2.1.0",
29+
"sanitize-filename": "^1.6.3"
2830
}
2931
}

client/src/App.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class App extends React.Component {
215215
style={{ display: "flex", flexDirection: "column", justifyContent: "center", alignContent: "center", alignItems: "center", height: "13ch", cursor: "pointer", paddingLeft: "2ch", marginBottom: "2vh" }}>
216216
<div style={{ display: "flex", flexDirection: "row", justifyContent: "center", alignContent: "center", alignItems: "center", marginBottom: "1vh" }}>
217217
<h3 style={{ marginRight: "1vw", fontSize: "2.3ch" }}>{this.state.username}</h3>
218-
<Avatar size="large" src={require("./assets/profile.webp").default} />
218+
<Avatar size="large" src={"https://api.irscybersec.tk/uploads/profile/" + this.state.username} />
219219
</div>
220220
<div>
221221
<h3 style={{ color: "#d89614", fontSize: "2.3ch" }}><b>Score:</b> {this.state.userScore}</h3>

client/src/Scoreboard.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Layout, message, Table } from 'antd';
2+
import { Layout, message, Table, Avatar } from 'antd';
33
import {
44
FileUnknownTwoTone
55
} from '@ant-design/icons';
@@ -319,7 +319,7 @@ class Scoreboard extends React.Component {
319319
<Column title="Position" dataIndex="position" key="position" />
320320
<Column title="Username" dataIndex="username" key="username"
321321
render={(text, row, index) => {
322-
return <Link to={"/Profile/" + text}><a style={{ fontSize: "110%", fontWeight: 700 }}>{text}</a></Link>;
322+
return <Link to={"/Profile/" + text}><a style={{ fontSize: "110%", fontWeight: 700 }}><Avatar src={"https://api.irscybersec.tk/uploads/profile/" + text} style={{marginRight: "1ch"}} /><span>{text}</span></a></Link>;
323323
}}
324324
/>
325325
<Column title="Score" dataIndex="score" key="score" />

client/src/Settings.js

+36-9
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ class Settings extends React.Component {
104104
constructor(props) {
105105
super(props);
106106
this.state = {
107-
passwordChangeModal: false
107+
fileList: [],
108+
disableUpload: false
108109
}
109110
}
110111

@@ -117,15 +118,41 @@ class Settings extends React.Component {
117118
<Layout className="layout-style">
118119
<Divider />
119120
<div style={{ display: "flex", marginRight: "5ch", alignItems: "center", justifyItems: "center" }}>
120-
<div style={{ display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center" }}>
121-
<Avatar style={{ backgroundColor: "Red", width: "10ch", height: "10ch" }} size='large' src={require("./assets/profile.webp").default} />
121+
<div style={{ display: "flex", flexDirection: "column", justifyContent: "initial", width: "15ch", overflow: "hidden" }}>
122+
<Avatar style={{ backgroundColor: "Red", width: "12ch", height: "12ch" }} size='large' src={"https://api.irscybersec.tk/uploads/profile/" + this.props.username}/>
122123
<div style={{ marginTop: "2ch" }}>
123-
<Upload beforeUpload={file => {
124-
if (file.type !== 'image/png') {
125-
message.error(`${file.name} is not a png file`);
126-
}
127-
return file.type === 'image/png' ? true : Upload.LIST_IGNORE;
128-
}}>
124+
<Upload
125+
fileList={this.state.fileList}
126+
disabled={this.state.disableUpload}
127+
accept=".png, .jpg, .jpeg, .webp"
128+
action={window.ipAddress + "/v1/profile/upload"}
129+
maxCount={1}
130+
onChange={(file) => {
131+
this.setState({fileList: file.fileList})
132+
if (file.file.status === "uploading") {
133+
this.setState({disableUpload: true})
134+
}
135+
else if ("response" in file.file) {
136+
if (file.file.response.success) message.success("Uploaded profile picture")
137+
else message.error("Failed to upload profile picture")
138+
this.setState({fileList: [], disableUpload: false})
139+
}
140+
}}
141+
headers={{ "Authorization": localStorage.getItem("IRSCTF-token") }}
142+
name="profile_pic"
143+
beforeUpload={file => {
144+
const exts = ["image/png", "image/jpg", "image/jpeg", "image/webp"]
145+
if (!exts.includes(file.type)) {
146+
message.error(`${file.name} is not an image file.`);
147+
return Upload.LIST_IGNORE
148+
}
149+
if (file.size > 102400) {
150+
message.error(`${file.name} is larger than 100KB.`);
151+
message.info('Please upload a smaller file')
152+
return Upload.LIST_IGNORE
153+
}
154+
return true
155+
}}>
129156
<Button type="primary" icon={<UploadOutlined />}>Upload</Button>
130157
</Upload>
131158
</div>

client/src/adminChallengeEdit.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ const CreateChallengeForm = (props) => {
2626
const [form] = Form.useForm();
2727
const [editorValue, setEditorValue] = React.useState("")
2828

29+
//Render existing categories select options
30+
let existingCats = []
31+
for (let i = 0; i < props.allCat.length; i++) {
32+
existingCats.push(<Option key={props.allCat[i].key} value={props.allCat[i].key}>{props.allCat[i].key}</Option>)
33+
}
34+
//Render existing challenges select options
35+
let existingChalls = []
36+
for (let i = 0; i < props.challenges.length; i++) {
37+
if (props.challenges[i].name !== props.initialData.name) existingChalls.push(<Option key={props.challenges[i].name} value={props.challenges[i].name}>{props.challenges[i].name}</Option>)
38+
}
39+
2940
if (typeof form.getFieldValue("name") === "undefined") {
3041
if (props.initialData.visibility === false) {
3142
props.initialData.visibility = "false"
@@ -37,16 +48,6 @@ const CreateChallengeForm = (props) => {
3748
form.setFieldsValue(props.initialData)
3849
setEditorValue(props.initialData.description)
3950
}
40-
//Render existing categories select options
41-
let existingCats = []
42-
for (let i = 0; i < props.allCat.length; i++) {
43-
existingCats.push(<Option key={props.allCat[i].key} value={props.allCat[i].key}>{props.allCat[i].key}</Option>)
44-
}
45-
//Render existing challenges select options
46-
let existingChalls = []
47-
for (let i = 0; i < props.challenges.length; i++) {
48-
existingChalls.push(<Option key={props.challenges[i].name} value={props.challenges[i].name}>{props.challenges[i].name}</Option>)
49-
}
5051

5152
return (
5253
<Form

client/src/assets/challenges_bg.webp

-40 KB
Binary file not shown.

client/src/assets/profile.webp

-18.9 KB
Binary file not shown.

client/src/challenges.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import React from 'react';
2-
import { Layout, Card, List, Progress, message, Button, Radio, Select } from 'antd';
2+
import { Layout, Card, List, Progress, message, Button, Select } from 'antd';
33
import {
44
FileUnknownTwoTone,
55
LeftCircleOutlined,
6-
AppstoreOutlined,
7-
TagsOutlined
86
} from '@ant-design/icons';
97
import './App.min.css';
108
import { Link } from 'react-router-dom';
11-
import ChallengesCategory from "./challengesCategory.js";
129
import ChallengesTagSort from "./challengesTagSort.js";
1310
import { Ellipsis } from 'react-spinners-css';
1411
import { Transition, animated } from 'react-spring';

client/src/challengesTagSort.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ class ChallengesTagSort extends React.Component {
577577
return (
578578
<List.Item key={item}>
579579
<List.Item.Meta
580-
avatar={<Avatar src={require("./assets/profile.webp").default} />}
580+
avatar={<Avatar src={"https://api.irscybersec.tk/uploads/profile/" + item} />}
581581
title={<Link to={"/Profile/" + item}><a style={{ fontSize: "110%", fontWeight: 700 }} onClick={() => { this.setState({ challengeModal: false }) }}>{item}</a></Link>}
582582
/>
583583
</List.Item>

client/src/profile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class Profile extends React.Component {
224224
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
225225
<div style={{ display: "flex" }}>
226226
<div style={{ display: "flex", marginRight: "5ch", alignItems: "center", justifyItems: "center" }}>
227-
<Avatar style={{ backgroundColor: "Red", marginRight: "3ch", width: "10ch", height: "10ch" }} size='large' src={require("./assets/profile.webp").default} />
227+
<Avatar style={{ backgroundColor: "Red", marginRight: "3ch", width: "10ch", height: "10ch" }} size='large' src={"https://api.irscybersec.tk/uploads/profile/" + this.state.targetUser} />
228228
<h1 style={{ fontSize: "5ch" }}>{this.state.targetUser}</h1>
229229
</div>
230230
<div>

0 commit comments

Comments
 (0)