1 | {combine_css path=$OAUTH_PATH|cat:'template/oauth_sprites.css'} |
---|
2 | |
---|
3 | {combine_script id='jquery.colorbox' load='footer' require='jquery' path='themes/default/js/plugins/jquery.colorbox.min.js'} |
---|
4 | {combine_css id='colorbox' path="themes/default/js/plugins/colorbox/style2/colorbox.css"} |
---|
5 | |
---|
6 | {if $OAUTH.providers.Persona.enabled} |
---|
7 | {combine_script id='persona' path='https://login.persona.org/include.js' load='footer'} |
---|
8 | {/if} |
---|
9 | |
---|
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} |
---|
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 | } |
---|
23 | |
---|
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() { |
---|
138 | alert('Unknown error'); |
---|
139 | } |
---|
140 | }); |
---|
141 | }, |
---|
142 | |
---|
143 | onlogout: function() { |
---|
144 | window.location.href = '{$U_LOGOUT}'; |
---|
145 | } |
---|
146 | }); |
---|
147 | {/if} |
---|
148 | {/footer_script} |
---|
149 | |
---|
150 | <div style="display:none;"> |
---|
151 | <form id="openid_form" action=""> |
---|
152 | <div> |
---|
153 | <span class="oauth_38px"></span> |
---|
154 | <h3>OpendID</h3> |
---|
155 | </div> |
---|
156 | <div> |
---|
157 | <br> |
---|
158 | <label id="openid_label" for="openid_identifier"></label> |
---|
159 | <br> |
---|
160 | <input type="text" name="openid_identifier" id="openid_identifier" size="50"> |
---|
161 | </div> |
---|
162 | <div> |
---|
163 | <br> |
---|
164 | <input type="submit" name="{'Submit'|translate}"> |
---|
165 | <a href="#" id="openid_cancel">{'Cancel'|translate}</a> |
---|
166 | </div> |
---|
167 | </form> |
---|
168 | </div> |
---|