Skip to content

Commit

Permalink
added try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
Surfoo committed Sep 5, 2018
1 parent bb50489 commit 7df7e44
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
24 changes: 16 additions & 8 deletions src/Georoadbook/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function indexAction(Application $app, Request $request)
];

if ($this->checkLogout($app, $request)) {
return $app->redirect('/');
$redirect = !empty($request->headers->get('referer')) ? $request->headers->get('referer') : '/';
return $app->redirect($redirect);
}

if ($app['session']->get('access_token')) {
Expand All @@ -45,10 +46,17 @@ public function indexAction(Application $app, Request $request)
*/
public function loginAction(Application $app, Request $request)
{
$login = new Login($app, $request);
$login->authenticate();

return $app->redirect('/');
try {
if (is_null($request->get('oauth_verifier')) && is_null($request->get('oauth_token'))) {
$app['session']->set('loginRedirect', !empty($request->headers->get('referer')) ? $request->headers->get('referer') : '/');
}
(new Login($app, $request))->authenticate();
$redirect = !is_null($app['session']->get('loginRedirect')) ? $app['session']->get('loginRedirect') : '/';
return $app->redirect($redirect);
}
catch(GeocachingOAuthException $e) {
echo $e->getMessage();
}
}

/**
Expand Down Expand Up @@ -182,7 +190,8 @@ public function uploadAction(Application $app, Request $request)
public function editAction(Application $app, Request $request, $id)
{
if ($this->checkLogout($app, $request)) {
return $app->redirect('/');
$redirect = !empty($request->headers->get('referer')) ? $request->headers->get('referer') : '/';
return $app->redirect($redirect);
}

$roadbook = new Georoadbook($app, $id);
Expand Down Expand Up @@ -342,8 +351,7 @@ public function deleteAction(Application $app, Request $request)
protected function checkLogout(Application $app, Request $request)
{
if ($request->get('logout') === '') {
$login = new Login($app, $request);
$login->logout();
(new Login($app, $request))->logout();
return true;
}

Expand Down
5 changes: 2 additions & 3 deletions src/Georoadbook/Process/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ public function authenticate()
$this->getToken();
}
} catch (GeocachingOAuthException $e) {
echo $e->getMessage();
return false;
$this->app['monolog']->error($e->getMessage());
throw $e;
}
return true;
}

public function logout()
Expand Down

0 comments on commit 7df7e44

Please sign in to comment.