From 16733cc00a43ced7c9a18ea821e70be922029763 Mon Sep 17 00:00:00 2001 From: James Wang Date: Sat, 2 Jan 2016 13:20:12 -0500 Subject: [PATCH] Use better method for displaying messages --- web/js/admin/problem.js | 11 +++++ web/js/easyctf.js | 99 ++++++++++++++++++++++------------------- web/js/login.js | 5 ++- web/js/register.js | 3 ++ web/pages/login.html | 2 +- web/pages/register.html | 4 +- 6 files changed, 75 insertions(+), 49 deletions(-) create mode 100644 web/js/admin/problem.js diff --git a/web/js/admin/problem.js b/web/js/admin/problem.js new file mode 100644 index 0000000..2adbfb1 --- /dev/null +++ b/web/js/admin/problem.js @@ -0,0 +1,11 @@ +function add_problem(name, category, description, hint, flag, value) { + $.post("/api/problem/add", { + name: name, + category: category, + hint: hint, + flag: flag, + value: value + }, function(data) { + + }) +} diff --git a/web/js/easyctf.js b/web/js/easyctf.js index 3f42a83..1237680 100644 --- a/web/js/easyctf.js +++ b/web/js/easyctf.js @@ -1,51 +1,60 @@ 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" - }); - $locationProvider.html5Mode(true); + $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" + }); + $locationProvider.html5Mode(true); }); app.controller("mainController", function($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); + }); + }, 2000); +} diff --git a/web/js/login.js b/web/js/login.js index f0335cb..74a7c97 100644 --- a/web/js/login.js +++ b/web/js/login.js @@ -4,13 +4,16 @@ $("#login-form").on("submit", function(e) { }); function login(email, password) { + $("#login").attr("disabled", "disabled"); $.post("/api/user/login", { email: email, password: password }, function(data) { - $("#status").text(data.message); if (data.success == 1) { + display_message("status", "success", "Success!", function() {$("#login").removeAttr("disabled");}); // wait then redirect or whatever + } else { + display_message("status", "warning", data.message, function() {$("#login").removeAttr("disabled");}); } }); } diff --git a/web/js/register.js b/web/js/register.js index be3fb03..d6bc090 100644 --- a/web/js/register.js +++ b/web/js/register.js @@ -4,6 +4,7 @@ $("#registration-form").on("submit", function(e) { }); function register(name, username, password, password_confirm, email, captcha_response) { + $("#register").attr("disabled", "disabled"); $.post("/api/user/register", { name: name, username: username, @@ -14,8 +15,10 @@ function register(name, username, password, password_confirm, email, captcha_res }, function(data) { $("#status").text(data.message); if (data.success == 1) { + display_message("status", "success", "Success!", function() {$("#register").removeAttr("disabled")}); // wait then redirect or whatever } else { + display_message("status", "warning", data.message, function() {$("#register").removeAttr("disabled")}); grecaptcha.reset(); } }); diff --git a/web/pages/login.html b/web/pages/login.html index 388e6a6..d968590 100644 --- a/web/pages/login.html +++ b/web/pages/login.html @@ -4,7 +4,7 @@
- +
diff --git a/web/pages/register.html b/web/pages/register.html index 8556dae..a991da4 100644 --- a/web/pages/register.html +++ b/web/pages/register.html @@ -51,14 +51,14 @@
-



- + +