-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
102 lines (89 loc) · 2.74 KB
/
api.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* api
*
*
*
*/
// fetch bootstrap|bootloader
if ($_GET['do'] == "oauth") {
require('bootloader.php');
} else {
require('bootstrap.php');
}
try {
// initialize the return array
$return = array();
switch ($_GET['do']) {
case 'oauth':
// user access
user_access();
// valid inputs
if (!isset($_GET['app_id']) || is_empty($_GET['app_id'])) {
_error(404);
}
// oauth app
$user->oauth_app($_GET['app_id']);
break;
case 'authorize':
// valid inputs
if (!isset($_GET['app_id']) || is_empty($_GET['app_id'])) {
return_json(array('error' => true, 'message' => "Bad Request, invalid app_id"));
}
if (!isset($_GET['app_secret']) || is_empty($_GET['app_secret'])) {
return_json(array('error' => true, 'message' => "Bad Request, invalid app_secret"));
}
if (!isset($_GET['auth_key']) || is_empty($_GET['auth_key'])) {
return_json(array('error' => true, 'message' => "Bad Request, invalid auth_key"));
}
// authorize app
$access_token = $user->authorize_app($_GET['app_id'], $_GET['app_secret'], $_GET['auth_key']);
return_json(array('access_token' => $access_token));
break;
case 'get_user_info':
// valid inputs
if (!isset($_GET['access_token']) || is_empty($_GET['access_token'])) {
return_json(array('error' => true, 'message' => "Bad Request, invalid access_token"));
}
// access app
$user_id = $user->access_app($_GET['access_token']);
// add api get user
// get user
$get_user = $db->query(sprintf("SELECT
user_id,
user_name,
user_email,
user_firstname,
user_lastname,
user_gender,
user_birthdate,
user_picture,
user_cover,
user_registered,
user_verified,
user_relationship,
user_biography,
user_website
FROM users WHERE user_id = %s", secure($user_id, 'int'))) or _error('SQL_ERROR_THROWEN');
if ($get_user->num_rows > 0) {
while ($_user = $get_user->fetch_assoc()) {
$_user['profile_picture'] = get_picture($_user['user_picture'], $_user['user_gender']);
$_user['profile_cover'] = $system['system_uploads'] . "/" . $_user['profile_cover'];
$_user['user_gender'] = $user->get_gender($_user['user_gender']);
$return['user_info'] = $_user;
}
}
// return & exit
return_json($return);
break;
default:
return_json(array('error' => true, 'message' => "Bad Request, invalid parameters"));
break;
}
} catch (Exception $e) {
if ($_GET['do'] == "oauth") {
_error(__("Error"), $e->getMessage());
} else {
return_json(array('error' => true, 'message' => $e->getMessage()));
}
}