Skip to content

Commit 5236eba

Browse files
committed
Full functionality with Flask.
Signed-off-by: Chris Warrick <[email protected]>
1 parent b794f46 commit 5236eba

10 files changed

+471
-146
lines changed

COMET/__init__.py

+245-106
Large diffs are not rendered by default.

COMET/requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
Flask==0.10.1
22
Flask-Login==0.2.11
3+
Flask-Bcrypt==0.6.0
4+
py-bcrypt==0.4
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<%inherit file="base.tmpl"/>
2+
<%block name="extra_head">
3+
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
4+
<style>
5+
.form-signin {
6+
max-width: 330px;
7+
padding: 15px;
8+
margin: 0 auto;
9+
}
10+
.form-signin .form-signin-heading,
11+
.form-signin .checkbox {
12+
margin-bottom: 10px;
13+
}
14+
.form-signin .checkbox {
15+
font-weight: normal;
16+
}
17+
.form-signin .form-control {
18+
position: relative;
19+
height: auto;
20+
-webkit-box-sizing: border-box;
21+
-moz-box-sizing: border-box;
22+
box-sizing: border-box;
23+
padding: 10px;
24+
font-size: 16px;
25+
}
26+
.form-signin .form-control:focus {
27+
z-index: 2;
28+
}
29+
.form-signin input[type="text"] {
30+
margin-bottom: -1px;
31+
border-bottom-right-radius: 0;
32+
border-bottom-left-radius: 0;
33+
}
34+
.form-signin input[type="password"] {
35+
margin-bottom: 10px;
36+
border-top-left-radius: 0;
37+
border-top-right-radius: 0;
38+
}
39+
</style>
40+
</%block>
41+
<%block name="content">
42+
% if alert:
43+
<div class="alert alert-${alert_status}" role="alert">${alert}</div>
44+
% endif
45+
46+
<form class="form-signin" method="POST" action="/login">
47+
<h2 class="form-signin-heading">Please sign in</h2>
48+
<label for="inputUsername" class="sr-only">Username</label>
49+
<input name="username" type="text" id="inputUsername" class="form-control" placeholder="Username" required autofocus>
50+
<label for="inputPassword" class="sr-only">Password</label>
51+
<input name="password" type="password" id="inputPassword" class="form-control" placeholder="Password" required>
52+
<div class="checkbox">
53+
<label>
54+
<input type="checkbox" name="remember-me" value="remember-me"> Remember me
55+
</label>
56+
</div>
57+
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
58+
</form>
59+
</%block>

COMET/templates/mako/webapp_post_edit.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
</div>
9292
</div>
9393

94-
<textarea name="content" id="content-area" class="form-control" rows="24">${open(path).read().split('\n\n', 1)[1]}</textarea>
94+
<textarea name="content" id="content-area" class="form-control" rows="24">${post_content}</textarea>
9595
</form>
9696
<script src="/wysihtml/dist/wysihtml5x-toolbar.min.js"></script>
9797
<script src="/wysihtml/parser_rules/advanced_and_extended.js"></script>

COMET/templates/mako/webapp_profile.tmpl

+17-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,29 @@
33
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
44
</%block>
55
<%block name="content">
6-
<h1 class="title">Editing profile <tt>${USERNAME}</tt></h1>
6+
<h1 class="title">Editing profile <tt>${current_user.username}</tt></h1>
7+
8+
% if alert:
9+
<div class="alert alert-${alert_status}" role="alert">${alert}</div>
10+
% endif
711

812
<form action="/profile/save" method="POST">
913
<div class="form-group">
1014
<label for="name">Real name</label>
11-
<input class="form-control" id="name" name="name" value="${REALNAME}" placeholder="Real name">
15+
<input class="form-control" id="realname" name="realname" value="${current_user.realname}" placeholder="Real name">
16+
</div>
17+
<div class="form-group">
18+
<label for="oldpwd">Old password:</label>
19+
<input type="password" class="form-control" id="oldpwd" name="oldpwd" placeholder="Old password">
20+
<p class="help-block">If you do not want to change your password, leave the fields blank.</p>
21+
</div>
22+
<div class="form-group">
23+
<label for="newpwd1">New password:</label>
24+
<input type="password" class="form-control" id="newpwd1" name="newpwd1" placeholder="New password">
1225
</div>
1326
<div class="form-group">
14-
<label for="passwd">New password (leave empty to keep previous):</label>
15-
<input type="password" class="form-control" id="password" name="password" placeholder="New password">
27+
<label for="newpwd2">Repeat new password:</label>
28+
<input type="password" class="form-control" id="newpwd2" name="newpwd2" placeholder="Repeat new password">
1629
</div>
1730
<button type="submit" class="btn btn-default">Save</button>
1831
</form>
+78-12
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,111 @@
11
<%inherit file="base.tmpl"/>
22
<%block name="extra_head">
33
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
4+
<style>
5+
.inactive-user .username, .inactive-user .realname {
6+
text-decoration: line-through;
7+
}
8+
</style>
9+
</%block>
10+
<%block name="extra_js">
11+
<script>
12+
$('#deleteModal').on('show.bs.modal', function (event) {
13+
var button = $(event.relatedTarget);
14+
var username = button.data('username');
15+
var uid = button.data('uid');
16+
var direction = button.data('direction');
17+
var modal = $(this);
18+
modal.find('.del-title').text(username);
19+
modal.find('.del-uid').val(uid);
20+
modal.find('.del-direction').val(direction);
21+
if (direction == 'del') {
22+
modal.find('.del-noun').text('deletion');
23+
modal.find('.del-verb').text('delete');
24+
modal.find('.del-verb-capital').text('Delete');
25+
} else {
26+
modal.find('.del-noun').text('undeletion');
27+
modal.find('.del-verb').text('undelete');
28+
modal.find('.del-verb-capital').text('Undelete');
29+
}
30+
});
31+
</script>
432
</%block>
533
<%block name="content">
634
<h1 class="title">Users</h1>
735

36+
% if alert:
37+
<div class="alert alert-${alert_status}" role="alert">${alert}</div>
38+
% endif
39+
840
<table class="table table-hover">
941
<thead><tr>
42+
<th>#</th>
1043
<th>Username</th>
1144
<th>Real name</th>
12-
<th>Can edit users</th>
45+
<th>Admin</th>
1346
<th>Actions</th>
1447
</tr></thead>
15-
% for user, data in USERS.items():
48+
% for uid, user in USERS.items():
49+
% if user.active:
1650
<tr>
17-
<td>${user}</td>
18-
<td>${data['name']}</td>
51+
% else:
52+
<tr class="danger inactive-user">
53+
% endif
54+
<td class="uid">${uid}</td>
55+
<td class="username">${user.username}</td>
56+
<td class="realname">${user.realname}</td>
1957
<td>
20-
% if data['can_edit_users']:
58+
% if user.is_admin:
2159
<i class="fa fa-check"></i>
2260
% else:
2361
<i class="fa fa-times"></i>
2462
% endif
2563
</td>
2664
<td>
65+
<form action="/users/edit" method="POST"><input type="hidden" name="uid" value="${uid}">
2766
<div class="btn-group" role="group">
28-
<a href="/users/${user}" class="btn btn-info btn-xs"><i class="fa fa-pencil"></i></a>
29-
% if user == USERNAME:
30-
<a href="#" class="btn btn-danger btn-xs disabled"><i class="fa fa-trash"></i></a>
67+
% if user.active:
68+
<button type="submit" class="btn btn-info btn-xs"><i class="fa fa-pencil"></i></button>
69+
% if user == current_user:
70+
<button type="button" class="btn btn-danger btn-xs" disabled><i class="fa fa-trash"></i></button>
71+
% else:
72+
<button type="button" class="btn btn-danger btn-xs" data-toggle="modal" data-target="#deleteModal" data-username="${user.username}" data-uid="${uid}" data-direction="del" title="Delete"><i class="fa fa-trash"></i></button>
73+
% endif
3174
% else:
32-
<a href="/users/${user}/delete" class="btn btn-danger btn-xs"><i class="fa fa-trash"></i></a>
75+
<button type="button" class="btn btn-info btn-xs" disabled><i class="fa fa-pencil"></i></button>
76+
<button type="button" class="btn btn-success btn-xs" data-toggle="modal" data-target="#deleteModal" data-username="${user.username}" data-uid="${uid}" data-direction="undel" title="Undelete"><i class="fa fa-trash-o"></i></button>
3377
% endif
3478
</div>
79+
</form>
3580
</tr>
3681
% endfor
37-
<tr><form action="/users/create/new" method="POST">
38-
<td><input name="name" placeholder="User to create"></td>
82+
<tr><form action="/users/new" method="POST">
83+
<td><i class="fa fa-plus"></i></td>
84+
<td><input name="username" placeholder="User to create"></td>
3985
<td></td>
4086
<td></td>
41-
<td><button type="submit" class="btn btn-success btn-xs"><i class="fa fa-check"></button></td>
87+
<td><button type="submit" class="btn btn-success btn-xs"><i class="fa fa-arrow-circle-right"></i></button></td>
4288
</form></tr>
4389
</table>
4490

91+
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
92+
<div class="modal-dialog">
93+
<div class="modal-content">
94+
<div class="modal-header">
95+
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
96+
<h4 class="modal-title" id="deleteModalLabel">Confirm <span class="del-noun">something</span></h4>
97+
</div>
98+
<div class="modal-body">
99+
Really <span class="del-verb">do something to</span> <span class="del-title">user</span>?
100+
</div>
101+
<div class="modal-footer">
102+
<form method="POST" action="/users/delete" class="delete-button">
103+
<input type="hidden" name="uid" class="del-uid">
104+
<input type="hidden" name="direction" class="del-direction">
105+
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
106+
<button type="submit" class="btn btn-danger del-verb-capital">Delete</button>
107+
</div>
108+
</div>
109+
</div>
110+
</div>
45111
</%block>

COMET/templates/mako/webapp_users_edit.tmpl

+34-19
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,55 @@
44
</%block>
55
<%block name="content">
66
% if not new:
7-
<h1 class="title">Editing profile <tt>${name}</tt></h1>
7+
<h1 class="title">Editing profile <tt>${user.username}</tt></h1>
88
% else:
9-
<h1 class="title">Creating profile <tt>${name}</tt></h1>
9+
<h1 class="title">Creating profile <tt>${user.username}</tt></h1>
1010
% endif
1111

12-
<form action="/users/${name}/save" method="POST">
12+
% if alert:
13+
<div class="alert alert-${alert_status}" role="alert">${alert}</div>
14+
% endif
15+
16+
<form action="/users/save" method="POST">
17+
<input name="uid" type="hidden" value="${user.uid}">
1318
<div class="form-group">
1419
<label for="name">Real name</label>
15-
<input class="form-control" id="name" name="name" value="${user['name']}"
20+
<input class="form-control" id="realname" name="realname" value="${user.realname}"
1621
placeholder="Real name" required>
1722
</div>
23+
% if user.password:
1824
<div class="form-group">
19-
% if user['password']:
20-
<label for="passwd">New password (leave empty to keep previous):</label>
21-
% else:
22-
<label for="passwd">Password:</label>
23-
% endif
24-
<input type="password" class="form-control" id="password" name="password"
25-
% if user['password']:
26-
placeholder="New password"
25+
<label for="oldpwd">Old password:</label>
26+
<input type="password" class="form-control" id="oldpwd" name="oldpwd" placeholder="Old password">
27+
<p class="help-block">If you do not want to change the password, leave the fields blank.</p>
28+
</div>
29+
<div class="form-group">
30+
<label for="newpwd1">New password:</label>
31+
<input type="password" class="form-control" id="newpwd1" name="newpwd1" placeholder="New password">
32+
</div>
33+
<div class="form-group">
34+
<label for="newpwd2">Repeat new password:</label>
35+
<input type="password" class="form-control" id="newpwd2" name="newpwd2" placeholder="Repeat new password">
36+
</div>
2737
% else:
28-
placeholder="Password" required
29-
% endif
30-
>
38+
<div class="form-group">
39+
<label for="newpwd1">Password:</label>
40+
<input type="password" class="form-control" id="newpwd1" name="newpwd1" placeholder="Password" required>
3141
</div>
42+
<div class="form-group">
43+
<label for="newpwd2">Repeat password:</label>
44+
<input type="password" class="form-control" id="newpwd2" name="newpwd2" placeholder="Repeat password" required>
45+
</div>
46+
% endif
3247
<div class="checkbox"><label>
33-
<input type="checkbox" name="can_edit_users"
34-
% if user['can_edit_users']:
48+
<input type="checkbox" name="is_admin"
49+
% if user.is_admin:
3550
checked
3651
% endif
37-
% if name == USERNAME:
52+
% if user == current_user:
3853
disabled
3954
% endif
40-
> Can edit users
55+
> Is administrator
4156
</label></div>
4257
<button type="submit" class="btn btn-default">Save</button>
4358
</form>

COMET/users.json

+31-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,34 @@
11
{
2-
"admin": {
3-
"can_edit_users": true,
4-
"password": "c7ad44cbad762a5da0a452f9e854fdc1e0e7a52a38015f23f3eab1d80b931dd472634dfac71cd34ebc35d16ab7fb8a90c81f975113d6c7538dc69dd8de9077ec",
5-
"name": "Website Administrator"
2+
"1": {
3+
"username": "admin",
4+
"realname": "Website Administrator",
5+
"can_see_others_posts": true,
6+
"is_admin": true,
7+
"active": true,
8+
"password": "$2a$12$.qMCcA2uOo0BKkDtEF/bueYtHjcdPBmfEdpxtktRwRTgsR7ZVTWmW"
9+
},
10+
"3": {
11+
"username": "user3",
12+
"realname": "User Three",
13+
"can_see_others_posts": false,
14+
"is_admin": false,
15+
"active": true,
16+
"password": "$2a$12$LGFk3vhXFXA75ZwYIPV6o.Bv/ING9dfSxNroTXQ15tQpjGW9FjCU2"
17+
},
18+
"2": {
19+
"username": "user2",
20+
"realname": "User Two",
21+
"can_see_others_posts": false,
22+
"is_admin": false,
23+
"active": true,
24+
"password": "$2a$12$GlbUlIMPBhLeWbQfK07g8uKsc8LO9P5gI7MyWsRpKt5exajp7ySoK"
25+
},
26+
"4": {
27+
"username": "user4",
28+
"realname": "User Four",
29+
"can_see_others_posts": false,
30+
"is_admin": true,
31+
"active": true,
32+
"password": "$2a$12$7fQihZDxHFayBkUAX2LSgeAX9m8MAkx2jovDv3B6WW47e1UfVV2Ue"
633
}
734
}

conf.py

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# !! This is the configuration of Nikola. !! #
77
# !! You should edit it to your liking. !! #
88

9+
# CHANGE! product of keyboard cat below
10+
COMET_SECRET_KEY = 'ltfpokghw3he4torjmhghgo30w5rektyghbnopfyjk32wo0-khnj4io0h09<F10>45kijhn0=p6kjh=0n5y0v'
911

1012
# ! Some settings can be different in different languages.
1113
# ! A comment stating (translatable) is used to denote those.

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
Flask==0.10.1
22
Flask-Login==0.2.11
3+
Flask-Bcrypt==0.6.0
4+
py-bcrypt==0.4

0 commit comments

Comments
 (0)