[20620] | 1 | {combine_css path=$OAUTH_PATH|cat:'template/oauth_sprites.css'} |
---|
| 2 | |
---|
[20293] | 3 | {combine_script id='jquery.colorbox' load='footer' require='jquery' path='themes/default/js/plugins/jquery.colorbox.min.js'} |
---|
[26556] | 4 | {combine_css id='colorbox' path="themes/default/js/plugins/colorbox/style2/colorbox.css"} |
---|
[20293] | 5 | |
---|
[26605] | 6 | {if $OAUTH.providers.Persona.enabled} |
---|
| 7 | {combine_script id='persona' path='https://login.persona.org/include.js' load='footer'} |
---|
| 8 | {/if} |
---|
| 9 | |
---|
[26556] | 10 | {html_style} |
---|
| 11 | #openid_form { padding:20px; } |
---|
| 12 | #openid_form h3, #openid_form .oauth_38px { display:inline-block; vertical-align:middle; margin:0; } |
---|
| 13 | #openid_label.error { color:red; font-weight:bold; } |
---|
| 14 | {/html_style} |
---|
| 15 | |
---|
| 16 | {footer_script} |
---|
[20293] | 17 | // redirect, called from the popup |
---|
[26604] | 18 | function oauth_redirect(type) { |
---|
| 19 | var url = '{$OAUTH.u_redirect}'; |
---|
| 20 | if (type && type != 'default') { |
---|
| 21 | url = '{$ABS_ROOT_URL}'+ type +'.php'; |
---|
[20293] | 22 | } |
---|
[26556] | 23 | |
---|
[20293] | 24 | window.location.href = url; |
---|
| 25 | } |
---|
| 26 | |
---|
[20301] | 27 | // open authentication popup |
---|
[20369] | 28 | function open_auth(url) { |
---|
[20293] | 29 | window.open( |
---|
[26604] | 30 | url + '&t=' + (new Date()).getTime(), |
---|
| 31 | 'hybridauth_social_sign_on', |
---|
| 32 | 'location=0,status=0,scrollbars=0,width=800,height=500' |
---|
[20293] | 33 | ); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | // click on a button |
---|
[26605] | 37 | jQuery('a.oauth:not(.persona)').click(function(e) { |
---|
[26604] | 38 | e.preventDefault(); |
---|
| 39 | |
---|
[21584] | 40 | var idp = jQuery(this).data('idp'); |
---|
[20293] | 41 | |
---|
[20369] | 42 | switch(idp) { |
---|
[23808] | 43 | case 'OpenID': case 'Wordpress': case 'Flickr': case 'Steam': |
---|
[20369] | 44 | switch(idp) { |
---|
[20301] | 45 | case 'OpenID': |
---|
[26604] | 46 | jQuery('#openid_label').html('{'Please enter your OpenID URL'|translate|escape:javascript}'); break; |
---|
[23808] | 47 | case 'Wordpress': case 'Flickr': case 'Steam': |
---|
[26604] | 48 | jQuery('#openid_label').html('{'Please enter your username'|translate|escape:javascript}'); break; |
---|
[20293] | 49 | } |
---|
[20369] | 50 | |
---|
[26556] | 51 | var bg_color = $('#the_page #content').css('background-color'); |
---|
| 52 | if (!bg_color || bg_color=='transparent') { |
---|
| 53 | bg_color = $('body').css('background-color'); |
---|
| 54 | } |
---|
[26604] | 55 | jQuery('#openid_form').css('background-color', bg_color); |
---|
[26556] | 56 | |
---|
[26604] | 57 | jQuery('#openid_form .oauth_38px').removeClass().addClass('oauth_38px ' + idp.toLowerCase()); |
---|
| 58 | jQuery('#openid_form h3').html(idp); |
---|
| 59 | jQuery('#openid_form').data('idp', idp); |
---|
[26556] | 60 | |
---|
[21584] | 61 | jQuery.colorbox({ |
---|
[26604] | 62 | inline: true, |
---|
| 63 | href: '#openid_form', |
---|
| 64 | initialWidth: 0, |
---|
| 65 | initialHeight: 0, |
---|
| 66 | mawWidth: '100%', |
---|
[26556] | 67 | onComplete: function(){ jQuery.colorbox.resize({ speed:0 }) } // prevent misalignement when icon not loaded |
---|
[26604] | 68 | }); |
---|
[20293] | 69 | break; |
---|
| 70 | |
---|
| 71 | default: |
---|
[26604] | 72 | open_auth('{$OAUTH.u_login}'+ idp); |
---|
[20293] | 73 | } |
---|
| 74 | }); |
---|
| 75 | |
---|
[26604] | 76 | jQuery('#openid_form').submit(function(e) { |
---|
| 77 | e.preventDefault(); |
---|
| 78 | |
---|
[21584] | 79 | var idp = jQuery(this).data('idp'); |
---|
[26604] | 80 | var oi = jQuery('#openid_form input[name=openid_identifier]').val(); |
---|
| 81 | jQuery('#openid_form input[name=openid_identifier]').val(''); |
---|
[20293] | 82 | |
---|
[26604] | 83 | jQuery('#openid_label').removeClass('error'); |
---|
[20369] | 84 | if (!oi) { |
---|
[26604] | 85 | jQuery('#openid_label').addClass('error'); |
---|
| 86 | return; |
---|
[20293] | 87 | } |
---|
| 88 | |
---|
[20369] | 89 | switch(idp) { |
---|
[26604] | 90 | case 'Wordpress': oi = 'http://' + oi + '.wordpress.com'; break; |
---|
| 91 | case 'Flickr': oi = 'http://www.flickr.com/photos/' + oi + '/'; break; |
---|
| 92 | case 'Steam': oi = 'http://steamcommunity.com/openid/' + oi; break; |
---|
[20293] | 93 | } |
---|
[26556] | 94 | |
---|
[26604] | 95 | open_auth('{$OAUTH.u_login}OpenID&openid_identifier=' + encodeURI(oi)); |
---|
[26556] | 96 | |
---|
[21584] | 97 | jQuery.colorbox.close(); |
---|
[20293] | 98 | }); |
---|
| 99 | |
---|
[26604] | 100 | jQuery('#openid_cancel').click(function(e) { |
---|
| 101 | e.preventDefault(); |
---|
| 102 | |
---|
| 103 | jQuery('#openid_label').removeClass('error'); |
---|
[21584] | 104 | jQuery.colorbox.close(); |
---|
[20293] | 105 | }); |
---|
[26605] | 106 | |
---|
| 107 | {if $OAUTH.providers.Persona.enabled} |
---|
| 108 | jQuery('a.oauth.persona').click(function(e) { |
---|
| 109 | e.preventDefault(); |
---|
| 110 | navigator.id.request(); |
---|
| 111 | }); |
---|
| 112 | |
---|
| 113 | jQuery('a[href$="act=logout"]').click(function(e) { |
---|
| 114 | e.preventDefault(); |
---|
| 115 | navigator.id.logout(); |
---|
| 116 | }); |
---|
| 117 | |
---|
| 118 | navigator.id.watch({ |
---|
| 119 | loggedInUser: {if not empty($OAUTH.persona_email)}'{$OAUTH.persona_email}'{else}null{/if}, |
---|
| 120 | |
---|
| 121 | onlogin: function(assertion) { |
---|
| 122 | jQuery.ajax({ |
---|
| 123 | type: 'POST', |
---|
| 124 | url: '{$OAUTH.u_login}Persona', |
---|
| 125 | dataType: 'json', |
---|
| 126 | data: { assertion: assertion }, |
---|
| 127 | success: function(data) { |
---|
| 128 | oauth_redirect(data.redirect_to); |
---|
| 129 | }, |
---|
| 130 | error: function() { |
---|
| 131 | alert('Unknown error'); |
---|
| 132 | } |
---|
| 133 | }); |
---|
| 134 | }, |
---|
| 135 | |
---|
| 136 | onlogout: function() { |
---|
| 137 | window.location.href = '{$U_LOGOUT}'; |
---|
| 138 | } |
---|
| 139 | }); |
---|
| 140 | {/if} |
---|
[26556] | 141 | {/footer_script} |
---|
[20293] | 142 | |
---|
| 143 | <div style="display:none;"> |
---|
| 144 | <form id="openid_form" action=""> |
---|
| 145 | <div> |
---|
[20620] | 146 | <span class="oauth_38px"></span> |
---|
[20293] | 147 | <h3>OpendID</h3> |
---|
| 148 | </div> |
---|
| 149 | <div> |
---|
[20323] | 150 | <br> |
---|
[26604] | 151 | <label id="openid_label" for="openid_identifier"></label> |
---|
[20293] | 152 | <br> |
---|
| 153 | <input type="text" name="openid_identifier" id="openid_identifier" size="50"> |
---|
| 154 | </div> |
---|
| 155 | <div> |
---|
| 156 | <br> |
---|
[26556] | 157 | <input type="submit" name="{'Submit'|translate}"> |
---|
| 158 | <a href="#" id="openid_cancel">{'Cancel'|translate}</a> |
---|
[20293] | 159 | </div> |
---|
| 160 | </form> |
---|
| 161 | </div> |
---|