forked from sirportly/whmcs-data-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsso.php
34 lines (29 loc) · 1.32 KB
/
sso.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
<?php
# require whmcs functions
require("../../../dbconnect.php");
require("../../../includes/functions.php");
# find first administrator
$administrator = select_query('tbladmins');
$administrator = mysql_fetch_array($administrator, MYSQL_ASSOC);
# try and process the login
$login = localAPI('validatelogin',array('email' => $_REQUEST['username'], 'password2' => $_REQUEST['password']),$administrator['id']);
# couldn't process the login, so forbid access
if ($login['result'] != 'success') {
header('HTTP/1.0 403 Forbidden');
return;
}
# check to see if login was a client or a contact
if ($login['contactid']) {
$user = full_query("SELECT CONCAT(`firstname`, ' ', `lastname`), `permissions`, `email` FROM `tblcontacts` WHERE `id` = '".$login['contactid']."'");
$user = mysql_fetch_array($user, MYSQL_BOTH);
$permissions = explode(',',$user['permissions']);
if (!in_array('tickets',$permissions)) {
header('HTTP/1.0 403 Forbidden');
return;
}
} else {
$user = full_query("SELECT CONCAT(`firstname`, ' ', `lastname`), `email` FROM `tblclients` WHERE `id` = '".$login['userid']."'");
$user = mysql_fetch_array($user, MYSQL_BOTH);
}
# output the JSON
echo json_encode(array('name' => $user['0'], 'email' => $user['email'], 'reference' => $user['email']));