Handles user login and logout

This commit is contained in:
Pierre
2017-05-17 14:43:12 +02:00
parent 3b0272a196
commit 033da4e0e3
7 changed files with 409 additions and 3 deletions

30
functions/errors.php Normal file
View File

@ -0,0 +1,30 @@
<?php
/**
* Error functions
*
* @author Pierre HUBERT
*/
/**
* Display a rest fatal error
*
* @param Integer $errorCode The code of the error
* @param String $errorMessage The message of the error
*/
function Rest_fatal_error($errorCode, $errorMessage){
//Returns a fatal error code
http_response_code($errorCode);
//Display message
header("Content-Type: application/json");
echo json_encode(array(
"error" => array(
"code"=>$errorCode,
"message" => $errorMessage,
)
), JSON_PRETTY_PRINT);
//Quit
exit();
}

25
functions/strings.php Normal file
View File

@ -0,0 +1,25 @@
<?php
/**
* API specific methods
*
* @author Pierre HUBERT
*/
/**
* Generate a random string, using a cryptographically secure
* pseudorandom number generator (random_int)
*
* @param int $length How many characters do we want?
* @param string $keyspace A string of all possible characters
* to select from
* @return string
*/
function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
{
$str = '';
$max = mb_strlen($keyspace, '8bit') - 1;
for ($i = 0; $i < $length; ++$i) {
$str .= $keyspace[random_int(0, $max)];
}
return $str;
}