Commit 4a56a086 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Configurable auth providers templates/titles

parent 87f85fa3
......@@ -34,15 +34,18 @@
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from django.utils.datastructures import SortedDict
from astakos.im import settings
from django.conf import settings
from astakos.im import settings as astakos_settings
import logging
logger = logging.getLogger(__name__)
# providers registry
PROVIDERS = {}
PROVIDERS = SortedDict()
_PROVIDERS = {}
class AuthProviderBase(type):
......@@ -52,12 +55,12 @@ class AuthProviderBase(type):
type_id = dct.get('module')
if type_id:
include = True
if type_id in settings.IM_MODULES:
if type_id in astakos_settings.IM_MODULES:
dct['module_enabled'] = True
newcls = super(AuthProviderBase, cls).__new__(cls, name, bases, dct)
if include:
PROVIDERS[type_id] = newcls
_PROVIDERS[type_id] = newcls
return newcls
......@@ -73,8 +76,21 @@ class AuthProvider(object):
def __init__(self, user=None):
self.user = user
def __getattr__(self, key):
if not key.startswith('get_'):
return super(AuthProvider, self).__getattr__(key)
if key.endswith('_display') or key.endswith('template'):
attr = key.replace('_display', '').replace('get_','')
settings_attr = self.get_setting(attr.upper())
if not settings_attr:
return getattr(self, attr)
return settings_attr
else:
return super(AuthProvider, self).__getattr__(key)
def get_setting(self, name, default=None):
attr = 'AUTH_PROVIDER_%s_%s' % (self.module.upper(), name.upper())
attr = 'ASTAKOS_AUTH_PROVIDER_%s_%s' % (self.module.upper(), name.upper())
return getattr(settings, attr, default)
def is_available_for_login(self):
......@@ -93,23 +109,26 @@ class AuthProvider(object):
self.is_active())
def is_active(self):
return self.module in settings.IM_MODULES
return self.module in astakos_settings.IM_MODULES
class LocalAuthProvider(AuthProvider):
module = 'local'
title = _('Local password')
description = _('Create a local password for your account')
create_prompt = _('Create an account')
add_prompt = _('Create a local password for your account')
@property
def add_url(self):
return reverse('password_change')
add_description = _('Create a local password for your account')
login_template = 'auth/local_login_form.html'
add_template = 'auth/local_add_action.html'
one_per_user = True
login_template = 'im/auth/local_login_form.html'
login_prompt_template = 'im/auth/local_login_prompt.html'
signup_prompt_template = 'im/auth/local_signup_prompt.html'
details_tpl = _('You can login to your account using your'
' %(auth_backend)s password.')
......@@ -123,17 +142,14 @@ class ShibbolethAuthProvider(AuthProvider):
title = _('Academic credentials (Shibboleth)')
description = _('Allows you to login to your account using your academic '
'credentials')
add_prompt = _('Add academic credentials to your account.')
@property
def add_url(self):
return reverse('astakos.im.target.shibboleth.login')
add_description = _('Allows you to login to your account using your academic '
'credentials')
login_template = 'auth/shibboleth_login_form.html'
add_template = 'auth/shibboleth_add_action.html'
details_tpl = _('You can login to your account using your'
' shibboleth credentials. Shibboleth id: %(identifier)s')
login_template = 'im/auth/shibboleth_login.html'
login_prompt_template = 'im/auth/shibboleth_login_prompt.html'
def get_provider(id, user_obj=None, default=None):
......@@ -142,3 +158,8 @@ def get_provider(id, user_obj=None, default=None):
"""
return PROVIDERS.get(id, default)(user_obj)
for module in astakos_settings.IM_MODULES:
if module in _PROVIDERS:
PROVIDERS[module] = _PROVIDERS[module]
......@@ -48,8 +48,11 @@ def im_modules(request):
return {'im_modules': IM_MODULES}
def auth_providers(request):
return {'auth_providers': filter(lambda p:p.module_enabled,
AUTH_PROVIDERS.itervalues())}
active_auth_providers = filter(lambda p:p.module_enabled,
AUTH_PROVIDERS.itervalues())
auth_providers = map(lambda p: p(), active_auth_providers)
return {'auth_providers': auth_providers,
'master_auth_provider': auth_providers[0]}
def next(request):
return {'next': get_query(request).get('next', '')}
......
<form action="{% url astakos.im.target.local.login %}" method="post"class="login innerlabels">{% csrf_token %}
<h2>LOGIN</h2>
{% with login_form as form %}
{% include "im/form_render.html" %}
{% endwith %}
<input type="hidden" name="next" value="{{ next }}">
{% if key %}
<input type="hidden" name="key" value="{{key}}">
{% else %}
{% if request.GET.key %}
<input type="hidden" name="key" value="{{request.GET.key}}">
{% endif %}
{% endif %}
<div class="form-row submit clearfix">
<input type="submit" class="submit altcol" value="SUBMIT" />
<a class="extra-link" href="{% url django.contrib.auth.views.password_reset %}">Forgot your password?</a>
</div>
</form>
<form action="{% url astakos.im.target.local.login %}" method="post"class="login innerlabels">{% csrf_token %}
<h2 class="form-toggler"><a href="#">LOGIN USING YOUR LOCAL ACCOUNT</a></h2>
<div class="form" style="display:none">
{% with login_form as form %}
{% include "im/form_render.html" %}
{% endwith %}
<input type="hidden" name="next" value="{{ next }}">
{% if key %}
<input type="hidden" name="key" value="{{key}}">
{% else %}
{% if request.GET.key %}
<input type="hidden" name="key" value="{{request.GET.key}}">
{% endif %}
{% endif %}
<div class="form-row submit clearfix">
<input type="submit" class="submit altcol" value="SUBMIT" />
<a class="extra-link" href="{% url django.contrib.auth.views.password_reset %}">Forgot your password?</a>
</div>
</div>
</form>
<script>
$(document).ready(function(){
$("h2.form-toggler a").click(function(e) {
e.preventDefault();
$("div.form").slideToggle();
})
})
</script>
new to okeanos ?
<a href="{% url astakos.im.views.signup %}{% ifnotequal code "" %}?code={{ code|urlencode }}{% endifnotequal %}">
{{ provider.get_create_prompt_display }}
</a>
<h2><a href="/im/login/shibboleth">LOGIN OR CREATE ACCOUNT USING SHIBBOLETH</a></h2>
LOGIN using
<a href="/im/login/shibboleth?{% ifnotequal next "" %}&next={{ next|urlencode }}{% endifnotequal %}{% ifnotequal code ""%}{% if next != "" %}&{% else %}?{% endif %}code={{ code }}{% endifnotequal %}"
alt="{{ provider.get_title_display }}">{{ provider.get_title_display }}</a>
LOGIN using 11
<a href="/im/login/shibboleth?{% ifnotequal next "" %}&next={{ next|urlencode }}{% endifnotequal %}{% ifnotequal code ""%}{% if next != "" %}&{% else %}?{% endif %}code={{ code }}{% endifnotequal %}"
alt="{{ o|title }}">{{ provider }}</a>
......@@ -9,50 +9,22 @@
{% endblock body.left %}
{% block body.right %}
{% if "local" in im_modules %}
<form action="{% url astakos.im.target.local.login %}" method="post"class="login innerlabels">{% csrf_token %}
<h2>LOGIN</h2>
{% with login_form as form %}
{% include "im/form_render.html" %}
{% endwith %}
<input type="hidden" name="next" value="{{ next }}">
{% if key %}
<input type="hidden" name="key" value="{{key}}">
{% else %}
{% if request.GET.key %}
<input type="hidden" name="key" value="{{request.GET.key}}">
{% endif %}
{% endif %}
<div class="form-row submit clearfix">
<input type="submit" class="submit altcol" value="SUBMIT" />
<a class="extra-link" href="{% url django.contrib.auth.views.password_reset %}">Forgot your password?</a>
</div>
</form>
{% endif %}
{% include master_auth_provider.login_template %}
<div class="extralogin">
{% for o in im_modules %}
<div>
{% if o != 'local' %}
LOGIN using
<a href="/im/login/{{ o }}?{% ifnotequal next "" %}&next={{ next|urlencode }}{% endifnotequal %}{% ifnotequal code ""%}{% if next != "" %}&{% else %}?{% endif %}code={{ code }}{% endifnotequal %}"
alt="{{ o|title }}">{{ o }}</a>
{% endif %}
</div>
{% endfor %}
{% for provider in auth_providers %}
{% if not provider == master_auth_provider %}
{% include provider.login_prompt_template %}
{% endif %}
{% endfor %}
</div><br />
{% block body.signup %}
{% for o in im_modules %}
{% if o != 'local' %}
{% endif %}
{% endfor %}
<div class="bottom">
{% block body.login.signup %}
new to okeanos ? <a href="{% url astakos.im.views.signup %}{% ifnotequal code "" %}?code={{ code|urlencode }}{% endifnotequal %}">CREATE ACCOUNT</a>
{% endblock %}
</div>
<div class="bottom">
{% block body.signup %}
{% for provider in auth_providers %}
{% include provider.signup_prompt_template %}
{% endfor %}
</div>
{% endblock body.signup %}
{% endblock body.right%}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment