diff --git a/ctf.nginx b/ctf.nginx index bd36907..155053f 100644 --- a/ctf.nginx +++ b/ctf.nginx @@ -21,6 +21,10 @@ server { default_type text/html; try_files /index.html /index.html; } + location ~^/profile/(.*)$ { + default_type text/html; + try_files /index.html /index.html; + } location ~ /api { proxy_set_header Host $host; @@ -29,4 +33,4 @@ server { proxy_pass http://localhost:8000; proxy_redirect off; } -} +} \ No newline at end of file diff --git a/server/api/user.py b/server/api/user.py index bc786c8..67b7d9b 100644 --- a/server/api/user.py +++ b/server/api/user.py @@ -91,7 +91,7 @@ def user_info(): username = session["username"] if username is None: raise WebException("No user specified.") - me = username.lower() == session["username"].lower() + me = False if not("username" in session) else username.lower() == session["username"].lower() user = get_user(username_lower=username.lower()).first() if user is None: raise WebException("User not found.") @@ -184,6 +184,7 @@ def login_user(username, password): return True def is_logged_in(): + if not("sid" in session and "username" in session): return False sid = session["sid"] username = session["username"] token = LoginTokens.query.filter_by(sid=sid).first() diff --git a/web/index.html b/web/index.html index ef611de..1fb696a 100644 --- a/web/index.html +++ b/web/index.html @@ -18,6 +18,7 @@ + diff --git a/web/js/easyctf.js b/web/js/easyctf.js index 362c275..147a807 100644 --- a/web/js/easyctf.js +++ b/web/js/easyctf.js @@ -8,33 +8,41 @@ app.config(function($routeProvider, $locationProvider) { templateUrl: "pages/about.html", controller: "mainController" }) - .when("/scoreboard", { - templateUrl: "pages/scoreboard.html", + .when("/chat", { + templateUrl: "pages/chat.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("/logout", { + templateUrl: "pages/blank.html", + controller: "logoutController" + }) .when("/profile", { templateUrl: "pages/profile.html", controller: "profileController" }) - .when("/logout", { - templateUrl: "pages/blank.html", - controller: "logoutController" + .when("/profile/:username", { + templateUrl: "pages/profile.html", + controller: "profileController" + }) + .when("/register", { + templateUrl: "pages/register.html", + controller: "mainController" + }) + .when("/scoreboard", { + templateUrl: "pages/scoreboard.html", + controller: "mainController" + }) + .when("/settings", { + templateUrl: "pages/settings.html", + controller: "mainController" }) .when("/admin/problems", { templateUrl: "pages/admin/problems.html", @@ -70,9 +78,11 @@ app.controller("logoutController", function() { }); }); -app.controller("profileController", ["$controller", "$scope", "$http", function($controller, $scope, $http) { +app.controller("profileController", ["$controller", "$scope", "$http", "$routeParams", function($controller, $scope, $http, $routeParams) { + var data = { }; + if ("username" in $routeParams) data["username"] = $routeParams["username"]; $controller("mainController", { $scope: $scope }); - $.post("/api/user/info", function(result) { + $.post("/api/user/info", data, function(result) { if (result["success"] == 1) { $scope.user = result["user"]; } diff --git a/web/pages/profile.html b/web/pages/profile.html index 5fb7a07..6b3c9a3 100644 --- a/web/pages/profile.html +++ b/web/pages/profile.html @@ -30,6 +30,7 @@