Commit 3da031b0 authored by Antek Grzanka's avatar Antek Grzanka

Submitting flags per task.

parent 7bb44233
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en" ng-app="ctfApp">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>CTF</title> <title>CTF</title>
...@@ -9,22 +9,22 @@ ...@@ -9,22 +9,22 @@
<link rel="stylesheet" href="/page/statics/css/main.css"> <link rel="stylesheet" href="/page/statics/css/main.css">
</head> </head>
<nav> <nav >
<div class="nav-wrapper container"> <div class="nav-wrapper container">
<a href="#" class="brand-logo"> <a href="#" class="brand-logo">
<span class="title"></span> <span class="title"></span>
</a> </a>
<ul id="nav-mobile" class="right hide-on-med-and-down"> <ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="page#/home">Początek</a></li> <li><a href="page#/home">Początek</a></li>
<li><a href="page#/tasks">Zadania</a></li> <li ><a href="page#/tasks">Zadania</a></li>
<li><a href="page#/scores">Wyniki</a></li> <li ><a href="page#/scores">Wyniki</a></li>
</ul> </ul>
</div> </div>
</nav> </nav>
<body> <body>
<div ng-app="ctfApp" class="container"> <div class="container">
<div ui-view></div> <div ui-view></div>
</div> </div>
</body> </body>
......
...@@ -77,4 +77,16 @@ p { ...@@ -77,4 +77,16 @@ p {
direction: ltr; direction: ltr;
-webkit-font-feature-settings: 'liga'; -webkit-font-feature-settings: 'liga';
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
}
.toast-success {
background-color: green;
color: black;
font-weight: bold;
}
.toast-error {
background-color: red;
color: black;
font-weight: bold;
} }
\ No newline at end of file
...@@ -37,37 +37,39 @@ ...@@ -37,37 +37,39 @@
} }
}); });
app.factory('APIProvider', ['$http', 'AppSettings', function($http, AppSettings){ app.factory('APIProvider', ['$http', 'AppSettings', function($http, AppSettings){
var tasks, teams, scores; var tasks, teams, scores;
var getTasks = function(callback){
$http.get(AppSettings.apiAddress + '/tasks').
success(function(data) {
tasks = data;
if (callback) callback(data);
});
};
var getScores = function(){};
var getTaskById = function(id, callback){
var result;
if (!tasks) {
getTasks(function(data){
result = getTaskById(id, callback)
});
}
else {
result = tasks.filter(function(task){
return task.level == id;
})[0];
}
callback(result);
};
return { return {
getScores: getScores, getScores: function(){},
getTasks: getTasks, getTasks: function(callback){
getTaskById: getTaskById $http.get(AppSettings.apiAddress + '/tasks').
success(function(data) {
tasks = data;
if (callback) callback(data);
});
},
getTaskById: function(id, callback){
var result;
if (!tasks) {
this.getTasks(function(data){
result = this.getTaskById(id, callback)
}.bind(this));
}
else {
result = tasks.filter(function(task){
return task.level == id;
})[0];
}
callback(result);
},
submitFlag: function(flag){
return $http.post(AppSettings.apiAddress + '/tasks', flag);
}
}; };
}]); }]);
app.controller('TasksController', ['$scope', '$http', 'APIProvider', 'AppSettings', function($scope, $http, APIProvider, AppSettings) { app.controller('TasksController', ['$scope', '$http', 'APIProvider', 'AppSettings', function($scope, $http, APIProvider, AppSettings) {
$scope.apiAddress = AppSettings.apiAddress; $scope.apiAddress = AppSettings.apiAddress;
APIProvider.getTasks(function(data){ APIProvider.getTasks(function(data){
...@@ -76,7 +78,8 @@ ...@@ -76,7 +78,8 @@
}); });
}]); }]);
app.controller('TaskController', ['$scope', '$http', '$stateParams', 'APIProvider', 'AppSettings', function($scope, $http, $stateParams, APIProvider, AppSettings) { app.controller('TaskController', ['$scope', '$stateParams', 'APIProvider', 'AppSettings', function($scope, $stateParams, APIProvider, AppSettings) {
$scope.submitUnknown = false;
$scope.apiAddress = AppSettings.apiAddress; $scope.apiAddress = AppSettings.apiAddress;
$scope.selectedTaskId = $stateParams.taskLevel; $scope.selectedTaskId = $stateParams.taskLevel;
console.log('SELECTED TASK ID', $scope.selectedTaskId); console.log('SELECTED TASK ID', $scope.selectedTaskId);
...@@ -84,6 +87,19 @@ ...@@ -84,6 +87,19 @@
console.log(data); console.log(data);
$scope.task = data; $scope.task = data;
}); });
$scope.submitFlag = function(){
var flag = $('input#flag-to-submit').val();
$scope.submitUnknown = true;
APIProvider.submitFlag(flag).success(function(){
Materialize.toast('Poprawna flaga! :)', 5000, 'toast-success');
$scope.submitUnknown = false;
}).error(function(){
console.log("Flaga zla!");
Materialize.toast('Błędna flaga! :(', 5000 ,'toast-error');
$scope.submitUnknown = false;
});
};
}]); }]);
app.controller('ScoreboardController', ['$scope', '$http', 'AppSettings', function($scope, $http, AppSettings) { app.controller('ScoreboardController', ['$scope', '$http', 'AppSettings', function($scope, $http, AppSettings) {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<div class="row"> <div class="row">
<div class="col s12"> <div class="col s12">
<a href="/page#/tasks" class="breadcrumb"><i class="fa fa-angle-left" style="margin-right:20px"></i> Powrót</a> <a href="/page#/tasks" class="breadcrumb"><i class="fa fa-angle-left" style="margin-right:20px"></i> Powrót</a>
<h1 class="leftr-align">{{task.name}}</h1> <h1 class="left-align">{{task.name}}</h1>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
...@@ -36,13 +36,24 @@ ...@@ -36,13 +36,24 @@
Nie dodano żadnych flag. Nie dodano żadnych flag.
</p> </p>
<button class="btn waves-effect waves-light" type="submit" name="action" style="float:right">Submit <button ng-click="submitFlag()" class="btn waves-effect waves-light" type="submit" name="action" style="float:right" ng-if="!submitUnknown">Submit
<i class="material-icons right">send</i> <i class="material-icons right">send</i>
</button> </button>
<div class="input-field" style="overflow:hidden"> <div class="preloader-wrapper small active" style="float:right" ng-if="submitUnknown">
<input placeholder="Wpisz flagę" id="flag-to-submit" type="text" class="validate"> <div class="spinner-layer spinner-green-only">
<div class="circle-clipper left">
<div class="circle"></div>
</div><div class="gap-patch">
<div class="circle"></div>
</div><div class="circle-clipper right">
<div class="circle"></div>
</div>
</div>
</div>
<div class="input-field" style="overflow:hidden" >
<input placeholder="Wpisz flagę" id="flag-to-submit" type="text" class="validate">
</div> </div>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment