forked from andresamayadiaz/FrontAccountingSimpleAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.php
executable file
·55 lines (46 loc) · 1.38 KB
/
util.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
<?php
/**********************************************
Author: Andres Amaya
Name: REST API Utils
Free software under GNU GPL
***********************************************/
function api_login(){
$app = \Slim\Slim::getInstance('SASYS');
$app->hook('slim.before', function () use ($app) {
$req = $app->request();
$company = $req->headers('X-COMPANY');
$user = $req->headers('X-USER');
$password = $req->headers('X-PASSWORD');
// TESTING
/*$company = 0;
$user = 'admin';
$password = '123';*/
$succeed = $_SESSION["wa_current_user"]->login($company,
$user, $password);
if(!$succeed){
$app->halt(403, 'Bad Login For Company: ' . $company . ' With User: ' . $user);
}
}, 1);
}
function api_response($code, $body){
$app = \Slim\Slim::getInstance('SASYS');
$app->response()->status($code);
$app->response()->body($body);
}
function api_success_response($body){
$app = \Slim\Slim::getInstance('SASYS');
$app->response()->status(200);
$app->response()->body($body);
//$app->response()->['Content-Type'] = $content_type;
}
function api_create_response($body){
$app = \Slim\Slim::getInstance('SASYS');
$app->response()->status(201);
$app->response()->body($body);
//$app->response()->['Content-Type'] = $content_type;
}
function api_error($code, $msg){
$app = \Slim\Slim::getInstance('SASYS');
$app->halt($code, json_encode(array('success' => 0, 'msg' => $msg)));
}
?>