Changeset 2034

Show
Ignore:
Timestamp:
06/16/09 12:23:37 (9 months ago)
Author:
JensDiemer
Message:

ajax login!

  • needs tests
  • "{{ login_link }}" -> "{% lucidTag auth %}"
Location:
branches/0.9/pylucid_project
Files:
2 added
11 modified

Legend:

Unmodified
Added
Removed
  • branches/0.9/pylucid_project/apps/pylucid/context_processors.py

    r2002 r2034  
    1212from pylucid_project import PYLUCID_VERSION_STRING 
    1313from pylucid_project.utils import slug 
     14from pylucid_plugins.auth.context_processors import auth_context_processors 
    1415 
    1516 
    1617def _add_plugin_info(request, context): 
    17     """ Add css anchor into context. Used infomation from lucidTagNode. """ 
     18    """ Add css anchor into context. Used information from lucidTagNode. """ 
    1819     
    1920    plugin_name = request.plugin_name 
     
    5859    } 
    5960     
    60      
    61      
    62     # TODO: Use internal SHA-Login plugin views, if implemented: 
    63     if request.user.is_authenticated(): 
    64         # admin_logout reverse is still broken in django, see: 
    65         # http://code.djangoproject.com/ticket/11080 
    66         # http://code.djangoproject.com/attachment/ticket/10061 
    67         #url = reverse("admin_logout") 
    68         #url = reverse("admin_index") + "logout/" # TODO: Update this if django is bugfixed 
    69         url = "?auth=logout" 
    70          
    71         txt = "%s [%s]" % (_("Log out"), request.user.username) 
    72     else: 
    73         #url = reverse("admin_index") # django admin panel index page 
    74         url = "?auth=login" 
    75         txt = _("Log in") 
    76          
    77     context["login_link"] = mark_safe('<a href="%s">%s</a>' % (url, txt)) 
     61    # TODO: Put all Plugin context processors into settings? 
     62    context.update(auth_context_processors(request)) 
    7863     
    7964    if hasattr(request, "plugin_name"): 
  • branches/0.9/pylucid_project/apps/pylucid_update/views.py

    r2030 r2034  
    267267        content = template.content 
    268268 
    269         new_head_file_tag = ( 
     269 
     270        SCRIPT_TAG = ( 
    270271            '<script src="%(url)s"' 
    271272            ' onerror="JavaScript:alert(\'Error loading file [%(url)s] !\');"' 
    272273            ' type="text/javascript" /></script>\n' 
    273             '<!-- ContextMiddleware extrahead -->\n' 
    274         ) % { 
     274        ) 
     275 
     276        new_head_file_tag = "" 
     277        new_head_file_tag += SCRIPT_TAG % { 
    275278            "url": posixpath.join(settings.MEDIA_URL, settings.PYLUCID.PYLUCID_MEDIA_DIR, "jquery.js") 
    276279        } 
     280        new_head_file_tag += SCRIPT_TAG % { 
     281            "url": posixpath.join( 
     282                settings.MEDIA_URL, settings.PYLUCID.PYLUCID_MEDIA_DIR, "pylucid_js_tools.js" 
     283            ) 
     284        } 
     285        new_head_file_tag += '<!-- ContextMiddleware extrahead -->\n'       
    277286         
    278287        content = replace(content, out,"{% lucidTag page_style %}", new_head_file_tag) 
     
    280289        content = replace(content, out,"{% lucidTag head_files %}", new_head_file_tag) 
    281290        content = replace(content, out,"<!-- ContextMiddleware head_files -->", new_head_file_tag) 
     291         
     292        content = replace(content, out,"{{ login_link }}", "{% lucidTag auth %}") 
    282293         
    283294        content = replace(content, out,"{% lucidTag back_links %}", "<!-- ContextMiddleware breadcrumb -->") 
  • branches/0.9/pylucid_project/media/PyLucid/pylucid_js_tools.js

    r2026 r2034  
     1 
     2 
     3// helper function for console logging 
     4// set debug to true to enable debug logging 
     5function log() { 
     6    if (debug && window.console && window.console.log) 
     7        window.console.log(Array.prototype.join.call(arguments,'')); 
     8}; 
     9 
    110 
    211function OpenInWindow(URL) { 
     
    514    win.focus(); 
    615} 
     16 
     17 
     18 
     19function get_pylucid_ajax_view(url) { 
     20    /************************************************************************* 
     21        PyLucid ajax replace function 
     22         
     23        usage e.g.: 
     24        ---------------------------------------------------------------------- 
     25            $(document).ready(function(){ 
     26                $("#link_id").click(function(){ 
     27                    return get_pylucid_ajax_view("{{ ajax_get_view_url }}"); 
     28                }); 
     29            }); 
     30        ---------------------------------------------------------------------- 
     31        or: 
     32        ---------------------------------------------------------------------- 
     33        <a href="{{ url }}" onclick="return get_pylucid_ajax_view('{{ ajax_url }}');">foo</a> 
     34        ---------------------------------------------------------------------- 
     35    *************************************************************************/ 
     36    $("#page_content").html('<h2>loading...</h2>'); 
     37    $("#page_content").animate({opacity: 0.3}, 500 ); 
     38 
     39    var url = encodeURI(url); 
     40    log("get:" + url); 
     41     
     42    var load_normal_link = true; 
     43     
     44    $.ajax({ 
     45        async: false, 
     46        type: "GET", 
     47        url: url, 
     48        dataType: "html", 
     49         
     50        success: function(form_html){ 
     51                log("ajax get success."); 
     52            $("#page_content").html(form_html); 
     53            $("#page_content").animate({opacity: 1}, 500 ); 
     54            load_normal_link = false; 
     55        }, 
     56        error: function(XMLHttpRequest){ 
     57                log("ajax get response error!"); 
     58            // Display the complete Traceback html page 
     59                log(XMLHttpRequest); 
     60                var response_text = XMLHttpRequest.responseText; 
     61                log("response_text: '" + response_text + "'"); 
     62                if (!response_text) { 
     63                        document.write("<h1>ajax response error</h1>"); 
     64                } else { 
     65                        document.write(response_text); 
     66                } 
     67                load_normal_link = true; 
     68        } 
     69    }); 
     70    if (debug) { 
     71        // never fall back in debug mode. 
     72        log("return: " + load_normal_link); 
     73        return false; 
     74    } else { 
     75        // fall back to normal view, if ajax request failed. 
     76        return load_normal_link; // The browser follow the link, if true 
     77    }     
     78} 
  • branches/0.9/pylucid_project/media/PyLucid/superfish/pylucid_superfish_init.js

    r2022 r2034  
    66      delay:       1000,                            // one second delay on mouseout  
    77      animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation  
    8       speed:       'fast',                          // faster animation speed 
     8      speed:       'fast'                           // faster animation speed 
    99  }); 
    1010}); 
  • branches/0.9/pylucid_project/pylucid_plugins/admin_menu/templates/admin_menu/admin_top_menu.html

    r2029 r2034  
    2121--> 
    2222</style> 
    23 <script type="text/javascript"> 
    24 $(document).ready(function(){ 
    25     $("#edit_page").click(function() { 
    26         var url = encodeURI("{{ edit_page_ajax}}"); 
    27         console.log("get:" + url); 
    28          
    29         bodyContent = $.ajax({ 
    30             type: "GET", 
    31             url: url, 
    32             dataType: "html", 
    33              
    34             success: function(form_html){ 
    35                 $("#page_content").html(form_html); 
    36             }, 
    37             error: function(XMLHttpRequest){ 
    38                  // Display the complete Traceback html page 
    39                  document.write(XMLHttpRequest.responseText); 
    40             },        
    41         }); 
    42         return false; // The browser follow the link, if true 
    43         }); 
    44 }); 
    45 </script> 
    4623{% endextrahead %} 
    4724 
    4825<ul class="sf-menu"> 
    49     <li class="current"> 
    50         <a href="{{ logout_link }}">{% trans 'logout' %} [{{ request.user.username }}]</a> 
    51     </li> 
     26    <li class="current">{% lucidTag auth %}</li> 
    5227    <li> 
    53         <li><a href="#{{ edit_page_link }}" title="edit inline" id="edit_page">{% trans 'edit page' %}</a></li> 
     28        <li><a href="{{ edit_page_link }}" title="edit inline" id="edit_page" onclick="return get_pylucid_ajax_view('{{ edit_page_ajax}}');">{% trans 'edit page' %}</a></li> 
    5429        <ul> 
    5530            <li><a href="{{ edit_admin_panel_link }}">edit in admin panel</a></li> 
  • branches/0.9/pylucid_project/pylucid_plugins/auth/templates/auth/input_password.html

    r2022 r2034  
    44{% block plugin_content %} 
    55 
    6 {% extrahead %} 
     6{# We can't use extrahead block here, because it's used in ajax view, too. #} 
    77<script type="text/javascript" src="{{ PyLucid_media_url }}sha.js"></script> 
    88<script type="text/javascript" src="{{ PyLucid_media_url }}shared_sha_tools.js"></script> 
     
    3333start_init(); 
    3434</script> 
    35 {% endextrahead %} 
    3635 
    3736<fieldset><legend>PyLucid <a href="http://www.pylucid.org/_goto/8/JS-SHA-Login/" title="What is the PyLucid JS-SHA-LogIn?">JS-SHA-LogIn</a> - step 2</legend> 
  • branches/0.9/pylucid_project/pylucid_plugins/auth/templates/auth/input_username.html

    r2001 r2034  
    22 
    33{% block plugin_content %} 
    4 <div class="{{ CSS_PLUGIN_CLASS_NAME }} {{ css_plugin_class }}" id="{{ css_plugin_id }}"> 
     4{# We can't use extrahead block here, because it's used in ajax view, too. #} 
     5<script type="text/javascript"> 
     6 
     7$(document).ready(function(){ 
     8    log("input username ready"); 
     9    $("#id_username").focus(); 
     10     
     11    $('#username_form').bind('submit', function() { 
     12        // get the input password form via ajax 
     13        $("#page_content").html('<h2>loading...</h2>'); 
     14        $("#page_content").animate({opacity: 0.3}, 500 ); 
     15     
     16        log("continue login..."); 
     17 
     18        var form = $(this); 
     19        var form_data = form.serialize(); 
     20        log("form data:" + form_data); 
     21         
     22        var url = encodeURI(form.attr('action')); 
     23        log("form url:" + url); 
     24         
     25            $.post(url, form_data, 
     26                function(form_html){ 
     27                    log("ajax get success."); 
     28                    $("#page_content").html(form_html); 
     29                    $("#page_content").animate({opacity: 1}, 500 ); 
     30                } 
     31            ); 
     32         
     33        return false; // <-- important! 
     34    });     
     35}); 
     36</script> 
     37 
    538<fieldset><legend>PyLucid <a href="http://www.pylucid.org/_goto/8/JS-SHA-Login/" title="What is the PyLucid JS-SHA-LogIn?">JS-SHA-LogIn</a> - step 1</legend> 
    639 
     
    1245</noscript> 
    1346 
    14 <form method="post" action="{{ form_url }}"> 
     47<form id="username_form" method="post" action="{{ form_url }}"> 
    1548  {{ form.as_p }} 
    1649  <br /> 
     
    2154</form> 
    2255</fieldset> 
    23  
    24 <script type="text/javascript">document.getElementById("id_username").focus();</script> 
    25 </div> 
    2656{% endblock %} 
  • branches/0.9/pylucid_project/pylucid_plugins/auth/views.py

    r2022 r2034  
    2525 
    2626 
     27def lucidTag(request): 
     28    # TODO: Use internal SHA-Login plugin views, if implemented: 
     29    if request.user.is_authenticated(): 
     30        # admin_logout reverse is still broken in django, see: 
     31        # http://code.djangoproject.com/ticket/11080 
     32        # http://code.djangoproject.com/attachment/ticket/10061 
     33        #url = reverse("admin_logout") 
     34        #url = reverse("admin_index") + "logout/" # TODO: Update this if django is bugfixed 
     35        template_name = "auth/logout_link.html" 
     36        context = {"logout_url": "?auth=logout"} 
     37    else: 
     38        template_name = "auth/login_link.html" 
     39        #url = reverse("admin_index") # django admin panel index page 
     40        context = { 
     41            "login_url": "?auth=login", 
     42            "login_url_ajax": "?auth=get_login_form", 
     43        } 
     44     
     45    return render_to_string(template_name, context, context_instance=RequestContext(request)) 
     46 
     47 
     48 
     49 
    2750def _logout_view(request, next_url): 
    2851    """ Logout the current user. """ 
     
    4366 
    4467 
    45 def _plaintext_login(request, context, username, next_url): 
     68def _plaintext_login(request, context, username, next_url, render_function): 
    4669    """ input the password and login if auth ok """ 
    4770    if "password" in request.POST: 
     
    5679     
    5780    # return a string for replacing the normal cms page content 
    58     return render_to_string('auth/plaintext_login.html', context) 
    59  
    60  
    61      
    62 def _sha_login(request, context, user, next_url): 
     81    return render_function('auth/plaintext_login.html', context) 
     82 
     83 
     84     
     85def _sha_login(request, context, user, next_url, render_function): 
    6386    """ 
    6487    Login via JS-SHA-Login. 
     
    122145 
    123146    # return a string for replacing the normal cms page content 
    124     return render_to_string('auth/input_password.html', context,  
    125         context_instance=RequestContext(request) 
    126     ) 
    127  
    128  
    129 def _login_view(request, form_url, next_url): 
     147    return render_function('auth/input_password.html', context, context_instance=RequestContext(request)) 
     148 
     149 
     150def _login_view(request, form_url, next_url, render_function): 
    130151    if DEBUG: 
    131152        request.page_msg( 
     
    147168             
    148169            if "plaintext_login" in request.POST: 
    149                 return _plaintext_login(request, context, user.username, next_url) 
     170                return _plaintext_login(request, context, user.username, next_url, render_function) 
    150171            else: 
    151                 return _sha_login(request, context, user, next_url) 
     172                return _sha_login(request, context, user, next_url, render_function) 
    152173    else: 
    153174        username_form = UsernameForm() 
     
    156177     
    157178    # return a string for replacing the normal cms page content 
    158     return render_to_string('auth/input_username.html', context) 
     179    return render_function('auth/input_username.html', context) 
    159180 
    160181 
     
    164185    """ 
    165186    next_url = request.path 
    166      
     187#    import time 
     188#    time.sleep(0.5) 
    167189    action = request.GET["auth"] 
    168190    if action=="login": 
    169191        form_url = request.path + "?auth=login" # FIXME: How can we add the GET Parameter? 
    170         return _login_view(request, form_url, next_url) 
     192        return _login_view(request, form_url, next_url, render_function=render_to_string) 
     193    elif action=="get_login_form": 
     194        form_url = request.path + "?auth=get_login_form" # FIXME: How can we add the GET Parameter? 
     195        return _login_view(request, form_url, next_url, render_function=render_to_response) 
    171196    elif action=="logout": 
    172197        return _logout_view(request, next_url) 
  • branches/0.9/pylucid_project/pylucid_plugins/extrahead/context_middleware.py

    r2022 r2034  
    4949    def __init__(self, request, context): 
    5050        self.request = request 
    51         self.data = "" 
     51        if settings.DEBUG: 
     52            # Turn debug mode in JavaScript on 
     53            self.data = DEBUG_INFO % { 
     54                "fileinfo": os.path.basename(__file__), 
     55                "content": '<script type="text/javascript">var debug=true;log("debug is on");</script>' 
     56            } 
     57            self.data += "\n"  
     58        else: 
     59            self.data = "" 
    5260         
    5361    def add_content(self, content): 
     
    8997            return False 
    9098         
    91         def cut(filepath): 
    92             return "..." + filepath.split(FILEPATH_SPLIT,1)[1] 
    93             if len(filepath)>=MAX_FILEPATH_LEN: 
    94                 return "...%s" % filepath[-MAX_FILEPATH_LEN:] 
    95             return filepath 
    96          
    97          
    98         try: 
    99             self_basename = os.path.basename(__file__) 
    100             if self_basename.endswith(".pyc"): 
    101                 # cut: ".pyc" -> ".py" 
    102                 self_basename = self_basename[:-1] 
    103      
     99        try:     
    104100            fileinfo = [] 
    105101            step = 0 
     
    111107                    continue 
    112108                 
    113                 fileinfo.append("%s line %s" % (cut(filepath), lineno)) 
     109                filepath = "..." + filepath.split(FILEPATH_SPLIT,1)[1] 
     110                 
     111                fileinfo.append("%s line %s" % (filepath, lineno)) 
    114112                if step>=1: 
    115113                    break 
  • branches/0.9/pylucid_project/pylucid_plugins/page_admin/templates/page_admin/edit_page_form.html

    r2029 r2034  
     1{% extends "pylucid/css_anchor_div.html" %} 
     2 
     3{% block plugin_content %} 
     4 
     5{# We can't use extrahead block here, because it's used in ajax view, too. #} 
    16<script type="text/javascript"> 
    27$(document).ready(function(){ 
    38    $("#preview_fieldset").hide(); 
    4     $("#preview").click(function() {    
     9     
     10    $("#preview").click(function() { 
     11        $("#edit_page_preview").html("<h2>loading...</h2>"); 
     12        $("#preview_fieldset").slideDown(); 
     13     
    514        var content = $("#id_content")[0].value; 
    615     
     
    1120        $.post(url, { 'content': content }, function(form_html){ 
    1221            $("#edit_page_preview").html(form_html); 
    13             $("#preview_fieldset").slideDown(); 
     22             
    1423        }); 
    1524      return false; // The browser submit the form, if true 
     
    4352        {% endif %} 
    4453 
    45         <a href="{{ url_pagelinklist }}" title="{% trans 'List of all pages for creating links' %}"> 
    46             <button type="button" onclick="OpenInWindow('{{ url_pagelinklist }}'); return false"> 
     54        <a href="{{ pagelinklist_url }}" title="{% trans 'List of all pages for creating links' %}"> 
     55            <button type="button" onclick="OpenInWindow('{{ pagelinklist_url }}'); return false"> 
    4756             {% trans 'page list' %} 
    4857            </button> 
    4958        </a> 
    50         <a href="{{ url_taglist }}" title="{% trans 'List of all available PyLucid template tags' %}"> 
    51             <button type="button" onclick="OpenInWindow('{{ url_taglist }}'); return false"> 
     59        <a href="{{ taglist_url }}" title="{% trans 'List of all available PyLucid template tags' %}"> 
     60            <button type="button" onclick="OpenInWindow('{{ taglist_url }}'); return false"> 
    5261             {% trans 'tag list' %} 
    5362            </button> 
     
    7887</form> 
    7988</fieldset> 
     89{% endblock %} 
  • branches/0.9/pylucid_project/pylucid_plugins/page_admin/views.py

    r2029 r2034  
    5656        "abort_url": request.path, 
    5757        "preview_url": "%s?page_admin=preview" % request.path, 
     58         
     59        "pagelinklist_url": "#TODO", #FIXME ;) 
     60        "taglist_url": "#TODO", #FIXME ;) 
     61         
    5862        "edit_page_form": edit_page_form, 
    5963        "pagecontent_instance": pagecontent_instance,