Commit 8cccbc87 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

astakos: Handle invalid provider ids

parent 765b04f9
......@@ -57,6 +57,10 @@ PROVIDERS = {}
REQUIRED_PROVIDERS = {}
class InvalidProvider(Exception):
pass
class AuthProviderBase(type):
def __new__(cls, name, bases, dct):
......@@ -667,6 +671,6 @@ def get_provider(module, user_obj=None, identifier=None, **params):
Return a provider instance from the auth providers registry.
"""
if not module in PROVIDERS:
raise Exception('Invalid auth provider "%s"' % module)
raise InvalidProvider('Invalid auth provider "%s"' % module)
return PROVIDERS.get(module)(user_obj, identifier, **params)
......@@ -409,6 +409,12 @@ def signup(request, template_name='im/signup.html', on_success='index',
return HttpResponseRedirect(reverse('index'))
provider = get_query(request).get('provider', 'local')
try:
auth.get_provider(provider)
except auth.InvalidProvider, e:
messages.error(request, e.message)
return HttpResponseRedirect(reverse("signup"))
if not auth.get_provider(provider).get_create_policy:
logger.error("%s provider not available for signup", provider)
raise PermissionDenied
......@@ -591,9 +597,14 @@ def logout(request, template='registration/logged_out.html',
else:
last_provider = request.COOKIES.get(
'astakos_last_login_method', 'local')
provider = auth.get_provider(last_provider)
try:
provider = auth.get_provider(last_provider)
except auth.InvalidProvider:
provider = auth.get_provider('local')
message = provider.get_logout_success_msg
extra = provider.get_logout_success_extra_msg
if extra:
message += "<br />" + extra
messages.success(request, message)
......
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