Ejemplo n.º 1
0
 def test_site(self):
     self.assertEqual(unicode(Steer), "Steer")
     self.assertEqual(repr(Steer), "<Site: Steer>")
     dash = Steer.get_dashboard('engine')
     self.assertEqual(Steer.get_default_dashboard(), dash)
     user = User()
     self.assertEqual(Steer.get_user_home(user), dash.get_absolute_url())
Ejemplo n.º 2
0
 def test_site(self):
     self.assertEqual(unicode(Steer), "Steer")
     self.assertEqual(repr(Steer), "<Site: Steer>")
     dash = Steer.get_dashboard('engine')
     self.assertEqual(Steer.get_default_dashboard(), dash)
     user = User()
     self.assertEqual(Steer.get_user_home(user), dash.get_absolute_url())
Ejemplo n.º 3
0
def switch_tenants(request, tenant_id):
    """
    Swaps a user from one tenant to another using the unscoped token from
    Keystone to exchange scoped tokens for the new tenant.
    """
    form, handled = LoginWithTenant.maybe_handle(request,
                                                 initial={
                                                     'tenant':
                                                     tenant_id,
                                                     'username':
                                                     request.user.username
                                                 })
    if handled:
        return handled

    unscoped_token = request.session.get('unscoped_token', None)
    if unscoped_token:
        try:
            token = api.token_create_scoped(request, tenant_id, unscoped_token)
            _set_session_data(request, token)
            user = users.User(users.get_user_from_request(request))
            return shortcuts.redirect(Steer.get_user_home(user))
        except exceptions.Unauthorized as e:
            messages.error(_("You are not authorized for that tenant."))

    # FIXME(gabriel): we don't ship switch_tenants.html
    return shortcuts.render(request, 'switch_tenants.html', {
        'to_tenant': tenant_id,
        'form': form
    })
Ejemplo n.º 4
0
def switch_tenants(request, tenant_id):
    """
    Swaps a user from one tenant to another using the unscoped token from
    Keystone to exchange scoped tokens for the new tenant.
    """
    form, handled = LoginWithTenant.maybe_handle(
            request, initial={'tenant': tenant_id,
                              'username': request.user.username})
    if handled:
        return handled

    unscoped_token = request.session.get('unscoped_token', None)
    if unscoped_token:
        try:
            token = api.token_create_scoped(request,
                                            tenant_id,
                                            unscoped_token)
            _set_session_data(request, token)
            user = users.User(users.get_user_from_request(request))
            return shortcuts.redirect(Steer.get_user_home(user))
        except exceptions.Unauthorized as e:
            messages.error(_("You are not authorized for that tenant."))

    # FIXME(gabriel): we don't ship switch_tenants.html
    return shortcuts.render(request,
                            'switch_tenants.html', {
                                'to_tenant': tenant_id,
                                'form': form})
Ejemplo n.º 5
0
def login(request):
    """
    Logs in a user and redirects them to the URL specified by
    :func:`steer.get_user_home`.
    """
    if request.user.is_authenticated():
        user = users.User(users.get_user_from_request(request))
        return shortcuts.redirect(Steer.get_user_home(user))

    form, handled = Login.maybe_handle(request)
    if handled:
        return handled

    # FIXME(gabriel): we don't ship a view named splash
    return shortcuts.render(request, 'splash.html', {'form': form})
Ejemplo n.º 6
0
def login(request):
    """
    Logs in a user and redirects them to the URL specified by
    :func:`steer.get_user_home`.
    """
    if request.user.is_authenticated():
        user = users.User(users.get_user_from_request(request))
        return shortcuts.redirect(Steer.get_user_home(user))

    form, handled = Login.maybe_handle(request)
    if handled:
        return handled

    # FIXME(gabriel): we don't ship a view named splash
    return shortcuts.render(request, 'splash.html', {'form': form})