Moved login-code into a separate function.
This makes it easier to log in users by their token from unittests.
This commit is contained in:
@@ -33,6 +33,11 @@ class UserClass(flask_login.UserMixin):
|
|||||||
|
|
||||||
|
|
||||||
class AnonymousUser(flask_login.AnonymousUserMixin):
|
class AnonymousUser(flask_login.AnonymousUserMixin):
|
||||||
|
@property
|
||||||
|
def objectid(self):
|
||||||
|
"""Anonymous user has no settable objectid."""
|
||||||
|
return None
|
||||||
|
|
||||||
def has_role(self, *roles):
|
def has_role(self, *roles):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -73,6 +78,13 @@ def config_login_manager(app):
|
|||||||
return login_manager
|
return login_manager
|
||||||
|
|
||||||
|
|
||||||
|
def login_user(oauth_token):
|
||||||
|
"""Log in the user identified by the given token."""
|
||||||
|
|
||||||
|
user = UserClass(oauth_token)
|
||||||
|
flask_login.login_user(user)
|
||||||
|
|
||||||
|
|
||||||
def get_blender_id_oauth_token():
|
def get_blender_id_oauth_token():
|
||||||
"""Returns a tuple (token, ''), for use with flask_oauthlib."""
|
"""Returns a tuple (token, ''), for use with flask_oauthlib."""
|
||||||
return session.get('blender_id_oauth_token')
|
return session.get('blender_id_oauth_token')
|
||||||
|
@@ -6,11 +6,12 @@ import urlparse
|
|||||||
|
|
||||||
from flask import (abort, Blueprint, current_app, flash, redirect,
|
from flask import (abort, Blueprint, current_app, flash, redirect,
|
||||||
render_template, request, session, url_for)
|
render_template, request, session, url_for)
|
||||||
from flask_login import login_required, login_user, logout_user, current_user
|
from flask_login import login_required, logout_user, current_user
|
||||||
from flask_oauthlib.client import OAuthException
|
from flask_oauthlib.client import OAuthException
|
||||||
from werkzeug import exceptions as wz_exceptions
|
from werkzeug import exceptions as wz_exceptions
|
||||||
|
|
||||||
from pillar.auth import UserClass, subscriptions
|
import pillar.auth
|
||||||
|
from pillar.auth import subscriptions
|
||||||
from pillar.web import system_util
|
from pillar.web import system_util
|
||||||
from .forms import UserProfileForm
|
from .forms import UserProfileForm
|
||||||
from .forms import UserSettingsEmailsForm
|
from .forms import UserSettingsEmailsForm
|
||||||
@@ -57,9 +58,7 @@ def blender_id_authorized():
|
|||||||
|
|
||||||
session['blender_id_oauth_token'] = (oauth_resp['access_token'], '')
|
session['blender_id_oauth_token'] = (oauth_resp['access_token'], '')
|
||||||
|
|
||||||
user = UserClass(oauth_resp['access_token'])
|
pillar.auth.login_user(oauth_resp['access_token'])
|
||||||
login_user(user)
|
|
||||||
current_app.login_manager.reload_user() # This ensures that flask_login.current_user is set.
|
|
||||||
|
|
||||||
if current_user is not None:
|
if current_user is not None:
|
||||||
# Check with the store for user roles. If the user has an active
|
# Check with the store for user roles. If the user has an active
|
||||||
@@ -91,8 +90,7 @@ def login_local():
|
|||||||
return abort(r.status_code)
|
return abort(r.status_code)
|
||||||
res = r.json()
|
res = r.json()
|
||||||
# If correct, receive token and log in the user
|
# If correct, receive token and log in the user
|
||||||
user = UserClass(res['token'])
|
pillar.auth.login_user(res['token'])
|
||||||
login_user(user)
|
|
||||||
return redirect(url_for('main.homepage'))
|
return redirect(url_for('main.homepage'))
|
||||||
return render_template('users/login.html', form=form)
|
return render_template('users/login.html', form=form)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user