Skip to content

Commit f807c18

Browse files
committed
Merge pull request #105 from dongweiming/react
security templates use jinja2
2 parents cee7a9e + b31f17e commit f807c18

File tree

6 files changed

+116
-91
lines changed

6 files changed

+116
-91
lines changed

firefly/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ def not_found_page(error):
8181

8282

8383
def register_blueprints(app):
84-
from firefly.views import (home, post, category, api, keyboard, user)
85-
for i in (home, post, category, api, keyboard, user):
84+
from firefly.views import (home, post, category, api, keyboard, user, auth)
85+
for i in (home, post, category, api, keyboard, user, auth):
8686
app.register_blueprint(i.bp)
8787

8888

firefly/libs/template.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
from flask import render_template as _render_template
33

44
from flask_login import current_user
5+
from flask_security.utils import url_for_security
56

67

78
def render_template(template_name_or_list, **context):
8-
context.update({'current_user': current_user})
9+
context.update({
10+
'current_user': current_user,
11+
'url_for_security': url_for_security
12+
})
913
return _render_template(template_name_or_list, **context)
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
-inherit /base.html
1+
{% extends "base.html" %}
22

3-
-def head_script()
4-
link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet"
5-
link href="${url_for('static', filename='stylesheets/screen.css')}" rel="stylesheet"
3+
{% block head_script %}
4+
<link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet"/>
5+
<link href="{{url_for('static', filename='stylesheets/screen.css')}}" rel="stylesheet"/>
6+
<link href="{{url_for('static', filename='stylesheets/index.css')}}" rel="stylesheet" media="all"/>
7+
{% endblock %}
68

7-
-def footer_script()
8-
script
9-
require(['../static/javascripts/common'], function (common) {
9+
{% block footer_script %}
10+
<script>
11+
require(['../../static/javascripts/common'], function (common) {
1012
require(['accounts']);
11-
});
13+
});
14+
</script>
15+
{% endblock %}
Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,42 @@
1-
-inherit accounts/base.html
2-
-block container
3-
div.container
4-
div.row
5-
div.page-header
6-
h1.text-center
7-
Hi ${current_user.cn}
8-
div.row
9-
div.col-md-3.col-md-offset-3
10-
img.img-circle.img-responsive.mg-btm src="${current_user.gravatar}?s=300&d=retro" alt=""
11-
div.col-md-3
12-
dl
13-
dt
14-
邮箱
15-
dd
16-
${current_user.email}
17-
dt
18-
First name
19-
dd
20-
${current_user.first_name}
21-
dt
22-
Last name
23-
dd
24-
${ current_user.last_name}
25-
a.btn.btn-primary.btn-lg href="${url_for_security('logout')}
26-
Logout
27-
28-
-py
29-
connections = current_user.social_connections()
30-
-if connections
31-
div.row
32-
div.text-center.mg-btm
33-
h2.text-center
34-
Connections
35-
- for connection in connections
36-
a href="${connection.profile_url}"
37-
img.img-circle src="${connection.image_url}" alt="" width="50" height="50"
1+
{% extends "/security/accounts/base.html" %}
2+
{% block outlet %}
3+
<div class="container">
4+
<div class="row">
5+
<div class="page-header">
6+
<h1 class="text-center">
7+
Hi {{current_user.cn.decode('utf-8')}}
8+
</h1>
9+
</div>
10+
</div>
11+
<div class="row">
12+
<div class="col-md-3 col-md-offset-3">
13+
<img class="img-circle img-responsive mg-btm" alt="" src="{{current_user.gravatar}}?s=300&d=retro"/>
14+
</div>
15+
<div class="col-md-3">
16+
<dl>
17+
<dt>邮箱</dt>
18+
<dd>{{current_user.email}}</dd>
19+
<dt>First name</dt>
20+
<dd>{{current_user.first_name}}</dd>
21+
<dt>Last name</dt>
22+
<dd>{{current_user.last_name}}</dd>
23+
<a class="btn btn-primary btn-lg" href="{{url_for_security('logout')}}">Logout</a>
24+
</dl>
25+
</div>
26+
{% set connections = current_user.social_connections() %}
27+
{% if connections %}
28+
<div class="row">
29+
<div class="text-center mg-btm">
30+
<h2 class="text-center">Connections
31+
{% for connection in connections %}
32+
<a href="{{connection.profile_url}}">
33+
<img class="img-circle" alt="" width="50" height="50" src="{{connection.image_url}}"/>
34+
</a>
35+
{% endfor %}
36+
</h2>
37+
</div>
38+
</div>
39+
{% endif %}
40+
</div>
41+
</div>
42+
{% endblock %}
Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,55 @@
1-
-inherit accounts/base.html
2-
-block container
3-
div.container
4-
div.row
5-
div.page-header
6-
h1.text-center
7-
Please sign in
8-
div.row
9-
div.col-md-5.col-md-offset-1
10-
div.social-login-buttons
11-
a.social-facebook.btn.btn-default.btn-lg href="${url_for('social.login', provider='Facebook')}"
12-
i.fa.fa-facebook-square with Facebook
13-
a.social-google.btn.btn-default.btn-lg href="${url_for('social.login', provider='Google')}"
14-
i.fa.fa-google-plus with Google
15-
a.social-github.btn.btn-default.btn-lg href="${url_for('social.login', provider='Github')}"
16-
i.fa.fa-github with Github
17-
a.social-twitter.btn.btn-default.btn-lg href="${url_for('social.login', provider='Twitter')}"
18-
i.fa.fa-twitter with Twitter
1+
{% extends "base.html" %}
2+
{% block outlet %}
3+
<div class="container">
4+
<div class="row">
5+
<div class="page-header">
6+
<h1 class="text-center">Please sign in</h1>
7+
</div>
8+
</div>
9+
<div class="row">
10+
<div class="col-md-5 col-md-offset-1">
11+
<div class="social-login-buttons">
12+
<a class="social-facebook btn btn-default btn-lg" href="{{url_for('social.login', provider='Facebook')}}">
13+
<i class="fa fa-facebook-square">with Facebook</i>
14+
</a>
15+
<a class="social-google btn btn-default btn-lg" href="{{url_for('social.login', provider='Google')}}">
16+
<i class="fa fa-google-plus">with Google</i>
17+
</a>
18+
<a class="social-github btn btn-default btn-lg" href="{{url_for('social.login', provider='Github')}}">
19+
<i class="fa fa-github">with Github</i>
20+
</a>
21+
<a class="social-twitter btn btn-default btn-lg" href="{{url_for('social.login', provider='Twitter')}}">
22+
<i class="fa fa-twitter">with Twitter</i>
23+
</a>
24+
</div>
25+
</div>
1926

20-
div.col-md-5
21-
form.form-signin role="form"
22-
input type="email" class="form-control input-lg" placeholder="Email address" required autofocus
23-
input type="password" class="form-control input-lg" placeholder="Password" required
24-
label.checkbox
25-
input id="remember" name="remember" type="checkbox" value="y"
26-
Remember me
27-
input id="next" name="next" type="hidden" value=""
28-
button.btn.btn-lg.btn-primary.btn-block type="submit"
29-
Sign in
30-
div.text-center
31-
ul.nav.nav-pills style="display: inline-block;"
32-
li
33-
a href="${url_for_security('login')}"
34-
Login
35-
li
36-
a href="${url_for_security('register')}"
37-
Register
38-
li
39-
a href="${url_for_security('forgot_password')}"
40-
Forgot password
41-
li
42-
a href="${url_for_security('send_confirmation')}"
43-
Confirm account
27+
<div class="col-md-5">
28+
<form class="form-signin" action="" role="form">
29+
<input type="email" class="form-control input-lg" placeholder="Email address" required="required" autofocus="autofocus"/>
30+
<input type="password" class="form-control input-lg" placeholder="Password" required="required"/>
31+
<label class="checkbox" for=""></label>
32+
<input id="remember" name="remember" type="checkbox" value="y">Remember me
33+
<input id="next" name="next" type="hidden" value=""/>
34+
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
35+
</form>
36+
</div>
37+
<div class="text-center">
38+
<ul class="nav nav-pills" style="display: inline-block;">
39+
<li>
40+
<a href="{{url_for_security('login')}}">Login</a>
41+
</li>
42+
<li>
43+
<a href="{{url_for_security('register')}}">Register</a>
44+
</li>
45+
<li>
46+
<a href="{{url_for_security('forgot_password')}}">Forgot password</a>
47+
</li>
48+
<li>
49+
<a href="{{url_for_security('send_confirmation')}}">Confirm account</a>
50+
</li>
51+
</ul>
52+
</div>
53+
</div>
54+
</div>
55+
{% endblock %}

firefly/views/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
@bp.route('/')
1212
@login_required
1313
def profile():
14-
return render_template('accounts/profile.html')
14+
return render_template('security/accounts/profile.html')

0 commit comments

Comments
 (0)