-
Notifications
You must be signed in to change notification settings - Fork 1
/
handle-oauth-return.php
63 lines (47 loc) · 2.04 KB
/
handle-oauth-return.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
try {
require_once('Sprinkles.php');
require_once('HTTP_Request_Oauth.php');
$request_token = request_param('oauth_token');
if (!$request_token)
throw new Exception("No OAuth request token was present in the return from Get Satisfaction.");
# TBD: expire old entries (two weeks)
$sql = "select token_secret from sessions where token='" .
mysql_real_escape_string($request_token) . "'";
$result = mysql_query($sql);
if (!$result) {
throw new Exception("Couldn't look up token $request_token; database error: "
. mysql_error());
}
$cols = mysql_fetch_array($result);
$request_token_secret = $cols[0];
$sprink = new Sprinkles();
$consumer_data = $sprink->oauth_consumer_data();
list($token, $token_secret) = get_oauth_access_token($consumer_data,
$request_token,
$request_token_secret);
if (!$token || !$token_secret) {
throw new Exception("Getting OAuth access token from Get Satisfaction failed.");
}
$result = mysql_query("update sessions set token = '" . mysql_real_escape_string($token) .
"', token_secret = '" . mysql_real_escape_string($token_secret) .
"' where token = '" . mysql_real_escape_string($request_token) . "'");
if (!$result) throw new Exception("Failed to store auth tokens on oauth response");
$sprink = new Sprinkles();
$sprink->open_session($token);
if (!$sprink->site_configured() && request_param('first_login')) {
$user = $sprink->current_user();
if (!$user) throw new Exception("Internal error: No current user just after opening session.");
$sprink->set_admin_users(array($user['canonical_name']));
$result = $sprink->set_site_settings(array('configured' => 'Y'));
if (!$result) die (mysql_error());
}
$return = request_param('return');
if (!$return) $return = 'helpstart.php';
redirect($return);
exit(0);
} catch (Exception $e) {
error_log("Exception thrown while preparing page: " . $e->getMessage());
$smarty->display('error.t');
}
?>