1 | <?php |
---|
2 | /** |
---|
3 | * This file is part of socialLogin, a plugin for Dotclear. |
---|
4 | * |
---|
5 | * @author Nicolas Frandeboeuf <nicofrand@gmail.com> |
---|
6 | * @version 1.0 |
---|
7 | * @package socialLogin |
---|
8 | * Licensed under the GPL version 3 license. |
---|
9 | * http://www.gnu.org/licenses/gpl-3.0.html |
---|
10 | */ |
---|
11 | |
---|
12 | class SocialLoginConnexion extends dcUrlHandlers |
---|
13 | { |
---|
14 | /** |
---|
15 | * Makes the connexion. |
---|
16 | * @global dcCore $core |
---|
17 | */ |
---|
18 | public static function connect() |
---|
19 | { |
---|
20 | global $core; |
---|
21 | |
---|
22 | if (!session_id()) |
---|
23 | session_start(); |
---|
24 | |
---|
25 | $previousUrl = (isset($_SESSION["socialLogin_previous_url"])) ? $_SESSION["socialLogin_previous_url"] : $core->blog->url; |
---|
26 | |
---|
27 | $apiKey = $core->blog->settings->socialLogin->janrain_api_key; |
---|
28 | |
---|
29 | // Call the auth_info API |
---|
30 | $postData = array("token" => $_POST["token"], "apiKey" => $apiKey, "format" => "json"); |
---|
31 | |
---|
32 | $curl = curl_init(); |
---|
33 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
---|
34 | curl_setopt($curl, CURLOPT_URL, "https://rpxnow.com/api/v2/auth_info"); |
---|
35 | curl_setopt($curl, CURLOPT_POST, true); |
---|
36 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); |
---|
37 | curl_setopt($curl, CURLOPT_HEADER, false); |
---|
38 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
---|
39 | $rawJson = curl_exec($curl); |
---|
40 | curl_close($curl); |
---|
41 | |
---|
42 | // Decode the response |
---|
43 | $authInfo = json_decode($rawJson, true); |
---|
44 | |
---|
45 | if (($authInfo["stat"] == "ok") && isset($authInfo["profile"])) |
---|
46 | { |
---|
47 | if (isset($_SESSION["socialLogin_error"])) |
---|
48 | unset($_SESSION["socialLogin_error"]); |
---|
49 | |
---|
50 | $profile = $authInfo["profile"]; |
---|
51 | |
---|
52 | if (isset($profile["identifier"])) |
---|
53 | $_SESSION["socialLogin_identifier"] = $profile["identifier"]; |
---|
54 | |
---|
55 | if (isset($profile["displayName"])) |
---|
56 | $_SESSION["socialLogin_pseudo"] = $profile["displayName"]; |
---|
57 | |
---|
58 | if (isset($profile["email"])) |
---|
59 | $_SESSION["socialLogin_email"] = $profile["email"]; |
---|
60 | |
---|
61 | if (isset($profile["url"])) |
---|
62 | $_SESSION["socialLogin_website"] = $profile["url"]; |
---|
63 | } |
---|
64 | else |
---|
65 | $_SESSION["socialLogin_error"] = "Profile does not exist"; |
---|
66 | |
---|
67 | http::redirect($previousUrl); |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | * Deconnects the visitor. |
---|
72 | * @global dcCore $core |
---|
73 | */ |
---|
74 | public static function deconnect() |
---|
75 | { |
---|
76 | global $core; |
---|
77 | |
---|
78 | if (!session_id()) |
---|
79 | session_start(); |
---|
80 | |
---|
81 | unset($_SESSION["socialLogin_identifier"]); |
---|
82 | unset($_SESSION["socialLogin_pseudo"]); |
---|
83 | unset($_SESSION["socialLogin_email"]); |
---|
84 | unset($_SESSION["socialLogin_website"]); |
---|
85 | |
---|
86 | $previousUrl = (isset($_SESSION["socialLogin_previous_url"])) ? $_SESSION["socialLogin_previous_url"] : $core->blog->url; |
---|
87 | http::redirect($previousUrl); |
---|
88 | } |
---|
89 | } |
---|
90 | ?> |
---|