-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.rs
77 lines (72 loc) · 2.45 KB
/
api.rs
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
<?php
if ($_GET['do'] == "oauth") {
require('bootloader.php');
} else {
require('bootstrap.php');
}
try {
$return = array();
switch ($_GET['do']) {
case 'oauth':
user_access();
if (!isset($_GET['app_id']) || is_empty($_GET['app_id'])) {
_error(404);
}
$user->oauth_app($_GET['app_id']);
break;
case 'authorize':
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"));
}
$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':
if (!isset($_GET['access_token']) || is_empty($_GET['access_token'])) {
return_json(array('error' => true, 'message' => "Bad Request, invalid access_token"));
}
$user_id = $user->access_app($_GET['access_token']);
$get_user = $db->query(sprintf("SELECT
user_id,
user_nisn,
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['profile_picture'], $_user['user_gender']);
$_user['user_gender'] = $user->get_gender($_user['user_gender']);
$_user['profile_cover'] = $system['system_uploads'] . "/" . $_user['profile_cover'];
$return['user_info'] = $_user;
}
}
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()));
}
}