Revision 081070a5
b/snf-astakos-app/astakos/im/auth_providers.py | ||
---|---|---|
34 | 34 |
|
35 | 35 |
from django.core.urlresolvers import reverse |
36 | 36 |
from django.utils.translation import ugettext as _ |
37 |
from django.utils.datastructures import SortedDict |
|
37 | 38 |
|
38 |
from astakos.im import settings |
|
39 |
from django.conf import settings |
|
40 |
from astakos.im import settings as astakos_settings |
|
39 | 41 |
|
40 | 42 |
import logging |
41 | 43 |
|
42 | 44 |
logger = logging.getLogger(__name__) |
43 | 45 |
|
44 | 46 |
# providers registry |
45 |
PROVIDERS = {} |
|
47 |
PROVIDERS = SortedDict() |
|
48 |
_PROVIDERS = {} |
|
46 | 49 |
|
47 | 50 |
class AuthProviderBase(type): |
48 | 51 |
|
... | ... | |
52 | 55 |
type_id = dct.get('module') |
53 | 56 |
if type_id: |
54 | 57 |
include = True |
55 |
if type_id in settings.IM_MODULES: |
|
58 |
if type_id in astakos_settings.IM_MODULES:
|
|
56 | 59 |
dct['module_enabled'] = True |
57 | 60 |
|
58 | 61 |
newcls = super(AuthProviderBase, cls).__new__(cls, name, bases, dct) |
59 | 62 |
if include: |
60 |
PROVIDERS[type_id] = newcls |
|
63 |
_PROVIDERS[type_id] = newcls
|
|
61 | 64 |
return newcls |
62 | 65 |
|
63 | 66 |
|
... | ... | |
73 | 76 |
def __init__(self, user=None): |
74 | 77 |
self.user = user |
75 | 78 |
|
79 |
def __getattr__(self, key): |
|
80 |
if not key.startswith('get_'): |
|
81 |
return super(AuthProvider, self).__getattr__(key) |
|
82 |
|
|
83 |
if key.endswith('_display') or key.endswith('template'): |
|
84 |
attr = key.replace('_display', '').replace('get_','') |
|
85 |
settings_attr = self.get_setting(attr.upper()) |
|
86 |
if not settings_attr: |
|
87 |
return getattr(self, attr) |
|
88 |
return settings_attr |
|
89 |
else: |
|
90 |
return super(AuthProvider, self).__getattr__(key) |
|
91 |
|
|
76 | 92 |
def get_setting(self, name, default=None): |
77 |
attr = 'AUTH_PROVIDER_%s_%s' % (self.module.upper(), name.upper()) |
|
93 |
attr = 'ASTAKOS_AUTH_PROVIDER_%s_%s' % (self.module.upper(), name.upper())
|
|
78 | 94 |
return getattr(settings, attr, default) |
79 | 95 |
|
80 | 96 |
def is_available_for_login(self): |
... | ... | |
93 | 109 |
self.is_active()) |
94 | 110 |
|
95 | 111 |
def is_active(self): |
96 |
return self.module in settings.IM_MODULES |
|
112 |
return self.module in astakos_settings.IM_MODULES
|
|
97 | 113 |
|
98 | 114 |
|
99 | 115 |
class LocalAuthProvider(AuthProvider): |
100 | 116 |
module = 'local' |
101 | 117 |
title = _('Local password') |
102 | 118 |
description = _('Create a local password for your account') |
119 |
create_prompt = _('Create an account') |
|
120 |
add_prompt = _('Create a local password for your account') |
|
103 | 121 |
|
104 | 122 |
|
105 | 123 |
@property |
106 | 124 |
def add_url(self): |
107 | 125 |
return reverse('password_change') |
108 | 126 |
|
109 |
add_description = _('Create a local password for your account') |
|
110 |
login_template = 'auth/local_login_form.html' |
|
111 |
add_template = 'auth/local_add_action.html' |
|
112 | 127 |
one_per_user = True |
128 |
|
|
129 |
login_template = 'im/auth/local_login_form.html' |
|
130 |
login_prompt_template = 'im/auth/local_login_prompt.html' |
|
131 |
signup_prompt_template = 'im/auth/local_signup_prompt.html' |
|
113 | 132 |
details_tpl = _('You can login to your account using your' |
114 | 133 |
' %(auth_backend)s password.') |
115 | 134 |
|
... | ... | |
123 | 142 |
title = _('Academic credentials (Shibboleth)') |
124 | 143 |
description = _('Allows you to login to your account using your academic ' |
125 | 144 |
'credentials') |
145 |
add_prompt = _('Add academic credentials to your account.') |
|
126 | 146 |
|
127 | 147 |
@property |
128 | 148 |
def add_url(self): |
129 | 149 |
return reverse('astakos.im.target.shibboleth.login') |
130 | 150 |
|
131 |
add_description = _('Allows you to login to your account using your academic ' |
|
132 |
'credentials') |
|
133 |
login_template = 'auth/shibboleth_login_form.html' |
|
134 |
add_template = 'auth/shibboleth_add_action.html' |
|
135 |
details_tpl = _('You can login to your account using your' |
|
136 |
' shibboleth credentials. Shibboleth id: %(identifier)s') |
|
151 |
login_template = 'im/auth/shibboleth_login.html' |
|
152 |
login_prompt_template = 'im/auth/shibboleth_login_prompt.html' |
|
137 | 153 |
|
138 | 154 |
|
139 | 155 |
def get_provider(id, user_obj=None, default=None): |
... | ... | |
142 | 158 |
""" |
143 | 159 |
return PROVIDERS.get(id, default)(user_obj) |
144 | 160 |
|
161 |
|
|
162 |
for module in astakos_settings.IM_MODULES: |
|
163 |
if module in _PROVIDERS: |
|
164 |
PROVIDERS[module] = _PROVIDERS[module] |
|
165 |
|
b/snf-astakos-app/astakos/im/context_processors.py | ||
---|---|---|
48 | 48 |
return {'im_modules': IM_MODULES} |
49 | 49 |
|
50 | 50 |
def auth_providers(request): |
51 |
return {'auth_providers': filter(lambda p:p.module_enabled, |
|
52 |
AUTH_PROVIDERS.itervalues())} |
|
51 |
active_auth_providers = filter(lambda p:p.module_enabled, |
|
52 |
AUTH_PROVIDERS.itervalues()) |
|
53 |
auth_providers = map(lambda p: p(), active_auth_providers) |
|
54 |
return {'auth_providers': auth_providers, |
|
55 |
'master_auth_provider': auth_providers[0]} |
|
53 | 56 |
|
54 | 57 |
def next(request): |
55 | 58 |
return {'next': get_query(request).get('next', '')} |
b/snf-astakos-app/astakos/im/templates/im/auth/local_login_form.html | ||
---|---|---|
1 |
<form action="{% url astakos.im.target.local.login %}" method="post"class="login innerlabels">{% csrf_token %} |
|
2 |
<h2>LOGIN</h2> |
|
3 |
{% with login_form as form %} |
|
4 |
{% include "im/form_render.html" %} |
|
5 |
{% endwith %} |
|
6 |
<input type="hidden" name="next" value="{{ next }}"> |
|
7 |
|
|
8 |
{% if key %} |
|
9 |
<input type="hidden" name="key" value="{{key}}"> |
|
10 |
{% else %} |
|
11 |
{% if request.GET.key %} |
|
12 |
<input type="hidden" name="key" value="{{request.GET.key}}"> |
|
13 |
{% endif %} |
|
14 |
{% endif %} |
|
15 |
|
|
16 |
<div class="form-row submit clearfix"> |
|
17 |
<input type="submit" class="submit altcol" value="SUBMIT" /> |
|
18 |
<a class="extra-link" href="{% url django.contrib.auth.views.password_reset %}">Forgot your password?</a> |
|
19 |
</div> |
|
20 |
</form> |
b/snf-astakos-app/astakos/im/templates/im/auth/local_login_prompt.html | ||
---|---|---|
1 |
<form action="{% url astakos.im.target.local.login %}" method="post"class="login innerlabels">{% csrf_token %} |
|
2 |
<h2 class="form-toggler"><a href="#">LOGIN USING YOUR LOCAL ACCOUNT</a></h2> |
|
3 |
<div class="form" style="display:none"> |
|
4 |
{% with login_form as form %} |
|
5 |
{% include "im/form_render.html" %} |
|
6 |
{% endwith %} |
|
7 |
<input type="hidden" name="next" value="{{ next }}"> |
|
8 |
|
|
9 |
{% if key %} |
|
10 |
<input type="hidden" name="key" value="{{key}}"> |
|
11 |
{% else %} |
|
12 |
{% if request.GET.key %} |
|
13 |
<input type="hidden" name="key" value="{{request.GET.key}}"> |
|
14 |
{% endif %} |
|
15 |
{% endif %} |
|
16 |
|
|
17 |
<div class="form-row submit clearfix"> |
|
18 |
<input type="submit" class="submit altcol" value="SUBMIT" /> |
|
19 |
<a class="extra-link" href="{% url django.contrib.auth.views.password_reset %}">Forgot your password?</a> |
|
20 |
</div> |
|
21 |
</div> |
|
22 |
</form> |
|
23 |
<script> |
|
24 |
$(document).ready(function(){ |
|
25 |
$("h2.form-toggler a").click(function(e) { |
|
26 |
e.preventDefault(); |
|
27 |
$("div.form").slideToggle(); |
|
28 |
}) |
|
29 |
}) |
|
30 |
</script> |
b/snf-astakos-app/astakos/im/templates/im/auth/local_signup_prompt.html | ||
---|---|---|
1 |
new to okeanos ? |
|
2 |
<a href="{% url astakos.im.views.signup %}{% ifnotequal code "" %}?code={{ code|urlencode }}{% endifnotequal %}"> |
|
3 |
{{ provider.get_create_prompt_display }} |
|
4 |
</a> |
|
5 |
|
b/snf-astakos-app/astakos/im/templates/im/auth/shibboleth_login.html | ||
---|---|---|
1 |
<h2><a href="/im/login/shibboleth">LOGIN OR CREATE ACCOUNT USING SHIBBOLETH</a></h2> |
b/snf-astakos-app/astakos/im/templates/im/auth/shibboleth_login_prompt.html | ||
---|---|---|
1 |
LOGIN using |
|
2 |
<a href="/im/login/shibboleth?{% ifnotequal next "" %}&next={{ next|urlencode }}{% endifnotequal %}{% ifnotequal code ""%}{% if next != "" %}&{% else %}?{% endif %}code={{ code }}{% endifnotequal %}" |
|
3 |
alt="{{ provider.get_title_display }}">{{ provider.get_title_display }}</a> |
b/snf-astakos-app/astakos/im/templates/im/auth/shibboleth_quick_login.html | ||
---|---|---|
1 |
LOGIN using 11 |
|
2 |
<a href="/im/login/shibboleth?{% ifnotequal next "" %}&next={{ next|urlencode }}{% endifnotequal %}{% ifnotequal code ""%}{% if next != "" %}&{% else %}?{% endif %}code={{ code }}{% endifnotequal %}" |
|
3 |
alt="{{ o|title }}">{{ provider }}</a> |
b/snf-astakos-app/astakos/im/templates/im/login_base.html | ||
---|---|---|
9 | 9 |
{% endblock body.left %} |
10 | 10 |
|
11 | 11 |
{% block body.right %} |
12 |
{% if "local" in im_modules %} |
|
13 |
<form action="{% url astakos.im.target.local.login %}" method="post"class="login innerlabels">{% csrf_token %} |
|
14 |
<h2>LOGIN</h2> |
|
15 |
{% with login_form as form %} |
|
16 |
{% include "im/form_render.html" %} |
|
17 |
{% endwith %} |
|
18 |
<input type="hidden" name="next" value="{{ next }}"> |
|
19 |
|
|
20 |
{% if key %} |
|
21 |
<input type="hidden" name="key" value="{{key}}"> |
|
22 |
{% else %} |
|
23 |
{% if request.GET.key %} |
|
24 |
<input type="hidden" name="key" value="{{request.GET.key}}"> |
|
25 |
{% endif %} |
|
26 |
{% endif %} |
|
27 |
|
|
28 |
<div class="form-row submit clearfix"> |
|
29 |
<input type="submit" class="submit altcol" value="SUBMIT" /> |
|
30 |
<a class="extra-link" href="{% url django.contrib.auth.views.password_reset %}">Forgot your password?</a> |
|
31 |
</div> |
|
32 |
</form> |
|
33 |
{% endif %} |
|
12 |
|
|
13 |
{% include master_auth_provider.login_template %} |
|
14 |
|
|
34 | 15 |
<div class="extralogin"> |
35 |
{% for o in im_modules %} |
|
36 |
<div> |
|
37 |
{% if o != 'local' %} |
|
38 |
LOGIN using |
|
39 |
<a href="/im/login/{{ o }}?{% ifnotequal next "" %}&next={{ next|urlencode }}{% endifnotequal %}{% ifnotequal code ""%}{% if next != "" %}&{% else %}?{% endif %}code={{ code }}{% endifnotequal %}" |
|
40 |
alt="{{ o|title }}">{{ o }}</a> |
|
41 |
{% endif %} |
|
42 |
</div> |
|
43 |
{% endfor %} |
|
16 |
{% for provider in auth_providers %} |
|
17 |
{% if not provider == master_auth_provider %} |
|
18 |
{% include provider.login_prompt_template %} |
|
19 |
{% endif %} |
|
20 |
{% endfor %} |
|
44 | 21 |
</div><br /> |
45 |
{% block body.signup %} |
|
46 |
{% for o in im_modules %} |
|
47 |
{% if o != 'local' %} |
|
48 |
|
|
49 |
{% endif %} |
|
50 |
{% endfor %} |
|
51 |
<div class="bottom"> |
|
52 |
{% block body.login.signup %} |
|
53 |
new to okeanos ? <a href="{% url astakos.im.views.signup %}{% ifnotequal code "" %}?code={{ code|urlencode }}{% endifnotequal %}">CREATE ACCOUNT</a> |
|
54 |
{% endblock %} |
|
55 |
</div> |
|
22 |
<div class="bottom"> |
|
23 |
{% block body.signup %} |
|
24 |
{% for provider in auth_providers %} |
|
25 |
{% include provider.signup_prompt_template %} |
|
26 |
{% endfor %} |
|
27 |
</div> |
|
56 | 28 |
{% endblock body.signup %} |
57 | 29 |
|
58 | 30 |
{% endblock body.right%} |
Also available in: Unified diff