1 | // redirect, called from the popup |
---|
2 | function oauth_redirect(type) { |
---|
3 | var url = '{$OAUTH.u_redirect}'; |
---|
4 | if (type && type != 'default') { |
---|
5 | url = '{$ABS_ROOT_URL}'+ type +'.php'; |
---|
6 | } |
---|
7 | |
---|
8 | window.location.href = url; |
---|
9 | } |
---|
10 | |
---|
11 | // open authentication popup |
---|
12 | function open_auth(url) { |
---|
13 | window.open( |
---|
14 | '{$OAUTH.u_login}' + url + '&key={$OAUTH.key}', |
---|
15 | 'hybridauth_social_sign_on', |
---|
16 | 'location=0,status=0,scrollbars=0,width=800,height=500' |
---|
17 | ); |
---|
18 | } |
---|
19 | |
---|
20 | // click on a button |
---|
21 | jQuery('a.oauth:not(.persona)').click(function(e) { |
---|
22 | e.preventDefault(); |
---|
23 | |
---|
24 | var idp = jQuery(this).data('idp'); |
---|
25 | |
---|
26 | switch(idp) { |
---|
27 | case 'OpenID': case 'Wordpress': case 'Flickr': case 'Steam': |
---|
28 | switch(idp) { |
---|
29 | case 'OpenID': |
---|
30 | jQuery('#openid_label').html('{'Please enter your OpenID URL'|translate|escape:javascript}'); break; |
---|
31 | case 'Wordpress': case 'Steam': |
---|
32 | jQuery('#openid_label').html('{'Please enter your username'|translate|escape:javascript}'); break; |
---|
33 | case 'Flickr': |
---|
34 | jQuery('#openid_label').html('{'Please enter your user ID'|translate|escape:javascript}'); break; |
---|
35 | } |
---|
36 | |
---|
37 | var bg_color = $('#the_page #content').css('background-color'); |
---|
38 | if (!bg_color || bg_color=='transparent') { |
---|
39 | bg_color = $('body').css('background-color'); |
---|
40 | } |
---|
41 | jQuery('#openid_form').css('background-color', bg_color); |
---|
42 | |
---|
43 | jQuery('#openid_form .oauth_38px').removeClass().addClass('oauth_38px ' + idp.toLowerCase()); |
---|
44 | jQuery('#openid_form h3').html(idp); |
---|
45 | jQuery('#openid_form').data('idp', idp); |
---|
46 | |
---|
47 | jQuery.colorbox({ |
---|
48 | inline: true, |
---|
49 | href: '#openid_form', |
---|
50 | initialWidth: 0, |
---|
51 | initialHeight: 0, |
---|
52 | mawWidth: '100%', |
---|
53 | onComplete: function(){ jQuery.colorbox.resize({ speed:0 }) } // prevent misalignement when icon not loaded |
---|
54 | }); |
---|
55 | break; |
---|
56 | |
---|
57 | default: |
---|
58 | open_auth(idp); |
---|
59 | } |
---|
60 | }); |
---|
61 | |
---|
62 | jQuery('#openid_form').submit(function(e) { |
---|
63 | e.preventDefault(); |
---|
64 | |
---|
65 | var idp = jQuery(this).data('idp'); |
---|
66 | var oi = jQuery('#openid_form input[name=openid_identifier]').val(); |
---|
67 | jQuery('#openid_form input[name=openid_identifier]').val(''); |
---|
68 | |
---|
69 | jQuery('#openid_label').removeClass('error'); |
---|
70 | if (!oi) { |
---|
71 | jQuery('#openid_label').addClass('error'); |
---|
72 | return; |
---|
73 | } |
---|
74 | |
---|
75 | switch(idp) { |
---|
76 | case 'Wordpress': oi = 'http://' + oi + '.wordpress.com'; break; |
---|
77 | case 'Flickr': oi = 'http://www.flickr.com/photos/' + oi + '/'; break; |
---|
78 | case 'Steam': oi = 'http://steamcommunity.com/openid/' + oi; break; |
---|
79 | } |
---|
80 | |
---|
81 | open_auth('OpenID&openid_identifier=' + encodeURI(oi)); |
---|
82 | |
---|
83 | jQuery.colorbox.close(); |
---|
84 | }); |
---|
85 | |
---|
86 | jQuery('#openid_cancel').click(function(e) { |
---|
87 | e.preventDefault(); |
---|
88 | |
---|
89 | jQuery('#openid_label').removeClass('error'); |
---|
90 | jQuery.colorbox.close(); |
---|
91 | }); |
---|
92 | |
---|
93 | {if $OAUTH.providers.Persona.enabled} |
---|
94 | jQuery('a.oauth.persona').click(function(e) { |
---|
95 | e.preventDefault(); |
---|
96 | navigator.id.request(); |
---|
97 | }); |
---|
98 | |
---|
99 | {if not empty($OAUTH.persona_email)} |
---|
100 | jQuery('a[href$="act=logout"]').click(function(e) { |
---|
101 | e.preventDefault(); |
---|
102 | navigator.id.logout(); |
---|
103 | }); |
---|
104 | {/if} |
---|
105 | |
---|
106 | navigator.id.watch({ |
---|
107 | loggedInUser: {if not empty($OAUTH.persona_email)}'{$OAUTH.persona_email}'{else}null{/if}, |
---|
108 | |
---|
109 | onlogin: function(assertion) { |
---|
110 | jQuery.ajax({ |
---|
111 | type: 'POST', |
---|
112 | url: '{$OAUTH.u_login}Persona', |
---|
113 | dataType: 'json', |
---|
114 | data: { |
---|
115 | assertion: assertion, |
---|
116 | key: '{$OAUTH.key}' |
---|
117 | }, |
---|
118 | success: function(data) { |
---|
119 | oauth_redirect(data.redirect_to); |
---|
120 | }, |
---|
121 | error: function() { |
---|
122 | alert('Unknown error'); |
---|
123 | } |
---|
124 | }); |
---|
125 | }, |
---|
126 | |
---|
127 | onlogout: function() { |
---|
128 | window.location.href = '{$U_LOGOUT}'; |
---|
129 | } |
---|
130 | }); |
---|
131 | {/if} |
---|