mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-08 17:34:39 +01:00
Reformat some responses
This commit is contained in:
parent
f3adb0b5dd
commit
297b55f66f
@ -4,6 +4,7 @@
|
||||
|
||||
use Throwable;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
@ -48,10 +49,15 @@ public function report(Throwable $exception)
|
||||
*/
|
||||
public function render($request, Throwable $exception)
|
||||
{
|
||||
if ($exception instanceof ModelNotFoundException) {
|
||||
return response()->json([
|
||||
'message' => str_replace('App\\', '', $exception->getModel()).' not found'], 404);
|
||||
}
|
||||
if ($exception instanceof InvalidQrCodeException) {
|
||||
return response()->json([
|
||||
'message' => 'not a valid QR code'], 400);
|
||||
}
|
||||
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
}
|
@ -76,7 +76,11 @@ protected function sendLoginResponse(Request $request)
|
||||
|
||||
$this->authenticated($request, $this->guard()->user());
|
||||
|
||||
return response()->json(['message' => $success], Response::HTTP_OK);
|
||||
return response()->json([
|
||||
'message' => 'authenticated',
|
||||
'token' => $success['token'],
|
||||
'name' => $success['name']
|
||||
], Response::HTTP_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,13 +58,11 @@ public function register(Request $request)
|
||||
|
||||
//$this->guard()->login($user);
|
||||
|
||||
$success['token'] = $user->createToken('MyApp')->accessToken;
|
||||
$success['name'] = $user->name;
|
||||
|
||||
return response()->json(['message' => $success]);
|
||||
|
||||
// return $this->registered($request, $user)
|
||||
// ?: redirect($this->redirectPath());
|
||||
return response()->json([
|
||||
'message' => 'account created',
|
||||
'token' => $user->createToken('MyApp')->accessToken,
|
||||
'name' => $user->name,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,8 +24,9 @@ public function upload(Request $request)
|
||||
]);
|
||||
|
||||
$path = $request->file('icon')->store('public/icons');
|
||||
$response['filename'] = pathinfo($path)['basename'];
|
||||
|
||||
return response()->json(pathinfo($path)['basename'], 201);
|
||||
return response()->json($response, 201);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user