blob: a0a8a6374480311f72f28b4c0cb4e8856182b4fc (
plain)
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
|
<?php
global $gApi;
$gApi->registerRoute( USERS_PKG_DIR, 'bituser_api_handler' );
function bituser_api_handler( $pMethod, $pRequest ) {
global $gApi, $gBitSystem, $gBitSmarty, $gBitUser;
$routeAction = BitBase::getParameter( $pRequest, 'route_action' );
$respStatus = HttpStatusCodes::HTTP_NOT_FOUND;
$respData = "Unknown ".$routeAction." method: ".$pMethod;
if( $routeAction == 'register' ) {
if( $pMethod == 'POST' ) {
$newUser = new BitPermUser();
if( $newUser->register( $pRequest ) ) {
$respStatus = HttpStatusCodes::HTTP_OK;
$respData = $newUser->exportHash();
} else {
$respStatus = HttpStatusCodes::HTTP_CONFLICT;
$respData = $newUser->mErrors;
}
}
} else if( $routeAction == 'authenticate' ) {
if( $pMethod == 'DELETE' ) {
$gApi->verifyAuthorization();
if( $gBitUser->isRegistered() ) {
$gBitUser->logout();
}
$respStatus = HttpStatusCodes::HTTP_OK;
} elseif( $pMethod == 'GET' || $pMethod == 'POST' ) {
$gApi->verifyAuthorization();
$gContent = &$gBitUser;
$respStatus = HttpStatusCodes::HTTP_OK;
$respData = $gBitUser->exportHash();
}
}
//bit_error_log( $respData, $respStatus );
$gApi->outputJson( $respData, $respStatus );
}
|