Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit b673eae

Browse files
authored
Merge pull request #41 from codewizardshq/voting-and-design
Voting and design
2 parents c988ea5 + ea3756c commit b673eae

37 files changed

+1528
-511
lines changed

CodeChallenge/api/questions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def json_error(reason, status=400):
2222
def end_code_challenge():
2323
if core.challenge_ended():
2424
r = jsonify(status="error",
25-
message="code challenge has ended")
25+
reason="code challenge has ended")
2626
r.status_code = 403
2727
abort(r)
2828

@@ -84,7 +84,7 @@ def next_question():
8484

8585

8686
def answer_limit_attempts():
87-
return current_app.config.get("ANSWER_ATTEMPT_LIMIT", "3 per 30 minutes")
87+
return current_app.config.get("ANSWER_ATTEMPT_LIMIT", "1 per 1 minutes")
8888

8989

9090
@bp.route("/answer", methods=["POST"])
@@ -163,10 +163,10 @@ def reset_all():
163163

164164
db.session.commit()
165165

166-
return jsonify(status="success", message="all answers and rank reset")
166+
return jsonify(status="success", reason="all answers and rank reset")
167167

168168
return jsonify(status="error",
169-
message="resetting not allowed at this time"), 403
169+
reason="resetting not allowed at this time"), 403
170170

171171

172172
@bp.route("/final", methods=["POST"])

CodeChallenge/cli/questions.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,21 @@
1818
@click.argument("answer")
1919
@click.argument("rank")
2020
@click.argument("asset")
21-
def q_add(title, answer, rank, asset):
21+
@click.argument("hint1")
22+
@click.argument("hint2")
23+
def q_add(title, answer, rank, asset, hint1, hint2):
2224
"""Add a new question to the database
2325
2426
TITLE is the text for the title of the question
2527
ANSWER is the answer stored only in the database
2628
RANK is the day rank the queestion should be revealed on
2729
ASSET is a path to a file to upload for a question
30+
HINT1 is a hint string
31+
HINT2 is a hint string
2832
"""
2933

3034
asset = os.path.abspath(asset)
31-
qid = add_question(title, answer, rank, asset)
35+
qid = add_question(title, answer, rank, asset, hint1, hint2)
3236

3337
click.echo(f"added question id {qid}")
3438

@@ -66,7 +70,9 @@ def q_del(qid):
6670
@click.argument("answer")
6771
@click.argument("rank")
6872
@click.argument("asset")
69-
def q_replace(title, answer, rank, asset):
73+
@click.argument("hint1")
74+
@click.argument("hint2")
75+
def q_replace(title, answer, rank, asset, hint1, hint2):
7076
"""Replace an existing rank's question.
7177
7278
This basically deletes the previous rank then adds the new rank

CodeChallenge/manage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .models import Question, db
44

55

6-
def add_question(title, answer, rank, asset) -> Question:
6+
def add_question(title, answer, rank, asset, hint1=None, hint2=None) -> Question:
77

88
q = Question.query.filter_by(rank=rank).first()
99

@@ -19,6 +19,8 @@ def add_question(title, answer, rank, asset) -> Question:
1919

2020
q.asset_ext = os.path.splitext(asset)[1]
2121
q.rank = rank
22+
q.hint1 = hint1
23+
q.hint2 = hint2
2224

2325
db.session.add(q)
2426
db.session.commit()

Pipfile.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"moment": "^2.24.0",
1414
"serialize-javascript": "^2.1.2",
1515
"vue": "^2.6.10",
16+
"vue-codemirror": "^4.0.6",
1617
"vue-moment": "^4.1.0",
1718
"vue-router": "^3.1.3",
1819
"vue-the-mask": "^0.11.1",
@@ -33,6 +34,7 @@
3334
"prettier": "^1.18.2",
3435
"sass": "^1.19.0",
3536
"sass-loader": "^8.0.0",
37+
"vue-cli-plugin-codemirror": "^0.0.6",
3638
"vue-cli-plugin-vuetify": "^2.0.2",
3739
"vue-template-compiler": "^2.6.10",
3840
"vuetify-loader": "^1.3.0"

public/index.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,23 @@
66
<meta http-equiv="X-UA-Compatible" content="IE=edge">
77
<meta name="viewport" content="width=device-width,initial-scale=1.0">
88
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">
9-
<link rel='shortcut icon' type='image/x-icon' href='/favicon.ico' />
9+
<link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
10+
<link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
11+
<link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
12+
<link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
13+
<link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
14+
<link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
15+
<link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
16+
<link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
17+
<link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
18+
<link rel="icon" type="image/png" sizes="192x192" href="/android-icon-192x192.png">
19+
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
20+
<link rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png">
21+
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
22+
<link rel="manifest" href="/manifest.json">
23+
<meta name="msapplication-TileColor" content="#ffffff">
24+
<meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
25+
<meta name="theme-color" content="#ffffff">
1026
<title>CodeWizardsHQ CODE CHALLENGE</title>
1127
</head>
1228

src/api/auth.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ async function createAccount(data) {
4343
await login(data.username, data.password, false);
4444
}
4545

46+
async function requestPasswordReset(email) {
47+
await request(routes.userapi_forgot, { data: { email } });
48+
}
49+
4650
async function fetchState() {
4751
const userData = await request(routes.userapi_hello, {}, state.auth);
4852
await setState({
@@ -75,11 +79,19 @@ function currentUser() {
7579
}
7680

7781
async function forgotPassword(email) {
78-
return await request(routes.userapi_forgot_password, { data: { email } }, false);
82+
return await request(
83+
routes.userapi_forgot_password,
84+
{ data: { email } },
85+
false
86+
);
7987
}
8088

8189
async function resetPassword(token, password) {
82-
return await request(routes.userapi_reset_password, { data: { token, password } }, false)
90+
return await request(
91+
routes.userapi_reset_password,
92+
{ data: { token, password } },
93+
false
94+
);
8395
}
8496

8597
export default {
@@ -89,6 +101,7 @@ export default {
89101
fetchState,
90102
createAccount,
91103
currentUser,
104+
requestPasswordReset,
92105
onAuthStateChange,
93106
offAuthStateChange,
94107
forgotPassword,

src/api/quiz.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ async function getQuestion() {
66
}
77

88
async function getRank() {
9-
return (await request(routes.questionsapi_get_rank)).rank;
9+
return request(routes.questionsapi_get_rank);
1010
}
1111

1212
async function resetRank() {
@@ -22,9 +22,21 @@ async function submit(answer) {
2222
return result.correct;
2323
}
2424

25+
async function submitFinal(answer, language, checkOnly) {
26+
const result = await request(routes.questionsapi_answer_final_question, {
27+
data: {
28+
checkOnly,
29+
text: answer,
30+
language
31+
}
32+
});
33+
return result;
34+
}
35+
2536
export default {
2637
getQuestion,
2738
submit,
39+
submitFinal,
2840
getRank,
2941
resetRank
3042
};

src/api/request.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
11
import axios from "axios";
2-
import routes from "./routes";
2+
// import routes from "./routes";
33

4-
export default async function request(route, options = {}, tryRefresh = true) {
4+
export default async function request(route, options = {}, _tryRefresh = true) {
5+
if (_tryRefresh) {
6+
// satisfy linter
7+
}
58
try {
69
// attempt initial request and return great response
710
const response = await axios({
811
method: route.type,
912
url: route.path,
1013
...options
1114
});
12-
return response.data;
13-
} catch (err) {
14-
if (err.response.status == 401 && tryRefresh) {
15-
// our tokens have possibly expired, send refresh
16-
// TODO: THIS IS UNFINISHED
17-
await axios({
18-
method: "POST",
19-
url: routes.userapi_refresh.path
20-
});
2115

22-
// try and return original request marked with no refresh
23-
return request(route, options, false);
24-
}
16+
return {
17+
...response.data,
18+
headers: response.headers
19+
};
20+
} catch (err) {
21+
// console.log(err.response);
22+
// if (err.response.status == 401 && tryRefresh) {
23+
// console.log("Trying refresh");
24+
// // our tokens have possibly expired, send refresh
25+
// // TODO: THIS IS UNFINISHED
26+
// await axios({
27+
// method: "POST",
28+
// url: routes.userapi_refresh.path
29+
// });
2530

31+
// // try and return original request marked with no refresh
32+
// return request(route, options, false);
33+
// }
2634
// return original error
35+
// console.log()
2736
return Promise.reject({
2837
status: err.response.status,
2938
headers: err.response.headers,
39+
data: err.response.data,
3040
message:
3141
!!err.response.data && !!err.response.data.reason
3242
? err.response.data.reason

src/api/routes.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ export default {
1111
userapi_login: route("/api/v1/users/token/auth", "POST"),
1212
userapi_logout: route("/api/v1/users/token/remove", "POST"),
1313
userapi_hello: route("/api/v1/users/hello", "GET"),
14+
userapi_forgot: route("/api/v1/users/forgot", "POST"),
1415
userapi_refresh: route("/api/v1/users/token/refresh", "POST"),
1516
userapi_forgot_password: route("/api/v1/users/forgot", "POST"),
1617
userapi_reset_password: route("/api/v1/users/reset-password", "POST"),
1718
questionsapi_rank_reset: route("/api/v1/questions/reset", "DELETE"),
1819
questionsapi_answer_next_question: route("/api/v1/questions/answer", "POST"),
20+
questionsapi_answer_final_question: route("/api/v1/questions/final", "POST"),
1921
questionsapi_get_rank: route("/api/v1/questions/rank", "GET"),
20-
questions_api_next_question: route("/api/v1/questions/next", "GET"),
22+
questions_api_next_question: route("/api/v1/questions/next", "GET")
2123
};
2224

2325
// export default {

0 commit comments

Comments
 (0)