[add] Added wrapper for login method
Also changed the logout endpoint to get
This commit is contained in:
parent
23868b60ee
commit
0449f202ef
@ -69,7 +69,7 @@ class SessionApplication{
|
||||
|
||||
// If the credentials don't match anything in the the records
|
||||
if(!isset($storedPassword)){
|
||||
throw new Exception('The user or password didnt match, please try again.');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Already has a session
|
||||
@ -82,7 +82,22 @@ class SessionApplication{
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
throw new Exception('The user or password didnt match, please try again.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $userName
|
||||
* @param $password
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
function login($userName, $password){
|
||||
if($this->newSession($userName, $password)){
|
||||
return array('status' => 'success', 'message' => 'Logged in successfully.');
|
||||
}
|
||||
else{
|
||||
throw new Exception('The user or password didnt match, please try again.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,14 +22,14 @@ $app->get('/api/session', function (Request $request, Response $response, array
|
||||
$app->post('/api/session/login', function ($request, $response) {
|
||||
$requestData = $request->getParsedBody();
|
||||
|
||||
$data = $this->sessionApplication->newSession($requestData['userName'], $requestData['password']);
|
||||
$data = $this->sessionApplication->login($requestData['userName'], $requestData['password']);
|
||||
|
||||
return $response->withStatus(200)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->write(json_encode($data));
|
||||
});
|
||||
|
||||
$app->post('/api/session/logout', function (Request $request, Response $response, array $args) {
|
||||
$app->get('/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()));
|
||||
|
Loading…
Reference in New Issue
Block a user