fix error formatting

This commit is contained in:
David Bomba 2019-09-24 08:37:38 +10:00
parent 176ba8dac5
commit d34b129474
8 changed files with 59 additions and 14 deletions

View File

@ -32,8 +32,8 @@ class InvitationController extends Controller
public function invoiceRouter(string $invitation_key)
{
$invitation = InvoiceInvitation::whereInvitationKey($invitation_key)->first();
// $invitation = InvoiceInvitation::whereRaw("BINARY `invitation_key`= ?", [$invitation_key])->first();
// $invitation = InvoiceInvitation::whereInvitationKey($invitation_key)->first();
$invitation = InvoiceInvitation::whereRaw("BINARY `invitation_key`= ?", [$invitation_key])->first();
if($invitation){
$invitation->markViewed();

View File

@ -30,8 +30,10 @@ class ApiSecretCheck
return $next($request);
else {
$error['error'] = ['message' => 'Invalid secret'];
$error = [
'message' => 'Invalid secret',
'errors' => []
];
return response()
->json(json_encode($error, JSON_PRETTY_PRINT) ,403)
->header('X-App-Version', config('ninja.app_version'))

View File

@ -28,7 +28,11 @@ class ContactSetDb
public function handle($request, Closure $next)
{
$error['error'] = ['message' => 'Database could not be set'];
$error = [
'message' => 'Invalid Token',
'errors' => []
];
// we must have a token passed, that matched a token in the db, and multiDB is enabled.
// todo i don't think we can call the DB prior to setting it???? i think this if statement needs to be rethought

View File

@ -32,14 +32,24 @@ class ContactTokenAuth
if( $request->header('X-API-TOKEN') && ($client_contact = ClientContact::with(['company'])->whereRaw("BINARY `token`= ?",[$request->header('X-API-TOKEN')])->first() ) )
{
$error = [
'message' => 'Authentication disabled for user.',
'errors' => []
];
//client_contact who once existed, but has been soft deleted
if(!$client_contact)
return response()->json(json_encode(['message' => 'Authentication disabled for user.'], JSON_PRETTY_PRINT) ,403);
return response()->json(json_encode($error, JSON_PRETTY_PRINT) ,403);
$error = [
'message' => 'Access is locked.',
'errors' => []
];
//client_contact who has been disabled
if($client_contact->is_locked)
return response()->json(json_encode(['message' => 'Access is locked.'], JSON_PRETTY_PRINT) ,403);
return response()->json(json_encode($error, JSON_PRETTY_PRINT) ,403);
//stateless, don't remember the contact.
auth()->guard('contact')->login($client_contact, false);
@ -49,7 +59,12 @@ class ContactTokenAuth
}
else {
return response()->json(json_encode(['message' => 'Invalid token'], JSON_PRETTY_PRINT) ,403);
$error = [
'message' => 'Invalid token',
'errors' => []
];
return response()->json(json_encode($error, JSON_PRETTY_PRINT) ,403);
}
return $next($request);

View File

@ -28,7 +28,10 @@ class SetDb
public function handle($request, Closure $next)
{
$error['error'] = ['message' => 'Database could not be set'];
$error = [
'message' => 'Invalid Token',
'errors' => []
];
// we must have a token passed, that matched a token in the db, and multiDB is enabled.
// todo i don't think we can call the DB prior to setting it???? i think this if statement needs to be rethought

View File

@ -26,8 +26,11 @@ class SetDomainNameDb
public function handle($request, Closure $next)
{
$error['error'] = ['message' => 'Database could not be set'];
$error = [
'message' => 'Invalid token',
'errors' => []
];
/*
* Use the host name to set the active DB
**/

View File

@ -17,6 +17,7 @@ class SetWebDb
*/
public function handle($request, Closure $next)
{
if (config('ninja.db.multi_db_enabled'))
{

View File

@ -33,9 +33,14 @@ class TokenAuth
$user = $company_token->user;
$error = [
'message' => 'User inactive',
'errors' => []
];
//user who once existed, but has been soft deleted
if(!$user)
return response()->json(json_encode(['message' => 'User inactive'], JSON_PRETTY_PRINT) ,403);
return response()->json(json_encode($error, JSON_PRETTY_PRINT) ,403);
/*
|
@ -47,8 +52,15 @@ class TokenAuth
$user->setCompany($company_token->company);
//user who once existed, but has been soft deleted
if($user->user_company()->is_locked)
return response()->json(json_encode(['message' => 'User access locked'], JSON_PRETTY_PRINT) ,403);
if($user->user_company()->is_locked){
$error = [
'message' => 'User access locked',
'errors' => []
];
return response()->json(json_encode($error, JSON_PRETTY_PRINT) ,403);
}
//stateless, don't remember the user.
auth()->login($user, false);
@ -58,7 +70,12 @@ class TokenAuth
}
else {
return response()->json(json_encode(['message' => 'Invalid token'], JSON_PRETTY_PRINT) ,403);
$error = [
'message' => 'Invalid token',
'errors' => []
];
return response()->json(json_encode($error, JinvoicelspSON_PRETTY_PRINT) ,403);
}
return $next($request);