first commit
This commit is contained in:
44
app/Http/Middleware/Authenticate.php
Normal file
44
app/Http/Middleware/Authenticate.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Auth\Factory as Auth;
|
||||
|
||||
class Authenticate
|
||||
{
|
||||
/**
|
||||
* The authentication guard factory instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Auth\Factory
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Create a new middleware instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Factory $auth
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Auth $auth)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if ($this->auth->guard($guard)->guest()) {
|
||||
return response('Unauthorized.', 401);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
168
app/Http/Middleware/BookingEngineTokenMiddleware.php
Normal file
168
app/Http/Middleware/BookingEngineTokenMiddleware.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Core\Service\FindCountryCodeService;
|
||||
use App\Core\Service\PropertyBookingEngineService;
|
||||
use App\Core\Service\PropertyChannelMappingService;
|
||||
use App\Core\Service\PropertyChannelService;
|
||||
use App\Core\Service\PropertyWebService;
|
||||
use App\Exceptions\ApiErrorException;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use App\Models\User;
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class BookingEngineTokenMiddleware
|
||||
{
|
||||
|
||||
private $propertyWebService;
|
||||
|
||||
public function __construct(
|
||||
PropertyWebService $propertyWebService,
|
||||
PropertyChannelService $channelService,
|
||||
PropertyChannelMappingService $propertyChannelMappingService,
|
||||
PropertyBookingEngineService $propertyBookingEngineService,
|
||||
FindCountryCodeService $findCountryCodeService
|
||||
)
|
||||
{
|
||||
$this->propertyWebService = $propertyWebService;
|
||||
$this->channelService = $channelService;
|
||||
$this->propertyChannelMappingService = $propertyChannelMappingService;
|
||||
$this->propertyBookingEngineService = $propertyBookingEngineService;
|
||||
$this->findCountryCodeService = $findCountryCodeService;
|
||||
}
|
||||
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
$channelToken = $request->header('channelToken');
|
||||
$bookingEngineToken = $request->header('bookingEngineToken');
|
||||
|
||||
if (!$channelToken) {
|
||||
return apiResponse(0, 'Token not provided.', null, 401);
|
||||
}
|
||||
|
||||
$channelRequest = [
|
||||
'criteria' => [
|
||||
['field' => 'token', 'condition' => '=', 'value' => $channelToken],
|
||||
['field' => 'status', 'condition' => '=', 'value' => 1],
|
||||
],
|
||||
'firstRow' => 1
|
||||
];
|
||||
|
||||
$channelCheck = $this->channelService->select($channelRequest);
|
||||
|
||||
if ($channelCheck['status'] != 'success' || empty($channelCheck['data'])) {
|
||||
return apiResponse(0, 'Channel Token not found.', null, 401);
|
||||
}
|
||||
|
||||
|
||||
$bookingEnginePropertyId = null;
|
||||
if (in_array($channelCheck['data']['channel_category_id'], [2, 3, 7])) {
|
||||
|
||||
if (is_null($bookingEngineToken)) {
|
||||
if (!in_array($channelCheck['data']['channel_category_id'], [7])) {
|
||||
return apiResponse(0, 'Booking Engine Token not found.', null, 401);
|
||||
}
|
||||
}
|
||||
|
||||
$bookingEngineRequest = [
|
||||
'criteria' => [
|
||||
['field' => 'token', 'condition' => '=', 'value' => $bookingEngineToken],
|
||||
['field' => 'status', 'condition' => '=', 'value' => 1],
|
||||
],
|
||||
'firstRow' => 1
|
||||
];
|
||||
|
||||
$bookingEngineCheck = $this->propertyBookingEngineService->select($bookingEngineRequest);
|
||||
|
||||
if ($bookingEngineCheck['status'] != 'success' || empty($bookingEngineCheck['data'])) {
|
||||
if (!in_array($channelCheck['data']['channel_category_id'], [7])) {
|
||||
return apiResponse(0, 'Booking Engine Token not found.', null, 401);
|
||||
}
|
||||
}
|
||||
|
||||
$bookingEnginePropertyId = isset($bookingEngineCheck['data']['property_id']) ? $bookingEngineCheck['data']['property_id'] : null;
|
||||
|
||||
|
||||
//channelToken Manipulation
|
||||
$params = json_decode($request->getContent(), 1);
|
||||
|
||||
if (fillOnUndefined($params, 'ipAddress') && fillOnUndefined($params,'referrer') != 'google') {
|
||||
// Find Country Code with IP
|
||||
$ipResponse = $this->findCountryCodeService->findCountryWithIpAddress($params['ipAddress']);
|
||||
|
||||
if ($ipResponse['status'] == 'success') {
|
||||
|
||||
$propertyChannelMappingParam = [
|
||||
'criteria' => [
|
||||
['field' => 'property_id', 'condition' => '=', 'value' => $bookingEnginePropertyId],
|
||||
['field' => 'status', 'condition' => '=', 'value' => 1],
|
||||
],
|
||||
'with' => ['channel'],
|
||||
];
|
||||
|
||||
$propertyChannelMapping = $this->propertyChannelMappingService->select($propertyChannelMappingParam);
|
||||
|
||||
$ipCountryCode = isset($ipResponse['data']['code']) ? $ipResponse['data']['code'] : 'tr';
|
||||
|
||||
if ($propertyChannelMapping['status'] == 'success') {
|
||||
|
||||
$propertyChannelMappingCollect = collect($propertyChannelMapping['data']);
|
||||
$countryChannel = $propertyChannelMappingCollect
|
||||
->where('channel.channel_category_id', 3)
|
||||
->where('channel.country_code', $ipCountryCode)
|
||||
->where('channel.parent_id', 1)
|
||||
->first();
|
||||
|
||||
if (!empty($countryChannel)) {
|
||||
$channelToken = $countryChannel['channel']['token'];
|
||||
$channelCheck['data']['id'] = $countryChannel['channel']['id'];
|
||||
}
|
||||
|
||||
//countryCodeGroup
|
||||
if (empty($countryChannel)) {
|
||||
$countryChannelGroup = $propertyChannelMappingCollect
|
||||
->where('channel.channel_category_id', 3)
|
||||
->where('channel.country_code', 'group')
|
||||
->where('channel.parent_id', 1)
|
||||
->toArray();
|
||||
|
||||
if (!empty($countryChannelGroup)) {
|
||||
foreach ($countryChannelGroup as $country) {
|
||||
if (!empty($country['channel']['country_code_group'])) {
|
||||
if (in_array($ipCountryCode, $country['channel']['countryCodeGroupArray'])) {
|
||||
|
||||
$channelToken = $country['channel']['token'];
|
||||
$channelCheck['data']['id'] = $country['channel']['id'];
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//countryCodeGroup
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//channelToken Manipulation
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$request->channelId = $channelCheck['data']['id'];
|
||||
$request->channelToken = $channelToken;
|
||||
$request->bookingEngineToken = $bookingEngineToken;
|
||||
$request->bookingEnginePropertyId = $bookingEnginePropertyId;
|
||||
$request->bookingEngineChannelCategoryId = $channelCheck['data']['channel_category_id'];
|
||||
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Core\Service\PropertyChannelMappingService;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class CheckPropertyChannelConnectionMiddleware
|
||||
{
|
||||
|
||||
private $propertyChannelMappingService;
|
||||
private $request;
|
||||
private $response;
|
||||
|
||||
public function __construct(
|
||||
Request $request,
|
||||
Response $response,
|
||||
PropertyChannelMappingService $propertyChannelMappingService
|
||||
)
|
||||
{
|
||||
$this->propertyChannelMappingService = $propertyChannelMappingService;
|
||||
$this->request = $request;
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
|
||||
//TODO: Buraya kanal (channel_id) ve kanal grupları (channel_group_id) için property için bir kontrol koyulacak
|
||||
//dd($this->request->params['property_id']);
|
||||
|
||||
/*$response = $next($request);
|
||||
$propertyId = $request->property_id ? $request->property_id : fillOnUndefined($request->params, 'property_id');
|
||||
$channelId = fillOnUndefined($request->params, 'channel_id');
|
||||
|
||||
$checkParams = [
|
||||
'property_id' => $propertyId,
|
||||
'channel_id' => $channelId,
|
||||
|
||||
] ;
|
||||
|
||||
$checkMappingStatus =$this->propertyChannelMappingService->checkPropertyChannelMapping($checkParams);
|
||||
if ($checkMappingStatus['status'] != 'success') {
|
||||
return apiResponse(false, $checkMappingStatus['message'], null, 400);
|
||||
}
|
||||
|
||||
return $response;*/
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
||||
56
app/Http/Middleware/ContentWizardMiddleware.php
Normal file
56
app/Http/Middleware/ContentWizardMiddleware.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Core\Service\PropertyConfigService;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class ContentWizardMiddleware
|
||||
{
|
||||
|
||||
private $propertyConfigService;
|
||||
private $request;
|
||||
private $response;
|
||||
|
||||
public function __construct(
|
||||
Request $request,
|
||||
Response $response,
|
||||
PropertyConfigService $propertyConfigService
|
||||
)
|
||||
{
|
||||
$this->propertyConfigService = $propertyConfigService;
|
||||
$this->request = $request;
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
$response = $next($request);
|
||||
if ($response->getData()->status == 200) {
|
||||
$params = $this->request->params;
|
||||
$url = collect($this->request->route());
|
||||
$getNameArray = $url->where('as', '!=', null)->first();
|
||||
$routeAlias = fillOnUndefined($getNameArray, 'as');
|
||||
|
||||
if($routeAlias == 'Property.Contact.Update'){
|
||||
if(isset($params['contact']['address']) && isset($params['contact']['latitude']) && isset($params['contact']['longitude'])){
|
||||
$routeAlias = 'Property.Location.Update' ;
|
||||
}
|
||||
}
|
||||
$rateParams = [
|
||||
'property_id' => fillOnUndefined($params, 'property_id'),
|
||||
'user_id' => $this->request->credentials->user_id,
|
||||
'property_rate_for' => $routeAlias,
|
||||
];
|
||||
$this->propertyConfigService->rateProperty(array_merge($params, $rateParams));
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
35
app/Http/Middleware/CorsMiddleware.php
Normal file
35
app/Http/Middleware/CorsMiddleware.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
use Closure;
|
||||
use Exception ;
|
||||
|
||||
class CorsMiddleware
|
||||
{
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
||||
$headers = [
|
||||
'Access-Control-Allow-Origin' => '*',
|
||||
'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS, PUT, DELETE',
|
||||
'Access-Control-Allow-Credentials' => 'true',
|
||||
'Access-Control-Max-Age' => '86400',
|
||||
'Access-Control-Allow-Headers' => 'Content-Type, Authorization, X-Requested-With, language, authToken'
|
||||
];
|
||||
|
||||
$apiHeader = collect($request->headers)->toArray();
|
||||
|
||||
if ($request->isMethod('OPTIONS'))
|
||||
{
|
||||
return response()->json('{"method":"OPTIONS"}', 200, $headers);
|
||||
}
|
||||
$response = $next($request);
|
||||
foreach($headers as $key => $value)
|
||||
{
|
||||
//$response->header($key, $value);
|
||||
$response->headers->set($key, $value);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
20
app/Http/Middleware/ExampleMiddleware.php
Normal file
20
app/Http/Middleware/ExampleMiddleware.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
|
||||
class ExampleMiddleware
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
70
app/Http/Middleware/JwtMiddleware.php
Normal file
70
app/Http/Middleware/JwtMiddleware.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Core\Service\ApiAccessTokenService;
|
||||
use App\Exceptions\ApiErrorException ;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use App\Models\User;
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
class JwtMiddleware
|
||||
{
|
||||
|
||||
private $apiAccessTokenService;
|
||||
|
||||
public function __construct(
|
||||
ApiAccessTokenService $apiAccessTokenService
|
||||
)
|
||||
{
|
||||
$this->apiAccessTokenService = $apiAccessTokenService ;
|
||||
}
|
||||
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
$token = $request->header('authToken');
|
||||
|
||||
if (!$token) {
|
||||
return apiResponse(0, 'Token not provided.', null, 401);
|
||||
}
|
||||
|
||||
try {
|
||||
$credentials = JWT::decode($token, Config::get('app.jwt.secret'), ['HS256']);
|
||||
|
||||
$findTokenCriteria = [
|
||||
'criteria' => [
|
||||
['field' => 'token', 'condition' => '=', 'value' => md5($token) ],
|
||||
['field' => 'expire_date', 'condition' => '>', 'value' => time() ],
|
||||
['field' => 'user_id', 'condition' => '=', 'value' => $credentials->user_id ],
|
||||
['field' => 'invalidate', 'condition' => '=', 'value' => 0 ],
|
||||
],
|
||||
'firstRow' => 1
|
||||
];
|
||||
$getTokenData = $this->apiAccessTokenService->select($findTokenCriteria);
|
||||
if(!$getTokenData['data']){
|
||||
throw new ExpiredException();
|
||||
}
|
||||
|
||||
} catch (ExpiredException $e) {
|
||||
return apiResponse(0, lang('Token is expired.'), null, 401);
|
||||
} catch (Exception $e) {
|
||||
return apiResponse(0, lang('An error while decoding token.'), null, 500);
|
||||
}
|
||||
|
||||
|
||||
$inputs = json_decode($request->getContent(), true);
|
||||
$inputs = is_array($inputs) ? $inputs : ["params" => []];
|
||||
|
||||
$user = User::find($credentials->user_id);
|
||||
|
||||
// Now let's put the user in the request class so that you can grab it from there
|
||||
$request->credentials = $credentials;
|
||||
$request->body = $inputs;
|
||||
$request->auth = $user;
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
27
app/Http/Middleware/LanguageSettingMiddleware.php
Normal file
27
app/Http/Middleware/LanguageSettingMiddleware.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use App\Core\Helper\LanguageService;
|
||||
use Exception;
|
||||
|
||||
class LanguageSettingMiddleware
|
||||
{
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
||||
$apiHeader = collect($request->headers)->toArray();
|
||||
if(!isset($apiHeader['language'])){
|
||||
return apiResponse(0, 'Language field is null.', null, 400);
|
||||
}
|
||||
$apiRequest = collect($request->params)->toArray();
|
||||
$apiRequest['locale'] = isset($apiRequest['locale']) ? $apiRequest['locale'] : reset($apiHeader['language']);
|
||||
LanguageService::setCurrentLanguage(reset($apiHeader['language']));
|
||||
$request->params = $apiRequest;
|
||||
app('translator')->setLocale(reset($apiHeader['language']));
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
67
app/Http/Middleware/MyWebTokenMiddleware.php
Normal file
67
app/Http/Middleware/MyWebTokenMiddleware.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Core\Service\PropertyWebService;
|
||||
use App\Exceptions\ApiErrorException ;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use App\Models\User;
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
class MyWebTokenMiddleware
|
||||
{
|
||||
|
||||
private $propertyWebService;
|
||||
|
||||
public function __construct(
|
||||
PropertyWebService $propertyWebService
|
||||
)
|
||||
{
|
||||
$this->propertyWebService = $propertyWebService ;
|
||||
}
|
||||
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
$token = $request->header('authToken');
|
||||
|
||||
if (!$token) {
|
||||
return apiResponse(0, 'Token not provided.', null, 401);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$findTokenCriteria = [
|
||||
'criteria' => [
|
||||
['field' => 'token', 'condition' => '=', 'value' => $token],
|
||||
],
|
||||
'firstRow' => 1
|
||||
];
|
||||
$getTokenData = $this->propertyWebService->select($findTokenCriteria);
|
||||
|
||||
if(!$getTokenData['data']){
|
||||
throw new ExpiredException();
|
||||
}
|
||||
|
||||
} catch (ExpiredException $e) {
|
||||
return apiResponse(0, lang('Token is expired.'), null, 400);
|
||||
} catch (Exception $e) {
|
||||
return apiResponse(0, lang('An error while decoding token.'), null, 500);
|
||||
|
||||
|
||||
}
|
||||
$inputs = json_decode($request->getContent(), true);
|
||||
$inputs = is_array($inputs) ? $inputs : ["params" => []];
|
||||
$inputs['params']['property_id'] = $getTokenData['data']['property_id'];
|
||||
$inputs['params']['property_web_id'] = $getTokenData['data']['id'];
|
||||
$inputs['params']['domain'] = $getTokenData['data']['domain'];
|
||||
$inputs['params']['default_language'] = $getTokenData['data']['default_language'];
|
||||
$inputs['params']['template_id'] = $getTokenData['data']['template_id'];
|
||||
$request->body = $inputs;
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
93
app/Http/Middleware/PropertyMiddleware.php
Normal file
93
app/Http/Middleware/PropertyMiddleware.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Core\Service\ServiceLogService;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use App\Models\User;
|
||||
use App\Core\Repository\UserPropertyMapping\UserPropertyMappingRepository;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class PropertyMiddleware
|
||||
{
|
||||
|
||||
private $userPropertyMappingRepository;
|
||||
|
||||
public function __construct(
|
||||
UserPropertyMappingRepository $userPropertyMappingRepository,
|
||||
ServiceLogService $serviceLogService
|
||||
)
|
||||
{
|
||||
$this->userPropertyMappingRepository = $userPropertyMappingRepository;
|
||||
$this->serviceLogService = $serviceLogService;
|
||||
}
|
||||
|
||||
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
$userId = $request->credentials->user_id;
|
||||
|
||||
$propertyId = $request->property_id ? $request->property_id : fillOnUndefined($request->params, 'property_id');
|
||||
if (!$propertyId) {
|
||||
return apiResponse(0, 'Property_id required.', null, 401);
|
||||
}
|
||||
$checkPropertyUserRequest = [
|
||||
'criteria' => [
|
||||
['field' => 'user_id', 'condition' => '=', 'value' => $userId],
|
||||
['field' => 'property_id', 'condition' => '=', 'value' => $propertyId],
|
||||
['field' => 'status', 'condition' => '=', 'value' => 1],
|
||||
],
|
||||
'with' => ['property'],
|
||||
'firstRow' => 1
|
||||
];
|
||||
|
||||
$checkPropertyUser = $this->userPropertyMappingRepository->findByCriteria($checkPropertyUserRequest);
|
||||
if (!$checkPropertyUser) {
|
||||
return apiResponse(0, 'User not matched this property.', null, 400);
|
||||
}
|
||||
|
||||
if (!$checkPropertyUser['property']['status']) {
|
||||
return apiResponse(0, 'User not matched this property.', null, 400);
|
||||
}
|
||||
|
||||
/** ServiceLog **/
|
||||
$request->serviceLogId = null;
|
||||
$request->serviceLogRequestTime = microtime(true);
|
||||
$selectedRoute = [
|
||||
//'Property.Dashboard',
|
||||
'Property.RoomRateMapping.RoomRateAvailabilityUpdate',
|
||||
'Property.RoomRateMapping.BulkUpdate',
|
||||
'RoomRateChannelPromotion.Update',
|
||||
'Property.Promotion.Update',
|
||||
'PA.Property.Quick-Pricing.Sync'
|
||||
];
|
||||
$route = $request->route();
|
||||
$routeName = isset($route[1]['as']) ? $route[1]['as'] : null;
|
||||
$inputs = json_decode($request->getContent(), true);
|
||||
if (in_array($routeName, $selectedRoute)) {
|
||||
$serviceLogParam = [
|
||||
'property_id' => $propertyId,
|
||||
'user_id' => $userId,
|
||||
'service' => $routeName,
|
||||
'request' => json_encode($inputs),
|
||||
'ip_address' => $request->ip(),
|
||||
'status' => 2
|
||||
];
|
||||
|
||||
$serviceLog = $this->serviceLogService->create($serviceLogParam);
|
||||
|
||||
if($serviceLog['status'] == 'success' && !empty($serviceLog['data'])) {
|
||||
$request->serviceLogId = $serviceLog['data']['id'];
|
||||
}
|
||||
|
||||
}
|
||||
/** ServiceLog **/
|
||||
|
||||
return $next($request);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
45
app/Http/Middleware/UserRoutePermissionAuthorize.php
Normal file
45
app/Http/Middleware/UserRoutePermissionAuthorize.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Core\Permission\RoutePermissionAuthorize;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
|
||||
class UserRoutePermissionAuthorize
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
|
||||
private $routePermissionAuthorize;
|
||||
|
||||
public function __construct ( RoutePermissionAuthorize $routePermissionAuthorize )
|
||||
{
|
||||
$this->routePermissionAuthorize =$routePermissionAuthorize;
|
||||
}
|
||||
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
|
||||
$params = $request->params;
|
||||
$requestParams = [
|
||||
'property_id' => fillOnUndefined($params, 'property_id'),
|
||||
'user_id' => $request->credentials->user_id,
|
||||
];
|
||||
|
||||
$result = $this->routePermissionAuthorize->isUserAuthorizedForCurrentRoute($requestParams);
|
||||
|
||||
if ( !$result)
|
||||
{
|
||||
return apiResponse(0, "Your permission not authorised" , null, 400);
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user