Adapted to support changes in Flask-Login 0.3
This commit is contained in:
parent
5e9cc831e8
commit
751a8aefe5
|
@ -50,12 +50,15 @@ class User(db.Model):
|
||||||
version += 1
|
version += 1
|
||||||
return new_nickname
|
return new_nickname
|
||||||
|
|
||||||
|
@property
|
||||||
def is_authenticated(self):
|
def is_authenticated(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@property
|
||||||
def is_active(self):
|
def is_active(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@property
|
||||||
def is_anonymous(self):
|
def is_anonymous(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -47,13 +47,13 @@
|
||||||
<a class="brand" href="{{ url_for('index') }}">microblog</a>
|
<a class="brand" href="{{ url_for('index') }}">microblog</a>
|
||||||
<ul class="nav">
|
<ul class="nav">
|
||||||
<li><a href="{{ url_for('index') }}">{{ _('Home') }}</a></li>
|
<li><a href="{{ url_for('index') }}">{{ _('Home') }}</a></li>
|
||||||
{% if g.user.is_authenticated() %}
|
{% if g.user.is_authenticated %}
|
||||||
<li><a href="{{ url_for('user', nickname=g.user.nickname) }}">{{ _('Your Profile') }}</a></li>
|
<li><a href="{{ url_for('user', nickname=g.user.nickname) }}">{{ _('Your Profile') }}</a></li>
|
||||||
<li><a href="{{ url_for('logout') }}">{{ _('Logout') }}</a></li>
|
<li><a href="{{ url_for('logout') }}">{{ _('Logout') }}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
<div class="nav-collapse collapse">
|
<div class="nav-collapse collapse">
|
||||||
{% if g.user.is_authenticated() %}
|
{% if g.user.is_authenticated %}
|
||||||
<form class="navbar-search pull-right" action="{{ url_for('search') }}" method="post" name="search">{{ g.search_form.hidden_tag() }}{{ g.search_form.search(size=20, placeholder=_('Search'), class="search-query")}}</form>
|
<form class="navbar-search pull-right" action="{{ url_for('search') }}" method="post" name="search">{{ g.search_form.hidden_tag() }}{{ g.search_form.search(size=20, placeholder=_('Search'), class="search-query")}}</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -28,7 +28,7 @@ def get_locale():
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def before_request():
|
def before_request():
|
||||||
g.user = current_user
|
g.user = current_user
|
||||||
if g.user.is_authenticated():
|
if g.user.is_authenticated:
|
||||||
g.user.last_seen = datetime.utcnow()
|
g.user.last_seen = datetime.utcnow()
|
||||||
db.session.add(g.user)
|
db.session.add(g.user)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -84,7 +84,7 @@ def index(page=1):
|
||||||
@app.route('/login', methods=['GET', 'POST'])
|
@app.route('/login', methods=['GET', 'POST'])
|
||||||
@oid.loginhandler
|
@oid.loginhandler
|
||||||
def login():
|
def login():
|
||||||
if g.user is not None and g.user.is_authenticated():
|
if g.user is not None and g.user.is_authenticated:
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
form = LoginForm()
|
form = LoginForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
Babel==1.3
|
Babel==1.3
|
||||||
Flask==0.10.1
|
Flask==0.10.1
|
||||||
Flask-Babel==0.9
|
Flask-Babel==0.9
|
||||||
Flask-Login==0.2.11
|
Flask-Login==0.3.0
|
||||||
Flask-Mail==0.9.0
|
Flask-Mail==0.9.0
|
||||||
Flask-OpenID==1.2.1
|
Flask-OpenID==1.2.1
|
||||||
Flask-SQLAlchemy==2.0
|
Flask-SQLAlchemy==2.0
|
||||||
|
|
6
tests.py
6
tests.py
|
@ -37,9 +37,9 @@ class TestCase(unittest.TestCase):
|
||||||
u = User(nickname='john', email='john@example.com')
|
u = User(nickname='john', email='john@example.com')
|
||||||
db.session.add(u)
|
db.session.add(u)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
assert u.is_authenticated() is True
|
assert u.is_authenticated is True
|
||||||
assert u.is_active() is True
|
assert u.is_active is True
|
||||||
assert u.is_anonymous() is False
|
assert u.is_anonymous is False
|
||||||
assert u.id == int(u.get_id())
|
assert u.id == int(u.get_id())
|
||||||
|
|
||||||
def test_avatar(self):
|
def test_avatar(self):
|
||||||
|
|
Loading…
Reference in New Issue