Merge pull request #19 from amalfra/dev

Connection to database failed. Ensure api is writable.
This commit is contained in:
Matt 2014-10-20 15:05:06 -04:00
commit 43075eec67
2 changed files with 28 additions and 25 deletions

8
api/api.php Normal file → Executable file
View File

@ -15,8 +15,16 @@ $app->response->headers->set('Content-Type', 'application/json');
$jsonResponse = new JsonResponse();
require_once('helpers.php'); // Must come after $jsonResponse exists.
// Catch Exception if connection to DB failed
try {
R::setup('sqlite:taskboard.db');
createInitialUser();
} catch(Exception $e) {
$app->response->setStatus(503);
$jsonResponse->message = 'Connection to Database failed. Ensure api is writable.';
$app->response->setBody($jsonResponse->asJson());
}
$app->notFound(function() use ($app, $jsonResponse) {
$app->response->setStatus(404);

7
api/userRoutes.php Normal file → Executable file
View File

@ -6,7 +6,7 @@ $app->post('/login', function() use ($app, $jsonResponse) {
$expires = ($data->rememberme)
? (2 * 7 * 24 * 60 * 60) /* Two weeks */
: (1.5 * 60 * 60) /* One and a half hours */;
try {
$lookup = R::findOne('user', ' username = ? ', [$data->username]);
$jsonResponse->message = 'Invalid username or password.';
@ -30,11 +30,6 @@ $app->post('/login', function() use ($app, $jsonResponse) {
$app->response->setStatus(200);
}
}
} catch (Exception $ex) {
}
if (!is_writable('taskboard.db')) {
$jsonResponse->message = 'The api directory is not writable.';
}
$app->response->setBody($jsonResponse->asJson());
});