Commits

Alexis Metaireau committed 1998886

add login templates and redirection in settings

Comments (0)

Files changed (4)

-django-oautclient
-=================
+django-oauthclient
+==================
 
 * Write view tests
+* Use restkit.oauth2 and restkit instead of libhttp2

oauthclient/models.py

 from django.db import models
 from django.conf import settings
-from oauthclient.settings import OAUTH_CONSUMER_KEY_SIZE, OAUTH_CONSUMER_SECRET_SIZE
+from oauthclient.settings import CONSUMER_KEY_SIZE, CONSUMER_SECRET_SIZE
 import oauth2
 
-KEY_SIZE = getattr(settings, 'OAUTH_CONSUMER_KEY_SIZE', 
-    OAUTH_CONSUMER_KEY_SIZE)
-SECRET_SIZE = getattr(settings,'OAUTH_CONSUMER_SECRET_SIZE', 
-    OAUTH_CONSUMER_SECRET_SIZE) 
-
 class OAuthServer(models.Model):
     """Defines the urls to use for the oauth authentication.
 
 
     """
     identifier = models.CharField(max_length=200, unique=True)
-    key = models.CharField(max_length=KEY_SIZE, null=True, blank=True)
-    secret = models.CharField(max_length=SECRET_SIZE, null=True, blank=True)
+    key = models.CharField(max_length=CONSUMER_KEY_SIZE, null=True, blank=True)
+    secret = models.CharField(max_length=CONSUMER_SECRET_SIZE, null=True, blank=True)
     server = models.ForeignKey(OAuthServer)
     last_modification = models.DateField(auto_now=True)
 

oauthclient/settings.py

-OAUTH_CONSUMER_KEY_SIZE = 18 
-OAUTH_CONSUMER_SECRET_SIZE = 32 
+from django.conf import settings
+
+CONSUMER_KEY_SIZE = getattr(settings, 'OAUTHCLIENT_CONSUMER_KEY_SIZE', 18)
+CONSUMER_SECRET_SIZE = getattr(settings, 'OAUTHCLIENT_CONSUMER_SECRET_SIZE', 32)
+REDIRECT_AFTER_LOGIN = getattr(settings, 'OAUTHCLIENT_REDIRECT_AFTER_LOGIN', None)
+REDIRECT_AFTER_LOGOUT = getattr(settings, 'OAUTHCLIENT_REDIRECT_AFTER_LOGOUT', None)
+LOGIN_TEMPLATE = getattr(settings, 'OAUTHCLIENT_LOGIN_TEMPLATE', 'login.html')
+LOGOUT_TEMPLATE = getattr(settings, 'OAUTHCLIENT_LOGOUT_TEMPLATE', 'logout.html')
+ERROR_TEMPLATE = getattr(settings, 'OAUTHCLIENT_ERROR_TEMPLATE', 'error.html')

oauthclient/views.py

 # django imports
-from django.shortcuts import render_to_response as render, redirect
+from django.shortcuts import render_to_response, redirect
 from django.contrib.sites.models import Site
 from django.core.urlresolvers import reverse
 
 
 #oauthclient import
 from models import ConsumerToken, OAuthServer
+from oauthclient import settings
 
 """These views are a generic way to do a three legged authentication with OAuth. 
 
             'present in session.' % (identifier, identifier))
     
     if ('error' in request.GET):
-        return render('error.html', {
+        return render_to_response(settings.ERROR_TEMPLATE, {
             'error':request.GET['error']
         })
     
 
     if 'next' in request.session:
         return redirect(request.session['next'])
-        
-    return render('authenticated.html', {})
+    if settings.REDIRECT_AFTER_LOGIN == None:
+        return render_to_response(settings.LOGIN_TEMPLATE)
+    return redirect(settings.REDIRECT_AFTER_LOGIN)
     
 def logout(request, identifier='default'):
     """Destruct the active session oauth related keys.
         if hasattr(request.session, identifier + '_' + key):
             del request.session[identifier + '_' + key]
             
-    return render('logout.html', {})
+    if settings.REDIRECT_AFTER_LOGOUT == None:
+        return render_to_response(settings.LOGOUT_TEMPLATE)
+    return redirect(settings.REDIRECT_AFTER_LOGOUT)