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
This commit is contained in:
Matthew Scragg 2015-11-06 17:44:48 -06:00
parent e635be8961
commit 0b1c55f6a5
9 changed files with 24 additions and 11 deletions

View file

@ -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():

View file

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

View file

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

View file

@ -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

View file

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