From 6c76f0fc47b9907418118575754abfb524214153 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Thu, 7 Jan 2016 00:23:00 -0600 Subject: [PATCH] public profile page --- ctf.nginx | 6 +++- server/api/user.py | 3 +- web/index.html | 1 + web/js/easyctf.js | 40 ++++++++++++++--------- web/pages/profile.html | 1 + web/pages/settings.html | 71 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 105 insertions(+), 17 deletions(-) create mode 100644 web/pages/settings.html 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 @@
diff --git a/web/pages/settings.html b/web/pages/settings.html new file mode 100644 index 0000000..fc22a07 --- /dev/null +++ b/web/pages/settings.html @@ -0,0 +1,71 @@ +
+
+
+
+

Account Settings

+
+ +
+
+
+
+
+
+

Public Profile

+
+
+

Hi.

+
+
+
+
+
+
+

Email

+
+
+

Hi.

+
+
+
+
+

Email Preferences

+
+
+

Hi.

+
+
+
+
+
+
+

Change Password

+
+
+

Hi.

+
+
+
+
+

Active Sessions

+
+
+

Hi.

+
+
+
+
+
+ + \ No newline at end of file