Skip to content

Commit 5d57911

Browse files
finalised plugin setup
1 parent ed14efa commit 5d57911

60 files changed

Lines changed: 3012 additions & 2 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CTFd/plugins/hintpointdelay/__init__.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11

2-
from flask import request
2+
from flask import Blueprint, render_template, request
33

44
from CTFd.cache import clear_standings
5+
from CTFd.constants.languages import SELECT_LANGUAGE_LIST
56
from CTFd.models import Hints, Unlocks, db, get_class_by_tablename
7+
from CTFd.plugins.LuaUtils import ConfigPanel, _LuaAsset
68
from CTFd.schemas.awards import AwardSchema
79
from CTFd.schemas.unlocks import UnlockSchema
10+
from CTFd.utils import get_config
811
from CTFd.utils.decorators import (
12+
admins_only,
913
authed_only,
1014
during_ctf_time_only,
1115
require_verified_emails,
@@ -29,9 +33,19 @@ def __init__(self, user, hint):
2933
self.challenge = hint.challenge_id
3034

3135

36+
hintpoint = Blueprint(
37+
"hintpointdelay",
38+
__name__,
39+
template_folder="templates",
40+
static_folder="staticAssets",
41+
)
42+
3243
def load(app):
3344
app.db.create_all()
34-
45+
46+
app.jinja_env.globals.update(hintpointassets=_LuaAsset("hintpointdelay"))
47+
app.register_blueprint(hintpoint, url_prefix="/hintpointdelay")
48+
3549
def get_modified_challenge_points(challenge):
3650
user = get_current_user()
3751
hintids = DelayedHints.query.filter(
@@ -92,6 +106,21 @@ def apply_delayed_hints(challenge):
92106
clear_standings()
93107

94108

109+
@app.route("/admin/hintpointdelay")
110+
@admins_only
111+
def hintpoint_config():
112+
standard = get_config("inlineTranslationStandard")
113+
configs = [
114+
ConfigPanel(
115+
"Standard Language",
116+
"Set the standard language.",
117+
standard,
118+
"inlineTranslationStandard",
119+
SELECT_LANGUAGE_LIST,
120+
)
121+
]
122+
return render_template("hintconfig.html", configs=configs)
123+
95124
@during_ctf_time_only
96125
@require_verified_emails
97126
@authed_only
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Alpine from "alpinejs";
2+
import CTFd from "../index";
3+
4+
Alpine.data("LanguageForm", () => ({
5+
async set(event) {
6+
let language = event.target.getAttribute("value");
7+
document.cookie = `language=${language};SameSite=Lax`;
8+
9+
// Set user language preference if logged in
10+
if (CTFd.user.id) {
11+
await CTFd.fetch("/api/v1/users/me", {
12+
method: "PATCH",
13+
body: JSON.stringify({ language }),
14+
});
15+
}
16+
17+
// Reload with new language
18+
window.location.reload();
19+
20+
},
21+
}));
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import $ from "jquery";
2+
import CTFd from "./index";
3+
4+
$(".toggle-button").click(function() {
5+
function foo (res) {
6+
$("#"+res.id).html(res.data)
7+
if(res.data === "enabled"){
8+
$("#"+res.id).removeClass("bg-danger").addClass("bg-success")
9+
}else{
10+
$("#"+res.id).removeClass("bg-success").addClass("bg-danger")
11+
}}
12+
$.get(`/admin/inlineTranslation/config/${this.id}`,function(res){
13+
foo(res)
14+
})
15+
});
16+
17+
$("select").on('change',function(){
18+
CTFd.fetch(`/admin/inlineTranslation/config/${this.id}`, {
19+
method: "POST",
20+
credentials: "same-origin",
21+
headers: {
22+
Accept: "application/json",
23+
"Content-Type": "application/json",
24+
},
25+
body: JSON.stringify({
26+
value: this.value
27+
}),
28+
})
29+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import CTFd from "@ctfdio/ctfd-js";
2+
3+
import dayjs from "dayjs";
4+
import advancedFormat from "dayjs/plugin/advancedFormat";
5+
6+
import highlight from "./theme/highlight";
7+
import styles from "./theme/styles";
8+
import times from "./theme/times";
9+
10+
import alerts from "./utils/alerts";
11+
import collapse from "./utils/collapse";
12+
import tooltips from "./utils/tooltips";
13+
14+
import eventAlerts from "./utils/notifications/alerts";
15+
import eventRead from "./utils/notifications/read";
16+
import eventToasts from "./utils/notifications/toasts";
17+
18+
import "./components/language";
19+
20+
dayjs.extend(advancedFormat);
21+
CTFd.init(window.init);
22+
23+
(() => {
24+
styles();
25+
times();
26+
highlight();
27+
28+
alerts();
29+
tooltips();
30+
collapse();
31+
32+
eventRead();
33+
eventAlerts();
34+
eventToasts();
35+
})();
36+
37+
export default CTFd;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import CTFd from "../index";
2+
import lolight from "lolight";
3+
4+
export default () => {
5+
if (
6+
// default to true if config is not defined yet
7+
!CTFd.config.themeSettings.hasOwnProperty("use_builtin_code_highlighter") ||
8+
CTFd.config.themeSettings.use_builtin_code_highlighter === true
9+
) {
10+
lolight("pre code");
11+
}
12+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export default () => {
2+
document.querySelectorAll(".form-control").forEach($el => {
3+
$el.addEventListener("onfocus", () => {
4+
$el.classList.remove("input-filled-invalid");
5+
$el.classList.add("input-filled-valid");
6+
});
7+
8+
$el.addEventListener("onblur", () => {
9+
if ($el.nodeValue === "") {
10+
$el.classList.remove("input-filled-valid");
11+
$el.classList.remove("input-filled-invalid");
12+
}
13+
});
14+
15+
if ($el.nodeValue) {
16+
$el.classList.add("input-filled-valid");
17+
}
18+
});
19+
20+
document.querySelectorAll(".page-select").forEach($el => {
21+
$el.addEventListener("change", e => {
22+
const url = new URL(window.location);
23+
url.searchParams.set("page", e.target.value ?? "1");
24+
window.location.href = url.toString();
25+
});
26+
});
27+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import dayjs from "dayjs";
2+
import advancedFormat from "dayjs/plugin/advancedFormat";
3+
4+
dayjs.extend(advancedFormat);
5+
6+
export default () => {
7+
document.querySelectorAll("[data-time]").forEach($el => {
8+
const time = $el.getAttribute("data-time");
9+
const format = $el.getAttribute("data-time-format") || "MMMM Do, h:mm:ss A";
10+
$el.innerText = dayjs(time).format(format);
11+
});
12+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Alert } from "bootstrap";
2+
3+
export default () => {
4+
const alertList = [].slice.call(document.querySelectorAll(".alert"));
5+
alertList.map(function (element) {
6+
return new Alert(element);
7+
});
8+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Tooltip } from "bootstrap";
2+
3+
export function copyToClipboard($input) {
4+
const tooltip = new Tooltip($input, {
5+
title: "Copied!",
6+
trigger: "manual",
7+
});
8+
9+
navigator.clipboard.writeText($input.value).then(() => {
10+
tooltip.show();
11+
setTimeout(() => {
12+
tooltip.hide();
13+
}, 1500);
14+
});
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Collapse } from "bootstrap";
2+
3+
export default () => {
4+
const collapseList = [].slice.call(document.querySelectorAll(".collapse"));
5+
collapseList.map(element => {
6+
return new Collapse(element, { toggle: false });
7+
});
8+
};

0 commit comments

Comments
 (0)