Changeset 8808


Ignore:
Timestamp:
05/09/13 09:47:06 (5 years ago)
Author:
mnagni
Message:

Incomplete - # 22737: [CEDA Site Python Port] Resource Registration - Make Agreement Docs PDFs
 http://team.ceda.ac.uk/trac/ceda/ticket/22737
Incomplete - # 22802: [CEDA Site Python Port] Login - no message is displayed when the user enters the wrong password
 http://team.ceda.ac.uk/trac/ceda/ticket/22802

Location:
mauRepo/dj_security/trunk/dj_security
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/dj_security/trunk/dj_security/__init__.py

    r8802 r8808  
    1010LOGGER = logging.getLogger(__name__) 
    1111 
    12 def cookie_domain(): 
     12def cookie_domain(c_domain = None): 
    1313    try: 
    14         return getattr(settings, 'COOKIE_DOMAIN') 
     14        return getattr(settings, 'COOKIE_DOMAIN', c_domain) 
    1515    except AttributeError: 
    1616        import socket 
  • mauRepo/dj_security/trunk/dj_security/middleware.py

    r8804 r8808  
    3838from userdb_model.models import User 
    3939 
     40import os 
    4041import socket 
    4142import urlparse 
     
    8384        return response                 
    8485 
     86def _calculate_remote_host(url_path): 
     87    remote_url = urlparse.urlparse(url_path) 
     88    LOGGER.debug("calculating remote_ip for %s" % (str(remote_url))) 
     89    port = 80 
     90    host = None 
     91    if remote_url.netloc: 
     92        host = remote_url.netloc 
     93    elif remote_url.path: 
     94        host = remote_url.path 
     95                    
     96    if host is None: 
     97        return None 
     98     
     99    if ':' in host: 
     100        return host.split(':') 
     101    else: 
     102        return host, '80' 
     103         
     104     
     105def _calculate_remote_ip(host, port):       
     106    addrinfo = socket.getaddrinfo(host, int(port)) 
     107    LOGGER.info("%s has remote_ip %s" % (host, addrinfo[0][-1][0]))                                  
     108    return addrinfo[0][-1][0] 
     109 
    85110def get_user_byuserkey(user_id): 
    86111    """ 
     
    95120        raise DSJOpenIDNotFoundError(ex) 
    96121 
    97 def _generate_auth_cookie(user, remote_ip, response): 
     122def _generate_auth_cookie(user, remote_ip, remote_host, response): 
    98123    token = AuthTicket( 
    99124            shared_secret(),  
     
    103128            % (user.userkey, getattr("user", "accountid", "NotAssigned")))                
    104129    LOGGER.info("Created authTicket for %s from %s" % (user.accountid, remote_ip)) 
     130    c_domain = cookie_domain(remote_host) 
    105131    response.set_cookie(auth_tkt_name(),  
    106132                        token.cookie_value(),  
    107                         domain = cookie_domain()) 
     133                        domain = c_domain) 
    108134    LOGGER.debug("Set authTicket in response for %s from %s to domain %s"  
    109                  % (user.accountid, remote_ip, cookie_domain())) 
     135                 % (user.accountid, remote_ip, remote_host)) 
    110136    return response 
    111137 
    112 def _encode_authenticated_response(request, response, redirect_to, user):     
    113     remote_ip = request.environ.get('REMOTE_ADDR') 
     138def _encode_authenticated_response(request, response, redirect_to, user): 
     139    remote_host, remote_port = _calculate_remote_host(redirect_to)     
     140    remote_ip = _calculate_remote_ip(remote_host, remote_port) 
    114141    LOGGER.info("responding to remote_ip: %s" % (remote_ip))       
    115     return _generate_auth_cookie(user, remote_ip, response)         
     142    return _generate_auth_cookie(user, remote_ip, remote_host, response)         
  • mauRepo/dj_security/trunk/dj_security/templates/signin.html

    r8791 r8808  
    106106 
    107107<div class="messages"> 
    108 Problems logging on? Contact <a href="http://badc.nerc.ac.uk/help/contact.html">BADC</a> support for help 
     108Problems logging on? Contact <a href="http://badc.nerc.ac.uk/help/contact.html">CEDA</a> support for help 
    109109</div> 
    110110{% endblock %} 
Note: See TracChangeset for help on using the changeset viewer.