Use better method for displaying messages

This commit is contained in:
James Wang 2016-01-02 13:20:12 -05:00
parent c38948121a
commit 16733cc00a
6 changed files with 75 additions and 49 deletions

11
web/js/admin/problem.js Normal file
View file

@ -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) {
})
}

View file

@ -1,51 +1,60 @@
var app = angular.module("easyctf", [ "ngRoute" ]); var app = angular.module("easyctf", [ "ngRoute" ]);
app.config(function($routeProvider, $locationProvider) { app.config(function($routeProvider, $locationProvider) {
$routeProvider.when("/", { $routeProvider.when("/", {
templateUrl: "pages/home.html", templateUrl: "pages/home.html",
controller: "mainController" controller: "mainController"
}) })
.when("/about", { .when("/about", {
templateUrl: "pages/about.html", templateUrl: "pages/about.html",
controller: "mainController" controller: "mainController"
}) })
.when("/register", { .when("/register", {
templateUrl: "pages/register.html", templateUrl: "pages/register.html",
controller: "mainController" controller: "mainController"
}) })
.when("/login", { .when("/login", {
templateUrl: "pages/login.html", templateUrl: "pages/login.html",
controller: "mainController" controller: "mainController"
}) })
.when("/chat", { .when("/chat", {
templateUrl: "pages/chat.html", templateUrl: "pages/chat.html",
controller: "mainController" controller: "mainController"
}) })
.when("/updates", { .when("/updates", {
templateUrl: "pages/updates.html", templateUrl: "pages/updates.html",
controller: "mainController" controller: "mainController"
}) })
.when("/problems", { .when("/problems", {
templateUrl: "pages/problems.html", templateUrl: "pages/problems.html",
controller: "mainController" controller: "mainController"
}) })
.when("/programming", { .when("/programming", {
templateUrl: "pages/programming.html", templateUrl: "pages/programming.html",
controller: "mainController" controller: "mainController"
}) })
.when("/shell", { .when("/shell", {
templateUrl: "pages/shell.html", templateUrl: "pages/shell.html",
controller: "mainController" controller: "mainController"
}) })
.when("/rules", { .when("/rules", {
templateUrl: "pages/rules.html", templateUrl: "pages/rules.html",
controller: "mainController" controller: "mainController"
}) })
.when("/scoreboard", { .when("/scoreboard", {
templateUrl: "pages/scoreboard.html", templateUrl: "pages/scoreboard.html",
controller: "mainController" controller: "mainController"
}); });
$locationProvider.html5Mode(true); $locationProvider.html5Mode(true);
}); });
app.controller("mainController", function($scope) { app.controller("mainController", function($scope) {
}); });
function display_message(containerId, alertType, message, callback) {
$("#" + containerId).html('<div class="alert alert-' + alertType + '">' + message + '</div>');
$("#" + containerId).hide().slideDown("fast", "swing", function() {
window.setTimeout(function () {
$("#" + containerId).slideUp("fast", "swing", callback);
});
}, 2000);
}

View file

@ -4,13 +4,16 @@ $("#login-form").on("submit", function(e) {
}); });
function login(email, password) { function login(email, password) {
$("#login").attr("disabled", "disabled");
$.post("/api/user/login", { $.post("/api/user/login", {
email: email, email: email,
password: password password: password
}, function(data) { }, function(data) {
$("#status").text(data.message);
if (data.success == 1) { if (data.success == 1) {
display_message("status", "success", "Success!", function() {$("#login").removeAttr("disabled");});
// wait then redirect or whatever // wait then redirect or whatever
} else {
display_message("status", "warning", data.message, function() {$("#login").removeAttr("disabled");});
} }
}); });
} }

View file

@ -4,6 +4,7 @@ $("#registration-form").on("submit", function(e) {
}); });
function register(name, username, password, password_confirm, email, captcha_response) { function register(name, username, password, password_confirm, email, captcha_response) {
$("#register").attr("disabled", "disabled");
$.post("/api/user/register", { $.post("/api/user/register", {
name: name, name: name,
username: username, username: username,
@ -14,8 +15,10 @@ function register(name, username, password, password_confirm, email, captcha_res
}, function(data) { }, function(data) {
$("#status").text(data.message); $("#status").text(data.message);
if (data.success == 1) { if (data.success == 1) {
display_message("status", "success", "Success!", function() {$("#register").removeAttr("disabled")});
// wait then redirect or whatever // wait then redirect or whatever
} else { } else {
display_message("status", "warning", data.message, function() {$("#register").removeAttr("disabled")});
grecaptcha.reset(); grecaptcha.reset();
} }
}); });

View file

@ -4,7 +4,7 @@
<form id="login-form"> <form id="login-form">
<input type="text" class="form-control" placeholder="Email" id="email"> <input type="text" class="form-control" placeholder="Email" id="email">
<input type="password" id="password" name="password" placeholder="Password" class="form-control"> <input type="password" id="password" name="password" placeholder="Password" class="form-control">
<input type="submit" class="btn btn-lg btn-success" value="Login"> <input id="login" type="submit" class="btn btn-lg btn-success" value="Login">
</form> </form>
</div> </div>
<div id="status"></div> <div id="status"></div>

View file

@ -51,14 +51,14 @@
<br> <br>
</div> </div>
<div id="status"></div>
<label>I have read and I agree to <a href="/rules" target="_blank">EasyCTF Rules</a>.</label> <label>I have read and I agree to <a href="/rules" target="_blank">EasyCTF Rules</a>.</label>
<br> <br>
<br> <br>
<input class="style2" type="checkbox" class="form-control" value="didRead"> <input class="style2" type="checkbox" class="form-control" value="didRead">
<br> <br>
<input class="style3" type="submit" class="btn btn-lg btn-success" value="Register"> <input id="register" class="style3" type="submit" class="btn btn-lg btn-success" value="Register">
</div> </div>
</form> </form>
<div id="status"></div>
</div> </div>
</div> </div>