Updated flask-login to version 0.3.2

This commit is contained in:
Adam Shimali
2016-05-04 13:01:55 +01:00
parent d20228ea25
commit 09117e5eeb
11 changed files with 19 additions and 20 deletions

View File

@@ -18,7 +18,7 @@ def choose_service():
@main.route("/services-or-dashboard")
def show_all_services_or_dashboard():
if not current_user.is_authenticated():
if not current_user.is_authenticated:
return redirect(url_for('.index'))
services = service_api_client.get_services({'user_id': current_user.id})['data']

View File

@@ -1,6 +1,6 @@
import markdown
import os
from flask import (render_template, url_for, redirect, Markup, current_app, abort)
from flask import (render_template, url_for, redirect, Markup)
from app.main import main
from flask_login import login_required
@@ -10,7 +10,7 @@ from mdx_gfm import GithubFlavoredMarkdownExtension
@main.route('/')
def index():
if current_user and current_user.is_authenticated():
if current_user and current_user.is_authenticated:
return redirect(url_for('main.choose_service'))
return render_template('views/signedout.html')

View File

@@ -24,7 +24,7 @@ def accept_invite(token):
invited_user = invite_api_client.check_token(token)
if not current_user.is_anonymous() and current_user.email_address != invited_user.email_address:
if not current_user.is_anonymous and current_user.email_address != invited_user.email_address:
message = Markup("""
Youre signed in as {}.
This invite is for another email address.

View File

@@ -26,7 +26,7 @@ from app import user_api_client
@main.route('/register', methods=['GET', 'POST'])
def register():
if current_user and current_user.is_authenticated():
if current_user and current_user.is_authenticated:
return redirect(url_for('main.choose_service'))
form = RegisterUserForm()

View File

@@ -29,7 +29,7 @@ from app.main.forms import LoginForm
@main.route('/sign-in', methods=(['GET', 'POST']))
def sign_in():
if current_user and current_user.is_authenticated():
if current_user and current_user.is_authenticated:
return redirect(url_for('main.choose_service'))
form = LoginForm()
@@ -52,9 +52,10 @@ def sign_in():
if user:
# Remember me login
if not login_fresh() and \
not current_user.is_anonymous() and \
not current_user.is_anonymous and \
current_user.id == user.id and \
user.is_active():
user.is_active:
confirm_login()
services = service_api_client.get_services({'user_id': str(user.id)}).get('data', [])
if (len(services) == 1):
@@ -63,7 +64,7 @@ def sign_in():
return redirect(url_for('main.choose_service'))
session['user_details'] = {"email": user.email_address, "id": user.id}
if user.is_active():
if user.is_active:
user_api_client.send_verify_code(user.id, 'sms', user.mobile_number)
if request.args.get('next'):
return redirect(url_for('.two_factor', next=request.args.get('next')))

View File

@@ -59,7 +59,7 @@ def verify_email(token):
if not user:
abort(404)
if user.is_active():
if user.is_active:
flash("That verification link has expired.")
return redirect(url_for('main.sign_in'))

View File

@@ -17,14 +17,16 @@ class User(UserMixin):
def get_id(self):
return self.id
@property
def is_active(self):
return self.state == 'active'
@property
def is_authenticated(self):
# To handle remember me token renewal
if not login_fresh():
return False
return super(User, self).is_authenticated()
return super(User, self).is_authenticated
@property
def id(self):

View File

@@ -39,7 +39,7 @@
<a href="#proposition-links" class="js-header-toggle menu">Menu</a>
<nav id="proposition-menu">
<ul id="proposition-links">
{% if current_user.is_authenticated() %}
{% if current_user.is_authenticated %}
<li>
<a href="{{ url_for('main.user_profile') }}">{{ current_user.name }}</a>
</li>

View File

@@ -23,13 +23,11 @@ class Config(object):
REMEMBER_COOKIE_DURATION = timedelta(days=1)
REMEMBER_COOKIE_HTTPONLY = True
REMEMBER_COOKIE_NAME = 'notify_admin_remember_me'
REMEMBER_COOKIE_PATH = '/admin'
REMEMBER_COOKIE_SECURE = True
SECRET_KEY = os.environ['SECRET_KEY']
SEND_FILE_MAX_AGE_DEFAULT = 365 * 24 * 60 * 60 # 1 year
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_NAME = 'notify_admin_session'
SESSION_COOKIE_PATH = '/admin'
SESSION_COOKIE_SECURE = True
SESSION_REFRESH_EACH_REQUEST = True
SHOW_STYLEGUIDE = True
@@ -60,6 +58,7 @@ class Development(Config):
REMEMBER_COOKIE_SECURE = False
SESSION_COOKIE_SECURE = False
WTF_CSRF_ENABLED = False
SESSION_PROTECTION = None
CSV_UPLOAD_BUCKET_NAME = 'development-notifications-csv-upload'

View File

@@ -1,7 +1,7 @@
Flask==0.10.1
Flask-Script==2.0.5
Flask-WTF==0.11
Flask-Login==0.2.11
Flask-Login==0.3.2
credstash==1.8.0
boto3==1.3.0
Pygments==2.0.2

View File

@@ -14,15 +14,12 @@ def test_render_sign_in_returns_sign_in_template(app_):
def test_logged_in_user_redirects_to_choose_service(app_,
api_user_active,
mock_get_user_by_email,
mock_login):
mock_get_user):
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
response = client.get(url_for('main.sign_in'))
assert response.status_code == 302
response = client.get(url_for('main.sign_in', follow_redirects=True))
assert response.location == url_for('main.choose_service', _external=True)