public profile page

This commit is contained in:
Michael Zhang 2016-01-07 00:23:00 -06:00
parent 177d4bf4ca
commit 6c76f0fc47
6 changed files with 105 additions and 17 deletions

View file

@ -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;
}
}
}

View file

@ -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()

View file

@ -18,6 +18,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-rc.0/angular-route.min.js" integrity="sha384-9MZDoFf10trgrfsQOs9GJhf/mP/sh5weVp3FDSi8h/4TEaV6dloEDkpxGTaOmAs6" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.9.3/js/bootstrap-select.min.js" integrity="sha384-1qZEXZBmj54fSiiWT8bZQGEpCumJWDrAoEqMdg6N5bTTLCkU5RXoNeUsKWekRYob" crossorigin="anonymous"></script>
<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="/js/easyctf.js"></script>
</head>

View file

@ -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"];
}

View file

@ -30,6 +30,7 @@
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
<li role="presentation"><a href="#activity" aria-controls="activity" role="tab" data-toggle="tab">Activity</a></li>
<a href="/settings" class="btn btn-primary" style="float:right;" ng-show="user['me']==true"><i class="fa fa-fw fa-pencil"></i> Edit Profile</a>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="profile">

71
web/pages/settings.html Normal file
View file

@ -0,0 +1,71 @@
<div class="row">
<div class="col-sm-3 col-xs-12">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Account Settings</h4>
</div>
<div class="list-group">
<a href="#profile" class="list-group-item" data-scroll>Profile</a>
<a href="#email" class="list-group-item" data-scroll>Email</a>
<a href="#security" class="list-group-item" data-scroll>Security</a>
</div>
</div>
</div>
<div class="col-sm-9 col-xs-12">
<section id="profile">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Public Profile</h4>
</div>
<div class="panel-body">
<p>Hi.</p>
</div>
</div>
</section>
<section id="email">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Email</h4>
</div>
<div class="panel-body">
<p>Hi.</p>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Email Preferences</h4>
</div>
<div class="panel-body">
<p>Hi.</p>
</div>
</div>
</section>
<section id="security">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Change Password</h4>
</div>
<div class="panel-body">
<p>Hi.</p>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Active Sessions</h4>
</div>
<div class="panel-body">
<p>Hi.</p>
</div>
</div>
</section>
</div>
</div>
<script type="text/javascript">
smoothScroll.init({
speed: 480,
easing: "easeOutCubic",
offset: $("#navbar").outerHeight(),
updateURL: false
});
</script>