]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
further generalization of openid selector
authorJoey Hess <joeyh@joeyh.name>
Wed, 13 May 2015 21:51:29 +0000 (17:51 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 13 May 2015 21:51:29 +0000 (17:51 -0400)
Now template variables can be set to control which login methods are shown

IkiWiki/Plugin/openid.pm
templates/openid-selector.tmpl
underlays/openid-selector/ikiwiki/openid/openid-jquery.js

index bfd130ace1b7228592acec680a708305b006b263..b8ebbe22854dc293564855f293655e5ba49e7876 100644 (file)
@@ -89,6 +89,8 @@ sub openid_selector {
                (defined $openid_url ? (openid_url => $openid_url) : ()),
                ($real_cgi_signin ? (otherform => $real_cgi_signin->($q, $session, 1)) : ()),
                otherform_label => $otherform_label,
+               login_selector_openid => 1,
+               login_selector_email => 1,
        );
 
        IkiWiki::printheader($session);
index 03eb5d7795f3894b3314009ff3b31875de9327f6..a055203a46baeffdeda92e359f7c7597ca4274a7 100644 (file)
@@ -2,14 +2,18 @@
 <script type="text/javascript" src="ikiwiki/openid/openid-jquery.js"></script>
 <script type="text/javascript">
 $(document).ready(function() {
-       selector.init('openid_identifier','<TMPL_IF OTHERFORM>otherform</TMPL_IF>', '<TMPL_VAR OTHERFORM_LABEL>');
+       selector.init(
+               'openid_identifier',
+               {
+                       <TMPL_IF LOGIN_SELECTOR_OPENID>'openid': 1,</TMPL_IF>
+                       <TMPL_IF LOGIN_SELECTOR_EMAIL>'email': 1,</TMPL_IF>
+               },
+               '<TMPL_IF OTHERFORM>otherform</TMPL_IF>',
+               '<TMPL_VAR OTHERFORM_LABEL>'
+       );
 });
 </script>
 
-<noscript>
-<h2>Login:</h2>
-</noscript>
-
 <form action="<TMPL_VAR CGIURL>" method="get" id="login_selector_form">
        <div>
                <script>
@@ -21,11 +25,26 @@ $(document).ready(function() {
                <div id="login_choice">
                        <div id="login_btns"></div>
                </div>
+
                <div id="login_input_area">
+               <div>
+               <h3>OpenId login:</h3>
+               <TMPL_IF LOGIN_SELECTOR_OPENID>
                        <label for="openid_identifier" class="block">Enter your OpenID:</label>
                        <input id="openid_identifier" name="openid_identifier" type="text" value="<TMPL_VAR ESCAPE=HTML OPENID_URL>"/>
                        <input id="openid_submit" type="submit" value="Login"/>
+               </TMPL_IF>
                </div>
+               <div>
+               <h3>Email login:</h3>
+               <TMPL_IF LOGIN_SELECTOR_EMAIL>
+                       <label for="email_address" class="block">Enter your email address:</label>
+                       <input id="email_address" name="Email_entry" type="text" value="<TMPL_VAR ESCAPE=HTML EMAIL_ADDRESS>"/>
+                       <input id="email_submit" type="submit" value="Login"/>
+               </TMPL_IF>
+               </div>
+               </div>
+
                <TMPL_IF LOGIN_ERROR>
                <div class="error"><TMPL_VAR LOGIN_ERROR></div>
                </TMPL_IF>
@@ -36,7 +55,7 @@ $(document).ready(function() {
 <TMPL_IF OTHERFORM>
 <br />
 <noscript>
-<h2><TMPL_VAR OTHERFORM_LABEL>:</h2>
+<h3><TMPL_VAR OTHERFORM_LABEL> login:</h3>
 </noscript>
 </TMPL_IF>
 <TMPL_VAR OTHERFORM>
index db8dca235226198d8bcce45fd415b03a7e595892..eaac503154080050689a263bc4ee407c5229651a 100644 (file)
@@ -5,21 +5,23 @@ http://code.google.com/p/openid-selector/
 This code is licenced under the New BSD License.
 */
 
-var selections_large = {
+var selections_email_large = {
     email: {
         name: 'Email',
        icon: 'wikiicons/email.png',
         label: 'Enter your email address:',
         url: null
-    },
+    }
+};
+var selections_openid_large = {
     openid: {
         name: 'OpenID',
        icon: 'wikiicons/openidlogin-bg.gif',
         label: 'Enter your OpenID:',
         url: null
-    },
+    }
 };
-var selections_small = {
+var selections_openid_small = {
     verisign: {
         name: 'Verisign',
         icon: 'ikiwiki/openid/verisign.png',
@@ -50,7 +52,7 @@ var selections_small = {
         url: 'http://openid.aol.com/{username}'
     }
 };
-var selections = $.extend({}, selections_large, selections_small);
+var selections = $.extend({}, selections_email_large, selections_openid_large, selections_openid_small);
 
 var selector = {
 
@@ -66,7 +68,7 @@ var selector = {
        selection_id: null,
        othersignin_id: null,
        
-    init: function(input_id, othersignin_id, othersignin_label) {
+    init: function(input_id, login_methods, othersignin_id, othersignin_label) {
         
         var selector_btns = $('#login_btns');
         
@@ -76,9 +78,17 @@ var selector = {
         $('#login_input_area').empty();
         
         // add box for each selection
-        for (id in selections_large) {
-               selector_btns.append(this.getBoxHTML(selections_large[id], 'large'));
-        }
+       if (login_methods['openid']) {
+               for (id in selections_openid_large) {
+                       selector_btns.append(this.getBoxHTML(selections_openid_large[id], 'large'));
+               }
+       }
+       if (login_methods['email']) {
+               for (id in selections_email_large) {
+                       selector_btns.prepend(this.getBoxHTML(selections_email_large[id], 'large'));
+               }
+       }
+
        if (othersignin_label != "") {
                this.othersignin_label=othersignin_label;
        }
@@ -98,11 +108,11 @@ var selector = {
                $('#'+this.othersignin_id).hide();
        }
 
-        if (selections_small) {
+        if (login_methods['openid'] && selections_openid_small) {
                selector_btns.append('<br/>');
                
-               for (id in selections_small) {
-                       selector_btns.append(this.getBoxHTML(selections_small[id], 'small'));
+               for (id in selections_openid_small) {
+                       selector_btns.append(this.getBoxHTML(selections_openid_small[id], 'small'));
                }
         }
         
@@ -179,7 +189,7 @@ var selector = {
        else {
                selector.setOpenIdUrl("");
        }
-       if(selector.ajaxHandler) {
+       if (selector.ajaxHandler) {
                selector.ajaxHandler(selector.selection_id, document.getElementById(selector.input_id).value);
                return false;
        }
@@ -227,7 +237,7 @@ var selector = {
                var input_area = $('#login_input_area');
                
                var html = '';
-               var id = 'entry';
+               var id = selection['name']+'_entry';
                var value = '';
                var label = selection['label'];
                var style = '';
@@ -240,7 +250,6 @@ var selector = {
                if (label) {
                        html = '<label for="'+ id +'" class="block">' + label + '</label>';
                }
-               html += '<input name="selection" type="hidden" value="' + selection['name'] + '" />'
                html += '<input id="'+id+'" type="text" style="'+style+'" name="'+id+'" value="'+value+'" />' + 
                                        '<input id="selector_submit" type="submit" value="Login"/>';