137 lines
5.0 KiB
PHP
137 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
use Closure;
|
|
use Illuminate\Contracts\Auth\Guard;
|
|
use App\Libraries\CywareLibrary;
|
|
use Illuminate\Support\Facades\Response;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use App\Contracts\LoyaltyCardResourceInterface;
|
|
use App\Contracts\PersonalDetailsResourceInterface;
|
|
use App\Contracts\LcardActionLogsInterface;
|
|
|
|
class BeforeMiddleware
|
|
{
|
|
protected $auth;
|
|
protected $lcard_logs;
|
|
protected $loyalty_card;
|
|
protected $personal_details;
|
|
|
|
public function __construct(Guard $auth,LcardActionLogsInterface $lcard_logs,LoyaltyCardResourceInterface $loyalty_card,PersonalDetailsResourceInterface $personal_details)
|
|
{
|
|
$this->auth = $auth;
|
|
$this->lcard_logs = $lcard_logs;
|
|
$this->loyalty_card = $loyalty_card;
|
|
$this->personal_details = $personal_details;
|
|
}
|
|
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \Closure $next
|
|
* @return mixed
|
|
*/
|
|
public function handle($request, Closure $next)
|
|
{
|
|
if($this->auth->user() &&
|
|
(
|
|
$request->path() != "api/mobile/logout" ||
|
|
$request->path() != "api/mobile/loginCardNumber" ||
|
|
$request->path() != "api/mobile/loginCardNumberEnroll"
|
|
)
|
|
)
|
|
{
|
|
if($this->auth->user()->type == 2)
|
|
{
|
|
$cyware = new CywareLibrary;
|
|
$cyware->setCardNumber($this->auth->user()->username);
|
|
$cyware->state_validate();
|
|
|
|
$loyalty_card = $this->loyalty_card->getByField([
|
|
'card_number' => $this->auth->user()->username,
|
|
'cyware_synced' => 1,
|
|
'is_active' => 1
|
|
]);
|
|
|
|
if($cyware->response['message'] == 'Card number is deactivated')
|
|
{
|
|
$this->lcard_logs->log(0,'LOGIN','LOGOUT','Member is deactivated');
|
|
$this->loyalty_card->remove_deviceuuid($this->auth->user()->username, 1);
|
|
// Auth::user()->AauthAcessToken()->delete();
|
|
Auth::user()->token()->revoke();
|
|
$data = [
|
|
'status' => 0,
|
|
'code' => 5,
|
|
'message' => 'Your account has been deactivated'
|
|
];
|
|
return Response::json($data,200);
|
|
}
|
|
elseif($cyware->response['message'] == 'No Records Found' || $cyware->response['message'] == 'Account not found')
|
|
{
|
|
$this->lcard_logs->log(0,'LOGIN','LOGOUT','Member is removed');
|
|
$this->loyalty_card->remove_deviceuuid($this->auth->user()->username, 1);
|
|
Auth::user()->token()->revoke();
|
|
$data = [
|
|
'status' => 0,
|
|
'code' => 5,
|
|
'message' => 'Your account has been deleted'
|
|
];
|
|
return Response::json($data,200);
|
|
|
|
}
|
|
elseif ($loyalty_card[0]['is_locked'] == 1)
|
|
{
|
|
$this->lcard_logs->log(0,'LOGIN','LOGOUT','Member is locked');
|
|
$this->loyalty_card->remove_deviceuuid($this->auth->user()->username, 1);
|
|
Auth::user()->token()->revoke();
|
|
$data = [
|
|
'status' => 0,
|
|
'code' => 1,
|
|
'message' => 'Your account has been locked'
|
|
];
|
|
return Response::json($data,200);
|
|
}
|
|
else
|
|
{
|
|
$pd_id = $this->loyalty_card->sync_cyware($cyware->response['data']);
|
|
$this->personal_details->sync_cyware($pd_id,$cyware->response['data']);
|
|
}
|
|
}
|
|
}
|
|
|
|
// if($request->header('card_number'))
|
|
// {
|
|
// $card_number = $request->header('card_number');
|
|
// $loyalty_card = $this->loyalty_card->getByField([
|
|
// 'card_number' => $card_number,
|
|
// 'cyware_synced' => 1,
|
|
// 'is_active' => 1
|
|
// ]);
|
|
// if($loyalty_card[0]['cyware_deactivated'] == 1)
|
|
// {
|
|
// $data = [
|
|
// 'status' => 3,
|
|
// 'message' => 'Your account has been deactivated'
|
|
// ];
|
|
|
|
// return Response::json($data,203);
|
|
// }
|
|
|
|
// if(!$this->auth->user())
|
|
// {
|
|
// $data = [
|
|
// 'status' => 3,
|
|
// 'message' => 'Your account has logged in a different device'
|
|
// ];
|
|
|
|
// return Response::json($data,203);
|
|
// }
|
|
// }
|
|
|
|
return $next($request);
|
|
}
|
|
}
|