admin controller

This commit is contained in:
Michael Zhang 2016-01-07 02:40:19 -06:00
parent d6694d06a5
commit f4a3f4513c
4 changed files with 62 additions and 14 deletions

View file

@ -8,12 +8,12 @@
font-weight: bold;
}
* {
body {
font-family: "Proxima Nova", Helvetica Neue, Helvetica, Arial, sans-serif;
}
.tab-content {
padding: 10px;
padding: 15px;
> .tab-pane {
display: none;
}

View file

@ -20,6 +20,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.4.3/jquery.timeago.min.js" integrity="sha384-Bap3DetwPgo4GEFvaIDVSIrz5G0mUAUsfCUcEsi+JrrNu7dyj3gBmuAG4hDIGg/4" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/smooth-scroll/7.1.1/js/smooth-scroll.min.js" integrity="sha384-bznoxhRX5dRiE60JhQSru8t7g2RPG9lwqvyut8sjFFWmsAlp+R38e7DiATv1YyIu" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ckeditor/4.5.4/ckeditor.js" integrity="sha384-N2/iPbB6nrU8RupS9WXTBZ1d2TRMI9qixvmdYNC+cbc12q9+YRW0Kw99QZfmYQzq" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.2/ace.js" integrity="sha384-niN+bRlaXMBoq/f5L4zKOEYGxuD0YRGBocto9LP2fB1UiMfxrymATRN4GqjVUt6J" crossorigin="anonymous"></script>
<script src="/js/easyctf.js"></script>
<script src="/js/admin.js"></script>
</head>

View file

@ -62,6 +62,7 @@ app.controller("mainController", ["$scope", "$http", function($scope, $http) {
$scope.config.navbar.logged_in = result["logged_in"];
$scope.config.navbar.username = result["username"];
$scope.config.navbar.admin = result["admin"];
$scope.$emit("adminStatus");
} else {
$scope.config.navbar.logged_in = false;
}
@ -91,8 +92,22 @@ app.controller("profileController", ["$controller", "$scope", "$http", "$routePa
});
}]);
app.controller("adminProblemsController", ["$controller", "$scope", "$http", function($controller, $scope, $http) {
app.controller("adminController", ["$controller", "$scope", "$http", function($controller, $scope, $http) {
$controller("mainController", { $scope: $scope });
$scope.$on("adminStatus", function() {
if ($scope.config["navbar"].logged_in != true) {
location.href = "/login";
return;
}
if ($scope.config["navbar"].admin != true) {
location.href = "/profile";
return;
}
});
}]);
app.controller("adminProblemsController", ["$controller", "$scope", "$http", function($controller, $scope, $http) {
$controller("adminController", { $scope: $scope });
$.post("/api/admin/problems/list", function(result) {
if (result["success"] == 1) {
$scope.problems = result["problems"];

View file

@ -2,6 +2,13 @@
<h1>Problem Editor</h1>
</div>
<style>
.ace_editor {
width: 100%;
height: 200px;
}
</style>
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#problems" aria-controls="problems" role="tab" data-toggle="tab">Problems</a></li>
<li role="presentation"><a href="#filesystem" aria-controls="filesystem" role="tab" data-toggle="tab">Filesystem</a></li>
@ -42,12 +49,12 @@
<div id="register_msg"></div>
</fieldset>
<fieldset class="container-fluid">
<p>Be sure you are familiar with guidelines to writing problems before you submit!</p>
<p>Be sure you are familiar with guidelines to writing problems before you submit! Problem unlocking and other options will be available after you submit your problem.</p>
<div class="row">
<div class="col-sm-12 form-group">
<label class="col-sm-12" for="name"><small>Problem Title</small></label>
<label class="col-sm-12" for="name"><small>Title</small></label>
<div class="col-sm-12">
<input class="form-control" type="text" required name="name" placeholder="Problem Title" autocomplete="off" />
<input class="form-control" type="text" required name="name" placeholder="Title" autocomplete="off" />
</div>
</div>
</div>
@ -72,28 +79,50 @@
</div>
<div class="row">
<div class="col-sm-12 form-group">
<label class="col-sm-12" for="value"><small>Problem Value</small></label>
<label class="col-sm-12" for="value"><small>Value</small></label>
<div class="col-sm-12">
<input class="form-control" type="number" required name="value" placeholder="Problem Value" autocomplete="off" value="10" />
<input class="form-control" type="number" required name="value" placeholder="Value" autocomplete="off" value="10" />
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12 form-group">
<label class="col-sm-12" for="description"><small>Problem Description</small></label>
<label class="col-sm-12" for="description"><small>Description</small></label>
<div class="col-sm-12">
<textarea id="new-description" name="description"></textarea>
<textarea id="new_description" name="description"></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12 form-group">
<label class="col-sm-12" for="hint"><small>Problem Hint</small></label>
<label class="col-sm-12" for="hint"><small>Hint</small></label>
<div class="col-sm-12">
<input class="form-control" type="text" required name="hint" placeholder="Problem Hint" autocomplete="off" />
<input class="form-control" type="text" required name="hint" placeholder="Hint" autocomplete="off" />
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12 form-group">
<label class="col-sm-12" for="grader"><small>Grader</small></label>
<div class="col-sm-12">
<div id="new_grader" class="ace_editor">def grade(key, tid):
""" Grade this problem. """
flag = "easyctf{a_flag}"
case_sensitive = True
if (key.find(flag) >= 0) if case_sensitive \
else (key.lower().find(flag.lower()) >= 0):
return { "success": 1, "message": "Correct!" }
return { "success": 0, "message": "Sorry, try again." }</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12 form-group">
<center>
<input type="submit" class="btn btn-primary btn-lg" value="Create" />
</center>
</div>
</div>
</fieldset>
</form>
</div>
@ -115,12 +144,15 @@
$(".selectpicker").selectpicker();
var config = {
toolbar: [
{ name: "basicstyles", items: [ "Bold", "Italic", "Underline", "-", "RemoveFormat" ] },
{ name: "basicstyles", items: [ "Bold", "Italic", "Underline" ] },
{ name: "links", items: [ "Link" ] },
{ name: "paragraph", items: [ "NumberedList", "BulletedList", "-", "Outdent", "Indent", "-", "Blockquote" ] },
{ name: "tools", items: [ "Maximize" ] },
{ name: "document", items: [ "Source" ] },
]
};
CKEDITOR.replace("new-description", config);
CKEDITOR.replace("new_description", config);
var new_grader = ace.edit("new_grader");
new_grader.setTheme("ace/theme/tomorrow");
new_grader.getSession().setMode("ace/mode/python");
</script>