Created
July 8, 2011 20:08
-
-
Save xtoddx/1072697 to your computer and use it in GitHub Desktop.
Tenant switch form enabling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/django-openstack/django_openstack/auth/views.py b/django-openstack/django_openstack/auth/views.py | |
index 23e317f..51fec34 100644 | |
--- a/django-openstack/django_openstack/auth/views.py | |
+++ b/django-openstack/django_openstack/auth/views.py | |
@@ -37,6 +37,36 @@ class Login(forms.SelfHandlingForm): | |
messages.error(request, 'Error authenticating: %s' % e.message) | |
+class LoginWithTenant(forms.SelfHandlingForm): | |
+ username = forms.CharField(max_length="20", label="User Name") | |
+ password = forms.CharField(max_length="20", label="Password", | |
+ widget=forms.PasswordInput()) | |
+ tenant = forms.CharField(max_length="20", label="Tenant") | |
+ | |
+ def handle(self, request, data): | |
+ try: | |
+ token = api.token_create(request, | |
+ "", | |
+ data['username'], | |
+ data['password']) | |
+ tenants = api.token_list_tenants(request, token.id) | |
+ tenants = [t.id for t in tenants] | |
+ if not data['tenant'] in tenants: | |
+ raise api_exceptions.Unauthorized("NOT IN THAT TENANT") | |
+ info = api.token_info(request, token) | |
+ request.session['token'] = token.id | |
+ request.session['user'] = info['user'] | |
+ request.session['admin'] = info['admin'] | |
+ request.session['serviceCatalog'] = token.serviceCatalog | |
+ request.session['tenant'] = data['tenant'] | |
+ logging.info(token.serviceCatalog) | |
+ | |
+ return shortcuts.redirect('dash_overview') | |
+ | |
+ except api_exceptions.Unauthorized as e: | |
+ messages.error(request, 'Error authenticating: %s' % e.message) | |
+ | |
+ | |
def login(request): | |
if request.user and request.user.is_authenticated(): | |
if request.user.is_admin(): | |
@@ -54,7 +84,7 @@ def login(request): | |
def switch_tenants(request, tenant_id): | |
- form, handled = LoginWithoutTenant.maybe_handle( | |
+ form, handled = LoginWithTenant.maybe_handle( | |
request, initial={'tenant': tenant_id}) | |
if handled: | |
return handled |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment