Changeset 8741 for mauRepo/dj_security


Ignore:
Timestamp:
26/03/13 12:43:48 (7 years ago)
Author:
mnagni
Message:

Incomplete - # 22698: [CEDA Site Python Port] MyCEDA Login needs to be more user-friendly
 http://team.ceda.ac.uk/trac/ceda/ticket/22698

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

Legend:

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

    r8740 r8741  
    8181     
    8282    def process_response(self, request, response): 
    83         LOGGER.debug("responding to request.path: %s" % (request.path))  
    84         session = getattr(request, 'session', None) 
    85          
    86         if not session:         
    87             return response 
    88          
    89         if request.GET.get('r') and getattr(request, 'session', None): 
    90             request.session['r'] = request.GET.get('r') 
    91          
    92         if request.path.endswith('account/register/') or request.path.endswith('accounts/profile/'): 
    93             return _encode_authenticated_response(request, response) 
    94          
    95         return response 
    96          
     83        return response                 
    9784     
    9885def _calculate_remote_ip(url_path):    
     
    143130                                      request.path])) 
    144131 
    145 def _encode_authenticated_response(request, response): 
    146     def_r = _get_path_to_host(request) 
    147     remote_url = request.session.get('r', def_r) 
     132def _encode_authenticated_response(request, response, redirect_to, user): 
     133    #def_r = _get_path_to_host(request) 
     134    #remote_url = request.session.get('r', def_r) 
    148135     
    149     if not remote_url: 
    150         raise DJSException('Missing url where redirect logged in user') 
     136    #if not redirect_to: 
     137    #    raise DJSException('Missing url where redirect logged in user') 
    151138     
    152     remote_ip = _calculate_remote_ip(base64.b64decode(remote_url)) 
     139    remote_ip = _calculate_remote_ip(redirect_to) 
    153140    LOGGER.info("responding to remote_ip: %s" % (remote_ip))       
    154     user = get_user_byuserkey(request.session[SESSION_KEY]) 
     141    #user = get_user_byuserkey(request.session[SESSION_KEY]) 
    155142     
    156143    '''   
  • mauRepo/dj_security/trunk/dj_security/templates/signin.html

    r8737 r8741  
    3333    <form id="auth_form" name="auth_form" action="{% url user_signin %}" method="post"> 
    3434    {% csrf_token %} 
    35     <input type="hidden" name="next" value="{{ next }}" /> 
     35    <input type="hidden" name="r" value="{{ r }}" /> 
    3636        <fieldset> 
    3737                <legend>{% trans "Sign In Using Your Account ID" %}</legend> 
     
    7373    {% csrf_token %} 
    7474    <input type="hidden" name="action" value="verify" /> 
    75     <input type="hidden" name="next" value="{{ next }}" /> 
     75    <input type="hidden" name="r" value="{{ r }}" /> 
    7676        <fieldset>     
    7777        <div> 
  • mauRepo/dj_security/trunk/dj_security/urls.py

    r8737 r8741  
    44from mezzanine.core.views import direct_to_template 
    55from django.conf import settings 
    6 from dj_security.views.dj_security_login import signin, CEDAAuthenticationForm 
     6from dj_security.views.dj_security_login import signin, CEDAAuthenticationForm,\ 
     7    signin_success 
     8from django_authopenid import views as oid_views 
    79 
    810admin.autodiscover() 
     
    99101    url(r'^account/signin/$', signin, name='user_signin',  
    100102        kwargs={'auth_form':CEDAAuthenticationForm,  
    101                 'template_name': 'signin.html'}),     
    102     (r'^accounts/profile/$', 'logged_in'), 
     103                'template_name': 'signin.html', 'redirect_field_name': 'r'}), 
     104    url(r'^account/signin/complete/$', oid_views.complete_signin, name='user_complete_signin',  
     105        kwargs={'on_success': signin_success, 'redirect_field_name': 'r'}),                         
     106    #(r'^accounts/profile/$', 'logged_in'), 
    103107    #(r'^locally_logged_in/$', 'locally_logged_in'), 
    104108    url(r'^account/', include('django_authopenid.urls')),     
  • mauRepo/dj_security/trunk/dj_security/views/dj_security_login.py

    r8740 r8741  
    1010from django.conf import settings 
    1111from django_authopenid.views import not_authenticated, ask_openid,\ 
    12     signin_failure, _build_context 
     12    signin_failure, _build_context, complete 
    1313from django_authopenid.forms import OpenidSigninForm 
    1414from django.db.models import Q 
     
    3030from django.db.utils import DatabaseError 
    3131from dj_security.exception import DSJOpenIDNotFoundError 
     32from dj_security.middleware import _encode_authenticated_response 
    3233 
    3334# Get an instance of a logger 
     
    142143            login(request, get_user_byopenid(request.session[OPENID])) 
    143144             
    144     return _encode_authenticated_response(request, context = {})     
    145      
    146 def _encode_authenticated_response(request, context): 
     145    return _encode_authenticated_response_(request, context = {})     
     146     
     147def _encode_authenticated_response_(request, context): 
    147148    redirect_parameter = getattr(settings, 'REDIRECT_URL', 'r') 
    148149    context['redirect_url'] = \ 
     
    216217            form2 = auth_form(data=request.POST) 
    217218            if form2.is_valid(): 
    218                 login(request, form2.get_user()) 
     219                #login(request, form2.get_user()) 
    219220                if request.session.test_cookie_worked(): 
    220                     request.session.delete_test_cookie() 
    221                 return HttpResponseRedirect(redirect_to) 
     221                    request.session.delete_test_cookie()  
     222                redirect_to = base64.b64decode(redirect_to)                                    
     223                response = HttpResponseRedirect(redirect_to) 
     224                _encode_authenticated_response(request, response, redirect_to, form2.get_user()) 
     225                return response 
    222226    return render(template_name, { 
    223227        'form1': form1, 
     
    227231    }, context_instance=_build_context(request, extra_context=extra_context))   
    228232 
    229  
    230      
     233def signin_success(request, identity_url, openid_response, 
     234        redirect_field_name=REDIRECT_FIELD_NAME, **kwargs): 
     235     
     236    #redirect_parameter = getattr(settings, 'REDIRECT_URL', 'r')     
     237    redirect_url = base64.b64decode(request.REQUEST.get(redirect_field_name, '')) 
     238    LOGGER.debug("Redirecting to %s" % (redirect_url))  
     239    ''' 
     240        Retrieves the user after the openid provider authenticated him/her 
     241    ''' 
     242    response = HttpResponseRedirect(redirect_url) 
     243     
     244    #if SESSION_KEY in request.session: 
     245    if OPENID in request.session: 
     246        return _encode_authenticated_response(request, response, redirect_url, get_user_byopenid(request.session[OPENID]))             
     247    elif SESSION_KEY in request.session: 
     248        response = HttpResponseRedirect(redirect_url) 
     249        return _encode_authenticated_response(request, response, redirect_url)             
     250     
     251     
     252    
    231253def login(request, user): 
    232254    """ 
     
    253275        request.session.cycle_key() 
    254276    request.session[SESSION_KEY] = user.userkey 
    255     request.session[BACKEND_SESSION_KEY] = user.backend 
     277    #request.session[BACKEND_SESSION_KEY] = user.backend 
    256278    if hasattr(request, 'user'): 
    257279        request.user = user 
Note: See TracChangeset for help on using the changeset viewer.