fallback to default avatar if email is not set

auth submodules are registered with initialized
check if auth.local is loaded before accessing registration route
check DB_URI before attempt to create db
Этот коммит содержится в:
Matthew Scragg 2015-11-06 17:44:48 -06:00
родитель e635be8961
Коммит 0b1c55f6a5
9 изменённых файлов: 24 добавлений и 11 удалений

Просмотреть файл

@ -113,6 +113,7 @@ class Assets(Environment):
class MyLDAPLoginManager(LDAPLoginManager):
@property
def attrlist(self):
# the parent method doesn't always work
return None
class RegexConverter(BaseConverter):
@ -188,16 +189,17 @@ def create_app(config=None):
def page_not_found(e):
return render_template('errors/404.html'), 404
if app.config['RELATIVE_PATH']:
if app.config.get('RELATIVE_PATH'):
@app.route("/")
def root():
return redirect(url_for(app.config['ROOT_ENDPOINT']))
return redirect(url_for(app.config.get('ROOT_ENDPOINT')))
app.discover()
# This will be removed at some point
with app.app_context():
db.metadata.create_all(db.get_engine(app))
if app.config.get('DB_URI'):
db.metadata.create_all(db.get_engine(app))
return app

Просмотреть файл

@ -86,7 +86,7 @@ DB_URI = 'sqlite:////tmp/wiki.db'
LDAP = {
'URI': 'ldap://localhost:8389',
# This BIND_DN/BIND_PASSORD default to '', this is shown here for demonstrative purposes
# This BIND_DN/BIND_PASSWORD default to '', this is shown here for demonstrative purposes
# The values '' perform an anonymous bind so we may use search/bind method
'BIND_DN': '',
'BIND_AUTH': '',

Просмотреть файл

@ -119,7 +119,8 @@ def filename_to_cname(filename):
def gravatar_url(email):
return "https://www.gravatar.com/avatar/" + hashlib.md5(email).hexdigest()
email = hashlib.md5(email).hexdigest() if email else "default@realms.io"
return "https://www.gravatar.com/avatar/" + email
def in_virtualenv():

Просмотреть файл

@ -2,6 +2,7 @@ from realms import login_manager
from flask import request, flash, redirect
from flask.ext.login import login_url
modules = set()
@login_manager.unauthorized_handler
def unauthorized():

Просмотреть файл

@ -1 +1,3 @@
from ..models import Auth
Auth.register('ldap')

Просмотреть файл

@ -0,0 +1,3 @@
from ..models import Auth
Auth.register('local')

Просмотреть файл

@ -4,6 +4,7 @@ from realms import login_manager
from realms.lib.util import gravatar_url
from itsdangerous import URLSafeSerializer, BadSignature
from hashlib import sha256
from . import modules
import bcrypt
import importlib
@ -17,6 +18,10 @@ auth_users = {}
class Auth(object):
@staticmethod
def register(module):
modules.add(module)
@staticmethod
def get_auth_user(auth_type):
mod = importlib.import_module('realms.modules.auth.%s.models' % auth_type)
@ -30,8 +35,7 @@ class Auth(object):
@staticmethod
def login_forms():
forms = []
# TODO be dynamic
for t in ['local', 'ldap', 'oauth']:
for t in modules:
forms.append(Auth.get_auth_user(t).login_form())
return "<hr />".join(forms)
@ -61,9 +65,6 @@ class BaseUser(UserMixin):
@property
def avatar(self):
if not self.email:
# TODO return default avatar
return ""
return gravatar_url(self.email)
@staticmethod

Просмотреть файл

@ -0,0 +1,3 @@
from ..models import Auth
Auth.register('oauth')

Просмотреть файл

@ -73,7 +73,7 @@
</li>
{% else %}
<li><a href="{{ url_for('auth.login') }}"><i class="fa fa-user"></i> &nbsp;Login</a></li>
{% if config.REGISTRATION_ENABLED %}
{% if config.REGISTRATION_ENABLED and 'auth.local' in config.MODULES %}
<li><a href="{{ url_for('auth.local.register') }}"><i class="fa fa-users"></i> &nbsp;Register</a></li>
{% endif %}
{% endif %}