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