[add] Endpoints to handle sessions

This commit is contained in:
2018-08-05 20:06:43 -06:00
parent d7be1f1d9c
commit 816b1e356a
3 changed files with 81 additions and 31 deletions

View File

@@ -13,6 +13,11 @@ $app->get('/[{name}]', function (Request $request, Response $response, array $ar
return $this->renderer->render($response, 'index.phtml', $args);
});
$app->get('/api/session', function (Request $request, Response $response, array $args) {
return $response->withStatus(200)
->withHeader('Content-Type', 'application/json')
->write(json_encode($this->sessionApplication->checkCurrentSession()));
});
$app->post('/api/session/login', function ($request, $response) {
$RequestData = $request->getParsedBody();
@@ -24,25 +29,8 @@ $app->post('/api/session/login', function ($request, $response) {
->write(json_encode($data));
});
$app->get('/api/encrypt/{string}', function (Request $request, Response $response, array $args) {
return $this->cryptographyService->encryptString($args['string']);
});
$app->get('/api/decrypt/{string}', function (Request $request, Response $response, array $args) {
return $this->cryptographyService->decryptString($args['string']);
});
$app->get('/api/encrypt/password/{string}', function (Request $request, Response $response, array $args) {
return $this->cryptographyService->encryptPassword($args['string']);
});
$app->get('/api/decrypt/password/{string}', function (Request $request, Response $response, array $args) {
$cosa = $this->cryptographyService->decryptPassword("pablso", "$2y$12$4T.gxWkQNPPFQau7ghfiQegdJQOm1yLTlbOTvcI3AizyqF/JSHr06");
if ($cosa){
return "yea";
}
else{
"nah";
}
$app->post('/api/session/logout', function (Request $request, Response $response, array $args) {
return $response->withStatus(200)
->withHeader('Content-Type', 'application/json')
->write(json_encode($this->sessionApplication->destroySession()));
});