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:
parent
e635be8961
commit
0b1c55f6a5
|
@ -113,6 +113,7 @@ class Assets(Environment):
|
||||||
class MyLDAPLoginManager(LDAPLoginManager):
|
class MyLDAPLoginManager(LDAPLoginManager):
|
||||||
@property
|
@property
|
||||||
def attrlist(self):
|
def attrlist(self):
|
||||||
|
# the parent method doesn't always work
|
||||||
return None
|
return None
|
||||||
|
|
||||||
class RegexConverter(BaseConverter):
|
class RegexConverter(BaseConverter):
|
||||||
|
@ -188,16 +189,17 @@ def create_app(config=None):
|
||||||
def page_not_found(e):
|
def page_not_found(e):
|
||||||
return render_template('errors/404.html'), 404
|
return render_template('errors/404.html'), 404
|
||||||
|
|
||||||
if app.config['RELATIVE_PATH']:
|
if app.config.get('RELATIVE_PATH'):
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def root():
|
def root():
|
||||||
return redirect(url_for(app.config['ROOT_ENDPOINT']))
|
return redirect(url_for(app.config.get('ROOT_ENDPOINT')))
|
||||||
|
|
||||||
app.discover()
|
app.discover()
|
||||||
|
|
||||||
# This will be removed at some point
|
# This will be removed at some point
|
||||||
with app.app_context():
|
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
|
return app
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ DB_URI = 'sqlite:////tmp/wiki.db'
|
||||||
LDAP = {
|
LDAP = {
|
||||||
'URI': 'ldap://localhost:8389',
|
'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
|
# The values '' perform an anonymous bind so we may use search/bind method
|
||||||
'BIND_DN': '',
|
'BIND_DN': '',
|
||||||
'BIND_AUTH': '',
|
'BIND_AUTH': '',
|
||||||
|
|
|
@ -119,7 +119,8 @@ def filename_to_cname(filename):
|
||||||
|
|
||||||
|
|
||||||
def gravatar_url(email):
|
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():
|
def in_virtualenv():
|
||||||
|
|
|
@ -2,6 +2,7 @@ from realms import login_manager
|
||||||
from flask import request, flash, redirect
|
from flask import request, flash, redirect
|
||||||
from flask.ext.login import login_url
|
from flask.ext.login import login_url
|
||||||
|
|
||||||
|
modules = set()
|
||||||
|
|
||||||
@login_manager.unauthorized_handler
|
@login_manager.unauthorized_handler
|
||||||
def unauthorized():
|
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 realms.lib.util import gravatar_url
|
||||||
from itsdangerous import URLSafeSerializer, BadSignature
|
from itsdangerous import URLSafeSerializer, BadSignature
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
|
from . import modules
|
||||||
import bcrypt
|
import bcrypt
|
||||||
import importlib
|
import importlib
|
||||||
|
|
||||||
|
@ -17,6 +18,10 @@ auth_users = {}
|
||||||
|
|
||||||
class Auth(object):
|
class Auth(object):
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def register(module):
|
||||||
|
modules.add(module)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_auth_user(auth_type):
|
def get_auth_user(auth_type):
|
||||||
mod = importlib.import_module('realms.modules.auth.%s.models' % auth_type)
|
mod = importlib.import_module('realms.modules.auth.%s.models' % auth_type)
|
||||||
|
@ -30,8 +35,7 @@ class Auth(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def login_forms():
|
def login_forms():
|
||||||
forms = []
|
forms = []
|
||||||
# TODO be dynamic
|
for t in modules:
|
||||||
for t in ['local', 'ldap', 'oauth']:
|
|
||||||
forms.append(Auth.get_auth_user(t).login_form())
|
forms.append(Auth.get_auth_user(t).login_form())
|
||||||
return "<hr />".join(forms)
|
return "<hr />".join(forms)
|
||||||
|
|
||||||
|
@ -61,9 +65,6 @@ class BaseUser(UserMixin):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def avatar(self):
|
def avatar(self):
|
||||||
if not self.email:
|
|
||||||
# TODO return default avatar
|
|
||||||
return ""
|
|
||||||
return gravatar_url(self.email)
|
return gravatar_url(self.email)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
from ..models import Auth
|
||||||
|
|
||||||
|
Auth.register('oauth')
|
|
@ -73,7 +73,7 @@
|
||||||
</li>
|
</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li><a href="{{ url_for('auth.login') }}"><i class="fa fa-user"></i> Login</a></li>
|
<li><a href="{{ url_for('auth.login') }}"><i class="fa fa-user"></i> 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> Register</a></li>
|
<li><a href="{{ url_for('auth.local.register') }}"><i class="fa fa-users"></i> Register</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue