File "api-password.inc.php"
Full Path: /srv/www/www.cadoro.it/src/controllers/api-password.inc.php
File size: 781 bytes
MIME-type: text/x-php
Charset: utf-8
<?php
header('Access-Control-Allow-Origin: *');
header('Content-Type: text/json; charset="UTF-8"');
# POST
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$data = _json(file_get_contents('php://input'));
$email = _a($data, 'email');
$user = models\User::get_by_email($email);
if (!$user) {
$user = models\User::get_by_card($email);
}
if ($user) {
$user->email_password();
} else {
$user = null;
}
# JSON output
echo json_encode(array(
"user" => $user ? array("id" => (int)$user['id']) : null,
));
}
# DEFAULT
else {
header('HTTP/1.0 400 Bad Request', true, 400);
header("Content-Type: application/json; charset=utf-8");
echo json_encode(array("error" => "unsupported method"));
}
?>