Commit aef56afc authored by Paul Brown's avatar Paul Brown

add support for new version of flask-login and flask-security

parent f2a53614
......@@ -95,7 +95,7 @@ def init_login():
class MyModelView(sqla.ModelView):
def is_accessible(self):
return login.current_user.is_authenticated()
return login.current_user.is_authenticated
# Create customized index view class that handles login & registration
......@@ -103,7 +103,7 @@ class MyAdminIndexView(admin.AdminIndexView):
@expose('/')
def index(self):
if not login.current_user.is_authenticated():
if not login.current_user.is_authenticated:
return redirect(url_for('.login_view'))
return super(MyAdminIndexView, self).index()
......@@ -115,7 +115,7 @@ class MyAdminIndexView(admin.AdminIndexView):
user = form.get_user()
login.login_user(user)
if login.current_user.is_authenticated():
if login.current_user.is_authenticated:
return redirect(url_for('.index'))
link = '<p>Don\'t have an account? <a href="' + url_for('.register_view') + '">Click here to register.</a></p>'
self._template_args['form'] = form
......
Flask
Flask-Admin
Flask-SQLAlchemy
Flask-Login==0.2.11
Flask-Login>=0.3.0
......@@ -4,7 +4,7 @@
<div class="row-fluid">
<div>
{% if current_user.is_authenticated() %}
{% if current_user.is_authenticated %}
<h1>Flask-Admin example</h1>
<p class="lead">
Authentication
......@@ -36,4 +36,4 @@
<a class="btn btn-primary" href="/"><i class="icon-arrow-left icon-white"></i> Back</a>
</div>
{% endblock body %}
\ No newline at end of file
{% endblock body %}
{% extends 'admin/base.html' %}
{% block access_control %}
{% if current_user.is_authenticated() %}
{% if current_user.is_authenticated %}
<div class="btn-group pull-right">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
<i class="icon-user"></i> {{ current_user.login }} <span class="caret"></span>
......@@ -11,4 +11,4 @@
</ul>
</div>
{% endif %}
{% endblock %}
\ No newline at end of file
{% endblock %}
......@@ -87,13 +87,13 @@ def init_login():
# Create customized model view class
class MyModelView(ModelView):
def is_accessible(self):
return login.current_user.is_authenticated()
return login.current_user.is_authenticated
# Create customized index view class
class MyAdminIndexView(admin.AdminIndexView):
def is_accessible(self):
return login.current_user.is_authenticated()
return login.current_user.is_authenticated
# Flask views
......
Flask
Flask-Admin
flask-mongoengine
Flask-Login==0.2.11
Flask-Login>=0.3.0
<html>
<body>
<div>
{% if user and user.is_authenticated() %}
{% if user and user.is_authenticated %}
Hello {{ user.login }}! <a href="{{ url_for('logout_view') }}">Logout</a>
{% else %}
Welcome anonymous user!
......
......@@ -56,7 +56,7 @@ security = Security(app, user_datastore)
class MyModelView(sqla.ModelView):
def is_accessible(self):
if not current_user.is_active() or not current_user.is_authenticated():
if not current_user.is_active or not current_user.is_authenticated:
return False
if current_user.has_role('superuser'):
......@@ -69,7 +69,7 @@ class MyModelView(sqla.ModelView):
Override builtin _handle_view in order to redirect users when a view is not accessible.
"""
if not self.is_accessible():
if current_user.is_authenticated():
if current_user.is_authenticated:
# permission denied
abort(403)
else:
......
Flask
Flask-Admin
Flask-SQLAlchemy
Flask-Security==1.7.4
Flask-Login==0.2.11
Flask-Security>=1.7.5
......@@ -11,7 +11,7 @@
<p>
This example shows how you can use <a href="https://pythonhosted.org/Flask-Security/index.html" target="_blank">Flask-Security</a> for authentication.
</p>
{% if not current_user.is_authenticated() %}
{% if not current_user.is_authenticated %}
<p>You can register as a regular user, or log in as a superuser with the following credentials:
<ul>
<li>email: <b>admin</b></li>
......@@ -27,4 +27,4 @@
</div>
</div>
</div>
{% endblock body %}
\ No newline at end of file
{% endblock body %}
{% extends 'admin/base.html' %}
{% block access_control %}
{% if current_user.is_authenticated() %}
{% if current_user.is_authenticated %}
<div class="navbar-text btn-group pull-right">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
<i class="glyphicon glyphicon-user"></i>
......@@ -15,4 +15,4 @@
</ul>
</div>
{% endif %}
{% endblock %}
\ No newline at end of file
{% endblock %}
......@@ -19,12 +19,12 @@ class User(UserMixin):
# Create menu links classes with reloaded accessible
class AuthenticatedMenuLink(MenuLink):
def is_accessible(self):
return current_user.is_authenticated()
return current_user.is_authenticated
class NotAuthenticatedMenuLink(MenuLink):
def is_accessible(self):
return not current_user.is_authenticated()
return not current_user.is_authenticated
# Create custom admin view for authenticated users
......@@ -34,7 +34,7 @@ class MyAdminView(BaseView):
return self.render('authenticated-admin.html')
def is_accessible(self):
return current_user.is_authenticated()
return current_user.is_authenticated
# Create flask app
......
Flask
Flask-Admin
Flask-Login==0.2.11
Flask-Login>=0.3.0
Flask
Flask-Admin
Flask-MongoEngine
Flask-Login==0.2.11
Flask-Login>=0.3.0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment