Update JWT Token
This commit is contained in:
@@ -22,50 +22,40 @@ class Authorization
|
||||
$acceptHeader = $request->header('Accept');
|
||||
$contentType = $request->header('Content-Type');
|
||||
$locale = $request->header('Accept-Language');
|
||||
$authorization = $request->header('Authorization');
|
||||
|
||||
// Add language
|
||||
if(!$locale)
|
||||
{
|
||||
return ApiResponse::apiResponse('Unauthorized', null, trans('Validation.required', ['attribute' => 'Accept-Language']), 401);
|
||||
if (!$locale) {
|
||||
return ApiResponse::apiResponse(
|
||||
'Unauthorized',
|
||||
null,
|
||||
trans('Validation.required', ['attribute' => 'Accept-Language']),
|
||||
401
|
||||
);
|
||||
}
|
||||
if($locale !== 'en-US' && $locale !== 'id-ID')
|
||||
{
|
||||
return ApiResponse::apiResponse('Bad Request', null, trans('Validation.invalid', ['attribute' => 'Accept-Language']), 400);
|
||||
}
|
||||
if ($locale === 'en-US')
|
||||
{
|
||||
|
||||
if ($locale === 'en-US') {
|
||||
App::setLocale('en');
|
||||
} elseif ($locale === 'id-ID')
|
||||
{
|
||||
} elseif ($locale === 'id-ID') {
|
||||
App::setLocale('id');
|
||||
} else
|
||||
{
|
||||
App::setLocale('en');
|
||||
}
|
||||
|
||||
// Validate authorization
|
||||
if (empty($authorization) || strpos($authorization, 'Bearer ') !== 0) {
|
||||
return ApiResponse::apiResponse('Unauthorized', null, trans('Validation.required', ['attribute' => 'Authorization']), 401);
|
||||
if ($acceptHeader !== 'application/json') {
|
||||
return ApiResponse::apiResponse(
|
||||
'Bad Request',
|
||||
null,
|
||||
trans('Validation.invalid', ['attribute' => 'Accept']),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
// Validate type accept & content type
|
||||
if (!$acceptHeader)
|
||||
{
|
||||
return ApiResponse::apiResponse('Unauthorized', null, trans('Validation.required', ['attribute' => 'Accept']), 401);
|
||||
}
|
||||
if (!$contentType && $request->isMethod('post'))
|
||||
{
|
||||
return ApiResponse::apiResponse('Unauthorized', null, trans('Validation.required', ['attribute' => 'Content-Type']), 401);
|
||||
}
|
||||
if ($acceptHeader !== 'application/json')
|
||||
{
|
||||
return ApiResponse::apiResponse('Bad Request', null, trans('Validation.invalid', ['attribute' => 'Accept']), 400);
|
||||
}
|
||||
if($contentType !== 'application/json' && $request->isMethod('post'))
|
||||
{
|
||||
return ApiResponse::apiResponse('Bad Request', null, trans('Validation.invalid', ['attribute' => 'Content-Type']), 400);
|
||||
if ($request->isMethod('post') && $contentType !== 'application/json') {
|
||||
return ApiResponse::apiResponse(
|
||||
'Bad Request',
|
||||
null,
|
||||
trans('Validation.invalid', ['attribute' => 'Content-Type']),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user