minor cosmetic changes and new create_customer api example

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-11-13 08:30:41 +01:00
parent 059e36aa78
commit e184201327
3 changed files with 73 additions and 24 deletions

View File

@@ -65,7 +65,7 @@ if ($action == 'delete') {
INSERT INTO `" . TABLE_API_KEYS . "` SET
`apikey` = :key, `secret` = :secret, `adminid` = :aid, `customerid` = :cid, `valid_until` = '-1', `allowed_from` = ''
");
// customer generates for himself, admins will see a customer-select-box
// customer generates for himself, admins will see a customer-select-box later
if (AREA == 'admin') {
$cid = 0;
}
@@ -183,7 +183,7 @@ if (count($all_keys) == 0) {
// my own key
$isMyKey = false;
if ($key['adminid'] == $userinfo['adminid'] && (AREA == 'admin' || (AREA == 'customer' && $key['customerid'] == $userinfo['customerid']))) {
if ($key['adminid'] == $userinfo['adminid'] && ((AREA == 'admin' && $key['customerid'] == 0) || (AREA == 'customer' && $key['customerid'] == $userinfo['customerid']))) {
// this is mine
$isMyKey = true;
}
@@ -193,12 +193,12 @@ if (count($all_keys) == 0) {
if ($isMyKey) {
$adminCustomerLink = $key['adminname'];
} else {
$adminCustomerLink = '&nbsp;(<a href="' . $linker->getLink(array(
$adminCustomerLink = '<a href="' . $linker->getLink(array(
'section' => (empty($key['customerid']) ? 'admins' : 'customers'),
'page' => (empty($key['customerid']) ? 'admins' : 'customers'),
'action' => 'su',
'id' => (empty($key['customerid']) ? $key['adminid'] : $key['customerid'])
)) . '" rel="external">' . (empty($key['customerid']) ? $key['adminname'] : $key['loginname']) . '</a>)';
)) . '" rel="external">' . (empty($key['customerid']) ? $key['adminname'] : $key['loginname']) . '</a>';
}
} else {
// customer do not need links

View File

@@ -0,0 +1,48 @@
<?php
// include FroxlorAPI helper class
require __DIR__ . '/FroxlorAPI.php';
// create object of FroxlorAPI with URL, apikey and apisecret
$fapi = new FroxlorAPI('https://froxlor.your-host.tld/api.php', 'your-api-key', 'your-api-secret');
// customer data
$data = [
'new_loginname' => 'test',
'email' => 'test@froxlor.org',
'firstname' => 'Test',
'name' => 'Testman',
'customernumber' => 1337,
'new_customer_password' => 's0mEcRypt1cpassword' . uniqid()
];
// send request
$fapi->request('Customers.add', $data);
// check for error
if (! empty($fapi->getLastError())) {
echo "Error: " . $fapi->getLastError();
exit();
}
// get response of request
$request = $fapi->getLastResponse();
// view response data
var_dump($request);
/*
array(60) {
["customerid"]=>
string(1) "1"
["loginname"]=>
string(4) "test"
["password"]=>
string(63) "$5$asdasdasd.asdasd"
["adminid"]=>
string(1) "1"
["name"]=>
string(7) "Testman"
["firstname"]=>
string(4) "Test"
[...]
*/

View File

@@ -23,7 +23,7 @@ abstract class ApiCommand extends ApiParameter
*
* @var boolean
*/
private $debug = true;
private $debug = false;
/**
* is admin flag
@@ -155,14 +155,14 @@ abstract class ApiCommand extends ApiParameter
}
// include every english language file we can get
foreach ($langs['English'] as $key => $value) {
foreach ($langs['English'] as $value) {
include_once makeSecurePath(FROXLOR_INSTALL_DIR . '/' . $value['file']);
}
// now include the selected language if its not english
if ($language != 'English') {
if (isset($langs[$language])) {
foreach ($langs[$language] as $key => $value) {
foreach ($langs[$language] as $value) {
include_once makeSecurePath(FROXLOR_INSTALL_DIR . '/' . $value['file']);
}
} else {
@@ -319,6 +319,7 @@ abstract class ApiCommand extends ApiParameter
header($resheader);
}
$response = array();
$response['status'] = $status;
$response['status_message'] = $status_message;
$response['data'] = $data;