1 | <?php |
---|
2 | // start a new session (required for Hybridauth) |
---|
3 | session_start(); |
---|
4 | |
---|
5 | // change the following paths if necessary |
---|
6 | $config = dirname(__FILE__) . '/../../../hybridauth/config.php'; |
---|
7 | require_once( "../../../hybridauth/Hybrid/Auth.php" ); |
---|
8 | die; |
---|
9 | try{ |
---|
10 | $hybridauth = new Hybrid_Auth( $config ); |
---|
11 | } |
---|
12 | // if sometin bad happen |
---|
13 | catch( Exception $e ){ |
---|
14 | $message = ""; |
---|
15 | |
---|
16 | switch( $e->getCode() ){ |
---|
17 | case 0 : $message = "Unspecified error."; break; |
---|
18 | case 1 : $message = "Hybriauth configuration error."; break; |
---|
19 | case 2 : $message = "Provider not properly configured."; break; |
---|
20 | case 3 : $message = "Unknown or disabled provider."; break; |
---|
21 | case 4 : $message = "Missing provider application credentials."; break; |
---|
22 | case 5 : $message = "Authentication failed. The user has canceled the authentication or the provider refused the connection."; break; |
---|
23 | |
---|
24 | default: $message = "Unspecified error!"; |
---|
25 | } |
---|
26 | ?> |
---|
27 | <style> |
---|
28 | PRE { |
---|
29 | background:#EFEFEF none repeat scroll 0 0; |
---|
30 | border-left:4px solid #CCCCCC; |
---|
31 | display:block; |
---|
32 | padding:15px; |
---|
33 | overflow:auto; |
---|
34 | width:740px; |
---|
35 | } |
---|
36 | HR { |
---|
37 | width:100%; |
---|
38 | border: 0; |
---|
39 | border-bottom: 1px solid #ccc; |
---|
40 | padding: 50px; |
---|
41 | } |
---|
42 | </style> |
---|
43 | <table width="100%" border="0"> |
---|
44 | <tr> |
---|
45 | <td align="center"><br /><img src="images/icons/alert.png" /></td> |
---|
46 | </tr> |
---|
47 | <tr> |
---|
48 | <td align="center"><br /><h3>Something bad happen!</h3><br /></td> |
---|
49 | </tr> |
---|
50 | <tr> |
---|
51 | <td align="center"> <?php echo $message ; ?><hr /></td> |
---|
52 | </tr> |
---|
53 | <tr> |
---|
54 | <td> |
---|
55 | <b>Exception</b>: <?php echo $e->getMessage() ; ?> |
---|
56 | <pre><?php echo $e->getTraceAsString() ; ?></pre> |
---|
57 | </td> |
---|
58 | </tr> |
---|
59 | </table> |
---|
60 | <?php |
---|
61 | // diplay error and RIP |
---|
62 | die(); |
---|
63 | } |
---|
64 | |
---|
65 | $provider = @ $_GET["provider"]; |
---|
66 | $return_to = @ $_GET["return_to"]; |
---|
67 | |
---|
68 | if( ! $return_to ){ |
---|
69 | echo "Invalid params!"; |
---|
70 | } |
---|
71 | |
---|
72 | if( ! empty( $provider ) && $hybridauth->isConnectedWith( $provider ) ) |
---|
73 | { |
---|
74 | $return_to = $return_to . ( strpos( $return_to, '?' ) ? '&' : '?' ) . "connected_with=" . $provider ; |
---|
75 | ?> |
---|
76 | <script language="javascript"> |
---|
77 | if( window.opener ){ |
---|
78 | try { window.opener.parent.$.colorbox.close(); } catch(err) {} |
---|
79 | window.opener.parent.location.href = "<?php echo $return_to; ?>"; |
---|
80 | } |
---|
81 | |
---|
82 | window.self.close(); |
---|
83 | </script> |
---|
84 | <?php |
---|
85 | die(); |
---|
86 | } |
---|
87 | |
---|
88 | if( ! empty( $provider ) ) |
---|
89 | { |
---|
90 | $params = array(); |
---|
91 | |
---|
92 | if( $provider == "OpenID" ){ |
---|
93 | $params["openid_identifier"] = @ $_REQUEST["openid_identifier"]; |
---|
94 | } |
---|
95 | |
---|
96 | if( isset( $_REQUEST["redirect_to_idp"] ) ){ |
---|
97 | $adapter = $hybridauth->authenticate( $provider, $params ); |
---|
98 | } |
---|
99 | else{ |
---|
100 | // here we display a "loading view" while tryin to redirect the user to the provider |
---|
101 | ?> |
---|
102 | <table width="100%" border="0"> |
---|
103 | <tr> |
---|
104 | <td align="center" height="190px" valign="middle"><img src="images/loading.gif" /></td> |
---|
105 | </tr> |
---|
106 | <tr> |
---|
107 | <td align="center"><br /><h3>Loading...</h3><br /></td> |
---|
108 | </tr> |
---|
109 | <tr> |
---|
110 | <td align="center">Contacting <b><?php echo ucfirst( strtolower( strip_tags( $provider ) ) ) ; ?></b>. Please wait.</td> |
---|
111 | </tr> |
---|
112 | </table> |
---|
113 | <script> |
---|
114 | window.location.href = window.location.href + "&redirect_to_idp=1"; |
---|
115 | </script> |
---|
116 | <?php |
---|
117 | } |
---|
118 | |
---|
119 | die(); |
---|
120 | } |
---|
121 | ?> |
---|
122 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
123 | <html xmlns="http://www.w3.org/1999/xhtml" > |
---|
124 | <head> |
---|
125 | <title>HybridAuth Social Sing-on</title> |
---|
126 | <style> |
---|
127 | .idpico{ |
---|
128 | cursor: pointer; |
---|
129 | cursor: hand; |
---|
130 | } |
---|
131 | #openidm{ |
---|
132 | margin: 7px; |
---|
133 | } |
---|
134 | </style> |
---|
135 | <script src="js/jquery.min.js"></script> |
---|
136 | <script> |
---|
137 | var idp = null; |
---|
138 | |
---|
139 | $(function() { |
---|
140 | $(".idpico").click( |
---|
141 | function(){ |
---|
142 | idp = $( this ).attr( "idp" ); |
---|
143 | |
---|
144 | switch( idp ){ |
---|
145 | case "google" : case "twitter" : case "yahoo" : case "facebook": case "aol" : |
---|
146 | case "vimeo" : case "myspace" : case "tumblr" : case "lastfm" : case "twitter" : |
---|
147 | case "linkedin" : |
---|
148 | start_auth( "?provider=" + idp ); |
---|
149 | break; |
---|
150 | case "wordpress" : case "blogger" : case "flickr" : case "livejournal" : |
---|
151 | if( idp == "blogger" ){ |
---|
152 | $("#openidm").html( "Please enter your blog name" ); |
---|
153 | } |
---|
154 | else{ |
---|
155 | $("#openidm").html( "Please enter your username" ); |
---|
156 | } |
---|
157 | $("#openidun").css( "width", "220" ); |
---|
158 | $("#openidimg").attr( "src", "images/icons/" + idp + ".png" ); |
---|
159 | $("#idps").hide(); |
---|
160 | $("#openidid").show(); |
---|
161 | break; |
---|
162 | case "openid" : |
---|
163 | $("#openidm").html( "Please enter your OpenID URL" ); |
---|
164 | $("#openidun").css( "width", "350" ); |
---|
165 | $("#openidimg").attr( "src", "images/icons/" + idp + ".png" ); |
---|
166 | $("#idps").hide(); |
---|
167 | $("#openidid").show(); |
---|
168 | break; |
---|
169 | |
---|
170 | default: alert( "u no fun" ); |
---|
171 | } |
---|
172 | } |
---|
173 | ); |
---|
174 | |
---|
175 | $("#openidbtn").click( |
---|
176 | function(){ |
---|
177 | oi = un = $( "#openidun" ).val(); |
---|
178 | |
---|
179 | if( ! un ){ |
---|
180 | alert( "nah not like that! put your username or blog name on this input field." ); |
---|
181 | |
---|
182 | return false; |
---|
183 | } |
---|
184 | |
---|
185 | switch( idp ){ |
---|
186 | case "wordpress" : oi = "http://" + un + ".wordpress.com"; break; |
---|
187 | case "livejournal" : oi = "http://" + un + ".livejournal.com"; break; |
---|
188 | case "blogger" : oi = "http://" + un + ".blogspot.com"; break; |
---|
189 | case "flickr" : oi = "http://www.flickr.com/photos/" + un + "/"; break; |
---|
190 | } |
---|
191 | |
---|
192 | start_auth( "?provider=OpenID&openid_identifier=" + escape( oi ) ); |
---|
193 | } |
---|
194 | ); |
---|
195 | |
---|
196 | $("#backtolist").click( |
---|
197 | function(){ |
---|
198 | $("#idps").show(); |
---|
199 | $("#openidid").hide(); |
---|
200 | |
---|
201 | return false; |
---|
202 | } |
---|
203 | ); |
---|
204 | }); |
---|
205 | |
---|
206 | function start_auth( params ){ |
---|
207 | start_url = params + "&return_to=<?php echo urlencode( $return_to ); ?>" + "&_ts=" + (new Date()).getTime(); |
---|
208 | window.open( |
---|
209 | start_url, |
---|
210 | "hybridauth_social_sing_on", |
---|
211 | "location=0,status=0,scrollbars=0,width=800,height=500" |
---|
212 | ); |
---|
213 | } |
---|
214 | </script> |
---|
215 | </head> |
---|
216 | <body> |
---|
217 | <div id="idps"> |
---|
218 | <table width="100%" border="0"> |
---|
219 | <tr> |
---|
220 | <td align="center"><img class="idpico" idp="google" src="images/icons/google.png" title="google" /></td> |
---|
221 | <td align="center"><img class="idpico" idp="twitter" src="images/icons/twitter.png" title="twitter" /></td> |
---|
222 | <td align="center"><img class="idpico" idp="facebook" src="images/icons/facebook.png" title="facebook" /></td> |
---|
223 | <td align="center"><img class="idpico" idp="openid" src="images/icons/openid.png" title="openid" /></td> |
---|
224 | </tr> |
---|
225 | <tr> |
---|
226 | <td align="center"><img class="idpico" idp="yahoo" src="images/icons/yahoo.png" title="yahoo" /></td> |
---|
227 | <td align="center"><img class="idpico" idp="flickr" src="images/icons/flickr.png" title="flickr" /></td> |
---|
228 | <td align="center"><img class="idpico" idp="myspace" src="images/icons/myspace.png" title="myspace" /></td> |
---|
229 | <td align="center"><img class="idpico" idp="linkedin" src="images/icons/linkedin.png" title="linkedin" /></td> |
---|
230 | </tr> |
---|
231 | <tr> |
---|
232 | <td align="center"><img class="idpico" idp="blogger" src="images/icons/blogger.png" title="blogger" /></td> |
---|
233 | <td align="center"><img class="idpico" idp="wordpress" src="images/icons/wordpress.png" title="wordpress" /></td> |
---|
234 | <td align="center"><img class="idpico" idp="livejournal" src="images/icons/livejournal.png" title="livejournal" /></td> |
---|
235 | </tr> |
---|
236 | </table> |
---|
237 | </div> |
---|
238 | <div id="openidid" style="display:none;"> |
---|
239 | <table width="100%" border="0"> |
---|
240 | <tr> |
---|
241 | <td align="center"><img id="openidimg" src="images/loading.gif" /></td> |
---|
242 | </tr> |
---|
243 | <tr> |
---|
244 | <td align="center"><h3 id="openidm">Please enter your user or blog name</h3></td> |
---|
245 | </tr> |
---|
246 | <tr> |
---|
247 | <td align="center"><input type="text" name="openidun" id="openidun" style="padding: 5px; margin:7px;border: 1px solid #999;width:240px;" /></td> |
---|
248 | </tr> |
---|
249 | <tr> |
---|
250 | <td align="center"> |
---|
251 | <input type="submit" value="Login" id="openidbtn" style="height:33px;width:85px;" /> |
---|
252 | <br /> |
---|
253 | <small><a href="#" id="backtolist">back</a></small> |
---|
254 | </td> |
---|
255 | </tr> |
---|
256 | </table> |
---|
257 | </div> |
---|
258 | </body> |
---|
259 | </html> |
---|