Select Git revision
TestISO8601Format.java
-
gmantele authored
dates with no seconds, but also with no day or month. Representations in days of year or weeks of year were not possible as well. Check out the ISO8601Format class' Javadoc for more details.
gmantele authoreddates with no seconds, but also with no day or month. Representations in days of year or weeks of year were not possible as well. Check out the ISO8601Format class' Javadoc for more details.
rest-web-service.php 2.69 KiB
<?php
/**
* REST Web Service using http://flightphp.com/
* This Web Service should be called only by authorized applications external to
* RAP, so this directory should be password protected.
*
* Apache configuration:
* <Location "/rap-ia2/ws">
* AuthType basic
* AuthName RAP
* AuthUserFile rap-service-passwd
* Require valid-user
* </Location>
*/
//
$WS_PREFIX = '/ws';
/**
* Retrieve user information from login token.
*/
Flight::route('GET ' . $WS_PREFIX . '/user-info', function() {
global $dao;
$token = Flight::request()->query['token'];
$userData = $dao->findLoginToken($token);
if (is_null($userData)) {
http_response_code(404);
die("Token not found");
}
$dao->deleteLoginToken($token);
header('Content-Type: text/plain');
echo $userData;
});
/**
* Retrieve user information from user ID.
*/
Flight::route('GET ' . $WS_PREFIX . '/user/@userId', function($userId) {
global $dao;
$user = $dao->findUserById($userId);
if ($user !== null) {
header('Content-Type: application/json');
echo json_encode($user);
} else {
http_response_code(404);
die("User not found");
}
});
/**
* Search users from search text (name, surname, email).
*/
Flight::route('GET ' . $WS_PREFIX . '/user', function() {
global $dao;
$searchText = Flight::request()->query['search'];
$users = $dao->searchUser($searchText);
echo json_encode($users);
});
/**
* Create new user from identity data. Return the new user encoded in JSON.
*/
Flight::route('POST ' . $WS_PREFIX . '/user', function() {
global $userHandler;
$postData = Flight::request()->data;
$user = new RAP\User();
$identity = new RAP\Identity($postData['type']);
$identity->email = $postData['email'];
$identity->typedId = $postData['typedId'];
if (isset($postData['name'])) {
$identity->name = $postData['name'];
}
if (isset($postData['surname'])) {
$identity->surname = $postData['surname'];
}
if (isset($postData['institution'])) {
$identity->institution = $postData['institution'];
}
if (isset($postData['eppn'])) {
$identity->eppn = $postData['eppn'];
}
$user->addIdentity($identity);
$userHandler->saveUser($user);
echo json_encode($user);
});
/**
* Performs a join.
*/
Flight::route('POST ' . $WS_PREFIX . '/join', function() {
global $userHandler;
$postData = Flight::request()->data;
$userHandler->joinUsers($postData['user1'], $postData['user2']);
// if the join has success, returns the remaining user id
echo $postData['user1'];
});
Flight::route('GET ' . $WS_PREFIX . '/test', function() {
});