Skip to content

Commit

Permalink
add support for new version of flask-login and flask-security
Browse files Browse the repository at this point in the history
  • Loading branch information
pawl committed Dec 12, 2015
1 parent f2a5361 commit aef56af
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 25 deletions.
6 changes: 3 additions & 3 deletions examples/auth-flask-login/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ def load_user(user_id):
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
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()

Expand All @@ -115,7 +115,7 @@ def login_view(self):
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
Expand Down
2 changes: 1 addition & 1 deletion examples/auth-flask-login/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Flask
Flask-Admin
Flask-SQLAlchemy
Flask-Login==0.2.11
Flask-Login>=0.3.0
4 changes: 2 additions & 2 deletions examples/auth-flask-login/templates/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -36,4 +36,4 @@ <h1>Flask-Admin example</h1>

<a class="btn btn-primary" href="/"><i class="icon-arrow-left icon-white"></i> Back</a>
</div>
{% endblock body %}
{% endblock body %}
4 changes: 2 additions & 2 deletions examples/auth-flask-login/templates/my_master.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% 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>
Expand All @@ -11,4 +11,4 @@
</ul>
</div>
{% endif %}
{% endblock %}
{% endblock %}
4 changes: 2 additions & 2 deletions examples/auth-mongoengine/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ def load_user(user_id):
# 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
Expand Down
2 changes: 1 addition & 1 deletion examples/auth-mongoengine/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Flask
Flask-Admin
flask-mongoengine
Flask-Login==0.2.11
Flask-Login>=0.3.0
2 changes: 1 addition & 1 deletion examples/auth-mongoengine/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<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!
Expand Down
4 changes: 2 additions & 2 deletions examples/auth/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __str__(self):
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'):
Expand All @@ -69,7 +69,7 @@ def _handle_view(self, name, **kwargs):
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:
Expand Down
3 changes: 1 addition & 2 deletions examples/auth/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Flask
Flask-Admin
Flask-SQLAlchemy
Flask-Security==1.7.4
Flask-Login==0.2.11
Flask-Security>=1.7.5
4 changes: 2 additions & 2 deletions examples/auth/templates/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h1>Flask-Admin example</h1>
<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>
Expand All @@ -27,4 +27,4 @@ <h1>Flask-Admin example</h1>
</div>
</div>
</div>
{% endblock body %}
{% endblock body %}
4 changes: 2 additions & 2 deletions examples/auth/templates/my_master.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% 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>
Expand All @@ -15,4 +15,4 @@
</ul>
</div>
{% endif %}
{% endblock %}
{% endblock %}
6 changes: 3 additions & 3 deletions examples/menu-external-links/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def __init__(self, id=None):
# 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
Expand All @@ -34,7 +34,7 @@ def index(self):
return self.render('authenticated-admin.html')

def is_accessible(self):
return current_user.is_authenticated()
return current_user.is_authenticated


# Create flask app
Expand Down
2 changes: 1 addition & 1 deletion examples/menu-external-links/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask
Flask-Admin
Flask-Login==0.2.11
Flask-Login>=0.3.0
2 changes: 1 addition & 1 deletion examples/mongoengine/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Flask
Flask-Admin
Flask-MongoEngine
Flask-Login==0.2.11
Flask-Login>=0.3.0

0 comments on commit aef56af

Please sign in to comment.