Changeset 8678 for mauRepo


Ignore:
Timestamp:
07/11/12 10:58:47 (7 years ago)
Author:
mnagni
Message:

Introduced two optional configurable parameters: COOKIE_DOMAIN, REDIRECT_URL

Location:
mauRepo/dj_security/trunk
Files:
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • mauRepo/dj_security/trunk/README

    r8665 r8678  
    88The application contains a few configurable parameters concentrate in settings.py 
    99 
    10 1) APPLICATION_ROOT: the root where the HTTP service is available, say "dj_security" 
    11 2) SHARED_SECRET: the secret key used to encrypt the generated 'auth_tkt' cookie 
    12 3) the deafult dataset 'DB_xxx' parameters, that is: 
     101) SHARED_SECRET: the secret key used to encrypt the generated 'auth_tkt' cookie 
     112) the deafult dataset 'DB_xxx' parameters, that is: 
    1312'ENGINE':   'DB_ENGINE',  
    1413'NAME':     'DB_NAME', 
     
    1615'PASSWORD': 'DB_PASSWORD', 
    1716'HOST':     'DB_HOST', 
    18 'PORT':     'DB_PORT',    
     17'PORT':     'DB_PORT', 
     183) COOKIE_DOMAIN (optional): the domain where the auth_tkt will belong  
     19[default = where dj_security is deployed] 
     204) REDIRECT_URL (optional): the parameter used by the client application 
     21to specify where redirect the user whenever the authentication succeed 
     22[default = 'r']  
    1923   
  • mauRepo/dj_security/trunk/dj_security/middleware.py

    r8674 r8678  
    4848    """             
    4949    def process_response(self, request, response): 
     50        if not request.POST.get('username', None) or request.user.id == None: 
     51            return response 
     52                 
    5053        remote_ip = _calculate_remote_ip(request) 
    51         logger.debug("remote_ip: %s" % (remote_ip))         
     54        logger.debug("remote_ip: %s" % (remote_ip))       
    5255        username = request.POST['username'] 
    5356        token = AuthTicket( 
     
    5760                 
    5861        logger.info("Logging %s from %s" % (username, remote_ip)) 
    59         response.set_cookie('auth_tkt', token.cookie_value()) 
     62        response.set_cookie('auth_tkt',  
     63                            token.cookie_value(),  
     64                            domain = getattr(settings, 'COOKIE_DOMAIN', None)) 
    6065        return response 
    6166     
    6267def _calculate_remote_ip(request): 
    63     import urlparse 
    6468    import socket 
     69    import urlparse     
    6570    remote_url = urlparse.urlparse(request.GET.get('r', '')) 
    6671    logger.debug("remote_url: %s" % (str(remote_url))) 
    6772    if remote_url.netloc != '': 
    68         logger.debug("gethostbyname_ex: %s" % (socket.gethostbyname_ex(remote_url.netloc.split(':')[0]))) 
     73        logger.debug("gethostbyname_ex: %s" % (str(socket.gethostbyname_ex(remote_url.netloc.split(':')[0])))) 
    6974        ips = socket.gethostbyname_ex(remote_url.netloc.split(':')[0])[2] 
    7075        if len(ips) > 1: 
  • mauRepo/dj_security/trunk/dj_security/static/templates/logged_in.html

    r8674 r8678  
    1212 
    1313<head> 
    14         <meta http-equiv="refresh" content="0;URL='{{ r }}'"> 
     14        <meta http-equiv="refresh" content="0;URL='{{ redirect_url }}'"> 
    1515    <title>Logged in</title> 
    1616</head> 
  • mauRepo/dj_security/trunk/dj_security/urls.py

    r8662 r8678  
    2020 
    2121 
    22 urlpatterns += patterns('dj_security.views.my_view', 
    23     (r'^login$', 'my_login'), 
     22urlpatterns += patterns('dj_security.views.dj_security_login', 
     23    (r'^login$', 'login'), 
    2424) 
    2525urlpatterns += patterns('dj_security.views.my_profile', 
  • mauRepo/dj_security/trunk/dj_security/views/dj_security_login.py

    r8674 r8678  
    88from dj_security.login_form import LoginForm 
    99from django.core.context_processors import csrf 
     10from django.conf import settings 
    1011import logging 
    1112 
     
    1920    return render_to_response('login.html', context) 
    2021 
    21 def my_login(request):        
     22def login(request):        
    2223    context = {} 
    2324    if request.method == 'POST': # If the form has been submitted... 
     
    3132                if user.is_active: 
    3233                    login(request, user) 
    33                     context['r'] = request.GET.get('r', '') 
     34                    redirect_parameter = getattr(settings, 'REDIRECT_URL', 'r') 
     35                    context['redirect_url'] = request.GET.get(redirect_parameter, '') 
    3436                    return render_to_response('logged_in.html', context)             
    3537                else: 
Note: See TracChangeset for help on using the changeset viewer.