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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.