Example #1
0
 def wrapper(request, *args, **kwargs):
     if getattr(request, 'user') is None:
         # If the user is not signed in, send them off to somewhere
         # they can log in.
         login_url = auth.create_login_url(request.path)
         return http.HttpResponseRedirect(login_url)
     return func(request, *args, **kwargs)
 def wrapper(request, *args, **kwargs):
     if getattr(request, 'user') is None:
         # If the user is not signed in, send them off to somewhere
         # they can log in.
         login_url = auth.create_login_url(request.path)
         return http.HttpResponseRedirect(login_url)
     return func(request, *args, **kwargs)
def base(request):
    # logout should always redirect to the current page to 
    # make it easier to switch users (like on the playlist tracker)
    logout_url = "%s?redirect=%s" % (auth.LOGOUT_URL, request.path)
    return {
        'user': hasattr(request, 'user') and request.user or None,
        'login_url': auth.create_login_url('/'),
        'logout_url': logout_url,
        'settings': settings,
        'MEDIA_URL': settings.MEDIA_URL,
        'chicago_now': time_util.chicago_now(),
        'request': request,
        }
def base(request):
    # logout should always redirect to the current page to
    # make it easier to switch users (like on the playlist tracker)
    logout_url = "%s?redirect=%s" % (auth.LOGOUT_URL, request.path)
    return {
        'user': hasattr(request, 'user') and request.user or None,
        'login_url': auth.create_login_url('/'),
        'logout_url': logout_url,
        'settings': settings,
        'MEDIA_URL': settings.MEDIA_URL,
        'chicago_now': time_util.chicago_now(),
        'request': request,
    }
Example #5
0
def bootstrap(request):
    """If the visitor is a chirpradio admin, create a user for them."""
    if request.user is None:
        g_user = google_users.get_current_user()
        if g_user is None:
            return http.HttpResponseRedirect(
                google_users.create_login_url(request.path))
        if not google_users.is_current_user_admin():
            return http.HttpResponseForbidden('Not a chirpradio project admin')
        user = User.get_by_email(g_user.email())
        if user:
            return http.HttpResponseForbidden('User %s already exists' %
                                              user.email)
        user = User(email=g_user.email(), is_superuser=True)
        user.set_password("test")
        user.save()
        return http.HttpResponseRedirect(auth.create_login_url('/'))
    return http.HttpResponseForbidden("Already logged in")
Example #6
0
def bootstrap(request):
    """If the visitor is a chirpradio admin, create a user for them."""
    if request.user is None:
        g_user = google_users.get_current_user()
        if g_user is None:
            return http.HttpResponseRedirect(
                google_users.create_login_url(request.path))
        if not google_users.is_current_user_admin():
            return http.HttpResponseForbidden('Not a chirpradio project admin')
        user = User.get_by_email(g_user.email())
        if user:
            return http.HttpResponseForbidden(
                'User %s already exists' % user.email)
        user = User(email=g_user.email(), is_superuser=True)
        user.set_password("test")
        user.save()
        return http.HttpResponseRedirect(auth.create_login_url('/'))
    return http.HttpResponseForbidden("Already logged in")
    def process_request(self, request):
        # lazy import to make sure we have the right Django!
        from django import http
        from django.conf import settings

        for prefix in settings.PUBLIC_TOP_LEVEL_URLS:
            if request.path.startswith(prefix):
                # These are special URLs that do not need login protection.
                return None
        try:
            user = auth.get_current_user(request)
        except auth.UserNotAllowedError:
            return http.HttpResponseForbidden('Access Denied!')
        # Un-logged-in users are not redirected away from the /auth/
        # namespace.  This ensures that the log-in and related pages
        # are reachable.
        if user is None and not request.path.startswith('/auth/'):
            login_url = auth.create_login_url(request.path)
            return http.HttpResponseRedirect(login_url)
        # Attach the user to the request.
        request.user = user
        return None
Example #8
0
    def process_request(self, request):
        # lazy import to make sure we have the right Django!
        from django import http
        from django.conf import settings

        for prefix in settings.PUBLIC_TOP_LEVEL_URLS:
            if request.path.startswith(prefix):
                # These are special URLs that do not need login protection.
                return None
        try:
            user = auth.get_current_user(request)
        except auth.UserNotAllowedError:
            return http.HttpResponseForbidden('Access Denied!')
        # Un-logged-in users are not redirected away from the /auth/
        # namespace.  This ensures that the log-in and related pages
        # are reachable.
        if user is None and not request.path.startswith('/auth/'):
            login_url = auth.create_login_url(request.path)
            return http.HttpResponseRedirect(login_url)
        # Attach the user to the request.
        request.user = user
        return None
Example #9
0
 def wrapper(request, *args, **kwargs):
     # Not signed in?  Redirect to a login page.
     if not request.user:
         return http.HttpResponseRedirect(
             auth.create_login_url(request.path))
     # If the user is signed in and has the required role(s),
     # satisfy the request.
     allow = False
     if self._role is None or (request.user
                               and request.user.is_superuser):
         allow = True
     if not allow:
         for role in self._role:
             if role in request.user.roles:
                 if self._logic == 0:
                     allow = True
                     break
                 else:
                     allow = True
             elif self._logic == 1:
                 allow = False
                 break
     if allow:
         return func(request, *args, **kwargs)
     else:
         # Return a 403.
         s = 'Page requires '
         if len(self._role) > 1:
             if self._logic == 0:
                 s += 'any '
             else:
                 s += 'all '
             s += 'roles '
         else:
             s += 'role '
         s += '"%s"' % '", "'.join(self._role)
         return http.HttpResponseForbidden(s)
 def wrapper(request, *args, **kwargs):
     # Not signed in?  Redirect to a login page.
     if not request.user:
         return http.HttpResponseRedirect(
             auth.create_login_url(request.path))
     # If the user is signed in and has the required role(s),
     # satisfy the request.
     allow = False
     if self._role is None or (request.user and
                               request.user.is_superuser):
         allow = True
     if not allow:
         for role in self._role:
             if role in request.user.roles:
                 if self._logic == 0:
                     allow = True
                     break
                 else:
                     allow = True
             elif self._logic == 1:
                 allow = False
                 break
     if allow:
         return func(request, *args, **kwargs)
     else:
         # Return a 403.
         s = 'Page requires '
         if len(self._role) > 1:
             if self._logic == 0:
                 s += 'any '
             else:
                 s += 'all '
             s += 'roles '
         else:
             s += 'role '
         s += '"%s"' % '", "'.join(self._role)
         return http.HttpResponseForbidden(s)
 def test_url_generation(self):
     # This is just a smoke test.
     auth.create_login_url("not actually a path")
Example #12
0
 def test_url_generation(self):
     # This is just a smoke test.
     auth.create_login_url("not actually a path")