Auto authenticate the user if logged in

This commit is contained in:
James Brooks 2015-06-02 08:35:30 +01:00
parent 2baf17b9d5
commit f550a7369e

View File

@ -45,20 +45,22 @@ class ApiAuthenticate
*/
public function handle($request, Closure $next)
{
if ($apiToken = $request->header('X-Cachet-Token')) {
try {
$user = User::findByApiToken($apiToken);
if ($this->auth->guest()) {
if ($apiToken = $request->header('X-Cachet-Token')) {
try {
$user = User::findByApiToken($apiToken);
$this->auth->onceUsingId($user->id);
} catch (ModelNotFoundException $e) {
$this->auth->onceUsingId($user->id);
} catch (ModelNotFoundException $e) {
return $this->handleError();
}
} elseif ($user = $request->getUser()) {
if ($this->auth->onceBasic() !== null) {
return $this->handleError();
}
} else {
return $this->handleError();
}
} elseif ($user = $request->getUser()) {
if ($this->auth->onceBasic() !== null) {
return $this->handleError();
}
} else {
return $this->handleError();
}
return $next($request);