+
+
-
-
-
-
-
diff --git a/web/js/admin/problems.js b/web/js/admin/problems.js
index 0061b19..e69de29 100644
--- a/web/js/admin/problems.js
+++ b/web/js/admin/problems.js
@@ -1,121 +0,0 @@
-function render_problems() {
- $.post("/api/admin/problem/data", {
- }, function(data) {
- data = data["data"];
- for (var i = 0; i < data.length; i++) {
- files = data[i]["files"];
- var checked = "";
- if (data[i]["disabled"]) {
- checked = "checked";
- }
- problem =
-`
`
- $("#problems").append(problem);
- }
- $("[name=update]").click(function(e) {
- var problem = $(this).parents("form:first");
- var pid = $("input[name=pid]", problem).val();
- var name = $("input[name=name]", problem).val();
- var description = $("textarea[name=description]", problem).val();
- var hint = $("input[name=hint]", problem).val();
- var category = $("input[name=category]", problem).val();
- var value = $("input[name=value]", problem).val();
- var flag = $("input[name=flag]", problem).val();
- var disabled = $("input[name=disabled]", problem).prop("checked") ? 1 : 0;
- update_problem(pid, name, category, description, hint, flag, disabled, value);
- });
- $("[name=delete-modal]").click(function(e) {
- var problem = $(this).parents("form:first");
- var pid = $("input[name=pid]", problem).val();
- var div = $(this).closest("div.panel");
- $("#delete").off().click(function(e) {
- delete_problem(pid, div);
- });
- });
- });
-}
-
-function update_problem(pid, name, category, description, hint, flag, disabled, value) {
- $.post("/api/problem/update", {
- pid: pid,
- name: name,
- category: category,
- description: description,
- hint: hint,
- flag: flag,
- disabled: disabled,
- value: value
- }, function(data) {
- if (data.success == 1) {
- display_message("status_" + pid, "success", data.message, function() {});
- } else {
- display_message("status_" + pid, "danger", data.message, function() {});
- }
- });
-}
-
-function delete_problem(pid, div) {
- $.post("/api/problem/delete", {
- pid: pid
- }, function(data) {
- if (data.success == 1) {
- display_message("delete_status", "success", data.message, function() {
- div.slideUp("normal", function() {
- $(this).remove();
- $("#delete-modal").modal("hide");
- } );
- });
- } else {
- display_message("delete_status", "warning", data.message, function() {});
- }
- });
-}
-
-$(function() {
- render_problems();
-});
diff --git a/web/js/admin/problems.old.js b/web/js/admin/problems.old.js
new file mode 100644
index 0000000..0061b19
--- /dev/null
+++ b/web/js/admin/problems.old.js
@@ -0,0 +1,121 @@
+function render_problems() {
+ $.post("/api/admin/problem/data", {
+ }, function(data) {
+ data = data["data"];
+ for (var i = 0; i < data.length; i++) {
+ files = data[i]["files"];
+ var checked = "";
+ if (data[i]["disabled"]) {
+ checked = "checked";
+ }
+ problem =
+`
+
`
+ $("#problems").append(problem);
+ }
+ $("[name=update]").click(function(e) {
+ var problem = $(this).parents("form:first");
+ var pid = $("input[name=pid]", problem).val();
+ var name = $("input[name=name]", problem).val();
+ var description = $("textarea[name=description]", problem).val();
+ var hint = $("input[name=hint]", problem).val();
+ var category = $("input[name=category]", problem).val();
+ var value = $("input[name=value]", problem).val();
+ var flag = $("input[name=flag]", problem).val();
+ var disabled = $("input[name=disabled]", problem).prop("checked") ? 1 : 0;
+ update_problem(pid, name, category, description, hint, flag, disabled, value);
+ });
+ $("[name=delete-modal]").click(function(e) {
+ var problem = $(this).parents("form:first");
+ var pid = $("input[name=pid]", problem).val();
+ var div = $(this).closest("div.panel");
+ $("#delete").off().click(function(e) {
+ delete_problem(pid, div);
+ });
+ });
+ });
+}
+
+function update_problem(pid, name, category, description, hint, flag, disabled, value) {
+ $.post("/api/problem/update", {
+ pid: pid,
+ name: name,
+ category: category,
+ description: description,
+ hint: hint,
+ flag: flag,
+ disabled: disabled,
+ value: value
+ }, function(data) {
+ if (data.success == 1) {
+ display_message("status_" + pid, "success", data.message, function() {});
+ } else {
+ display_message("status_" + pid, "danger", data.message, function() {});
+ }
+ });
+}
+
+function delete_problem(pid, div) {
+ $.post("/api/problem/delete", {
+ pid: pid
+ }, function(data) {
+ if (data.success == 1) {
+ display_message("delete_status", "success", data.message, function() {
+ div.slideUp("normal", function() {
+ $(this).remove();
+ $("#delete-modal").modal("hide");
+ } );
+ });
+ } else {
+ display_message("delete_status", "warning", data.message, function() {});
+ }
+ });
+}
+
+$(function() {
+ render_problems();
+});
diff --git a/web/js/easyctf.js b/web/js/easyctf.js
index fc3f611..362c275 100644
--- a/web/js/easyctf.js
+++ b/web/js/easyctf.js
@@ -1,91 +1,140 @@
var app = angular.module("easyctf", [ "ngRoute" ]);
app.config(function($routeProvider, $locationProvider) {
- $routeProvider.when("/", {
- templateUrl: "pages/home.html",
- controller: "mainController"
- })
- .when("/about", {
- templateUrl: "pages/about.html",
- controller: "mainController"
- })
- .when("/register", {
- templateUrl: "pages/register.html",
- controller: "mainController"
- })
- .when("/login", {
- templateUrl: "pages/login.html",
- controller: "mainController"
- })
- .when("/chat", {
- templateUrl: "pages/chat.html",
- controller: "mainController"
- })
- .when("/updates", {
- templateUrl: "pages/updates.html",
- controller: "mainController"
- })
- .when("/problems", {
- templateUrl: "pages/problems.html",
- controller: "mainController"
- })
- .when("/programming", {
- templateUrl: "pages/programming.html",
- controller: "mainController"
- })
- .when("/shell", {
- templateUrl: "pages/shell.html",
- controller: "mainController"
- })
- .when("/rules", {
- templateUrl: "pages/rules.html",
- controller: "mainController"
- })
- .when("/scoreboard", {
- templateUrl: "pages/scoreboard.html",
- controller: "mainController"
- })
- .when("/admin/problems", {
- templateUrl: "pages/admin/problems.html",
- controller: "mainController"
- });
- $locationProvider.html5Mode(true);
+ $routeProvider.when("/", {
+ templateUrl: "pages/home.html",
+ controller: "mainController"
+ })
+ .when("/about", {
+ templateUrl: "pages/about.html",
+ controller: "mainController"
+ })
+ .when("/scoreboard", {
+ templateUrl: "pages/scoreboard.html",
+ controller: "mainController"
+ })
+ .when("/learn", {
+ templateUrl: "pages/learn.html",
+ controller: "mainController"
+ })
+ .when("/chat", {
+ templateUrl: "pages/chat.html",
+ controller: "mainController"
+ })
+ .when("/register", {
+ templateUrl: "pages/register.html",
+ controller: "mainController"
+ })
+ .when("/login", {
+ templateUrl: "pages/login.html",
+ controller: "mainController"
+ })
+ .when("/profile", {
+ templateUrl: "pages/profile.html",
+ controller: "profileController"
+ })
+ .when("/logout", {
+ templateUrl: "pages/blank.html",
+ controller: "logoutController"
+ })
+ .when("/admin/problems", {
+ templateUrl: "pages/admin/problems.html",
+ controller: "adminProblemsController"
+ })
+ .otherwise({
+ templateUrl: "pages/404.html",
+ controller: "mainController"
+ });
+ $locationProvider.html5Mode(true);
});
-app.controller("mainController", function($scope) {
+app.controller("mainController", ["$scope", "$http", function($scope, $http) {
+ $scope.config = { navbar: { } };
+ $.post("/api/user/status", function(result) {
+ if (result["success"] == 1) {
+ $scope.config.navbar.logged_in = result["logged_in"];
+ $scope.config.navbar.username = result["username"];
+ $scope.config.navbar.admin = result["admin"];
+ } else {
+ $scope.config.navbar.logged_in = false;
+ }
+ $scope.$apply();
+ }).fail(function() {
+ $scope.config.navbar.logged_in = false;
+ $scope.$apply();
+ });
+}]);
+
+app.controller("logoutController", function() {
+ $.post("/api/user/logout", function(result) {
+ location.href = "/";
+ });
});
+app.controller("profileController", ["$controller", "$scope", "$http", function($controller, $scope, $http) {
+ $controller("mainController", { $scope: $scope });
+ $.post("/api/user/info", function(result) {
+ if (result["success"] == 1) {
+ $scope.user = result["user"];
+ }
+ $scope.$apply();
+ $(".timeago").timeago();
+ });
+}]);
+
+app.controller("adminProblemsController", ["$controller", "$scope", "$http", function($controller, $scope, $http) {
+ $controller("mainController", { $scope: $scope });
+}]);
+
function display_message(containerId, alertType, message, callback) {
- $("#" + containerId).html('
' + message + '
');
- $("#" + containerId).hide().slideDown("fast", "swing", function() {
- window.setTimeout(function () {
- $("#" + containerId).slideUp("fast", "swing", callback);
- }, message.length * 75);
- });
-}
+ $("#" + containerId).html("
" + message + "
");
+ $("#" + containerId).hide().slideDown("fast", "swing", function() {
+ window.setTimeout(function () {
+ $("#" + containerId).slideUp("fast", "swing", callback);
+ }, message.length * 75);
+ });
+};
-function load_navbar() {
- $.post("/api/user/status", {
- },
- function(data) {
- if (data.logged_in) {
- $("#logout").show();
- $("#account_link").show();
- } else {
- $("#login_link").show();
- $("#register_link").show();
- }
- if (data.admin) {
- $("#admin_dropdown").show();
- }
- });
-}
+$.fn.serializeObject = function() {
+ var a, o;
+ o = {};
+ a = this.serializeArray();
+ $.each(a, function() {
+ if (o[this.name]) {
+ if (!o[this.name].push) {
+ o[this.name] = [o[this.name]];
+ }
+ return o[this.name].push(this.value || "");
+ } else {
+ return o[this.name] = this.value || "";
+ }
+ });
+ return o;
+};
-$("#logout").click(function(e) {
- e.preventDefault();
- $.post("/api/user/logout", {
- }, function (data) {
- window.location = "/";
- });
-})
+// register page
-$(document).ready( load_navbar() );
+var register_form = function() {
+ var input = "#register_form input";
+ var data = $("#register_form").serializeObject();
+ $.post("/api/user/register", data, function(result) {
+ if (result["success"] == 1) {
+ location.href = "/profile";
+ } else {
+ display_message("register_msg", "danger", result["message"])
+ }
+ });
+};
+
+// login page
+
+var login_form = function() {
+ var input = "#login_form input";
+ var data = $("#login_form").serializeObject();
+ $.post("/api/user/login", data, function(result) {
+ if (result["success"] == 1) {
+ location.href = "/profile";
+ } else {
+ display_message("login_msg", "danger", result["message"])
+ }
+ });
+};
\ No newline at end of file
diff --git a/web/js/login.js b/web/js/login.js
deleted file mode 100644
index 28754fd..0000000
--- a/web/js/login.js
+++ /dev/null
@@ -1,21 +0,0 @@
-$("#login-form").on("submit", function(e) {
- e.preventDefault();
- login($("#email").val(), $("#password").val());
-});
-
-function login(email, password) {
- $("#login").attr("disabled", "disabled");
- $.post("/api/user/login", {
- email: email,
- password: password
- }, function(data) {
- if (data.success == 1) {
- display_message("status", "success", "Success!", function() {
- $("#login").removeAttr("disabled");
- window.location = "#/account";
- });
- } else {
- display_message("status", "danger", data.message, function() {$("#login").removeAttr("disabled");});
- }
- });
-}
diff --git a/web/js/register.js b/web/js/register.js
deleted file mode 100644
index e53fe6c..0000000
--- a/web/js/register.js
+++ /dev/null
@@ -1,27 +0,0 @@
-$("#registration-form").on("submit", function(e) {
- e.preventDefault();
- register($("#name").val(), $("#username").val(), $("#password").val(), $("#password_confirm").val(), $("#email").val(), $("#g-recaptcha-response").val());
-});
-
-function register(name, username, password, password_confirm, email, captcha_response) {
- $("#register").attr("disabled", "disabled");
- $.post("/api/user/register", {
- name: name,
- username: username,
- password: password,
- password_confirm: password_confirm,
- email: email,
- captcha_response: captcha_response
- }, function(data) {
- $("#status").text(data.message);
- if (data.success == 1) {
- display_message("status", "success", "Success!", function() {
- $("#register").removeAttr("disabled");
- window.location = "#/login";
- });
- } else {
- display_message("status", "danger", data.message, function() {$("#register").removeAttr("disabled")});
- grecaptcha.reset();
- }
- });
-}
diff --git a/web/pages/404.html b/web/pages/404.html
new file mode 100644
index 0000000..dee5283
--- /dev/null
+++ b/web/pages/404.html
@@ -0,0 +1,5 @@
+
+
+
Go away. Stop snooping around, you little creep.
\ No newline at end of file
diff --git a/web/pages/admin/problems.html b/web/pages/admin/problems.html
index 1a2c84e..1d0a668 100644
--- a/web/pages/admin/problems.html
+++ b/web/pages/admin/problems.html
@@ -1,77 +1,5 @@
-
- Problems
-
-
-
-
-
-
-
-
-
- Are you sure you want to delete this problem? You cannot undo this.
-
-
-
-
-
-
+Problems
+
-
-
+
+
\ No newline at end of file
diff --git a/web/pages/blank.html b/web/pages/blank.html
new file mode 100644
index 0000000..e69de29
diff --git a/web/pages/login.html b/web/pages/login.html
index d968590..7ff5137 100644
--- a/web/pages/login.html
+++ b/web/pages/login.html
@@ -1,14 +1,53 @@
-
-
Log-in
-
\ No newline at end of file
diff --git a/web/pages/profile.html b/web/pages/profile.html
new file mode 100644
index 0000000..5fb7a07
--- /dev/null
+++ b/web/pages/profile.html
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
Edit Picture
+
{{ user.name }}
+
@{{ user.username }}
+
+
+
+ {{ user.type }}
+
ADMIN
+
+
+
+
+ Joined
+
+
+
+
+
+
+
+
+
+
+
The user you were looking for doesn't exist. Check to make sure you've spelled the name right.
+
+
+
\ No newline at end of file
diff --git a/web/pages/register.html b/web/pages/register.html
index a991da4..46238ce 100644
--- a/web/pages/register.html
+++ b/web/pages/register.html
@@ -1,64 +1,103 @@
-