Merge branch '641-create-capi-call-to-verify-if-resq-user' into 'master-fix'

Resolve "Create capi call to verify if resq user"

See merge request jankstudio/resq!753
This commit is contained in:
Kendrick Chan 2021-12-03 05:57:12 +00:00
commit aa529e7411
4 changed files with 53 additions and 0 deletions

View file

@ -57,6 +57,8 @@ access_keys:
acls:
- id: customer.register
label: Register Customer
- id: customer.verify
label: Verify Customer
- id: municipality
label: Municipality
acls:

View file

@ -155,6 +155,12 @@ capi_customer_register:
controller: App\Controller\CAPI\CustomerController::register
methods: [POST]
# verify if resq customer
capi_customer_verify:
path: /capi/customer/{customer_hash}
controller: App\Controller\CAPI\CustomerController::verifyCustomer
methods: [GET]
# customer warranty api
capi_cwarr_check:
path: /capi/customer_warranty/{serial}

View file

@ -15,6 +15,8 @@ use App\Entity\Customer;
use App\Entity\CustomerVehicle;
use App\Entity\Vehicle;
use App\Service\HashGenerator;
use Catalyst\APIBundle\Access\Generator as ACLGenerator;
class CustomerController extends APIController
@ -202,6 +204,45 @@ class CustomerController extends APIController
return new APIResponse(true, $message, $data);
}
public function verifyCustomer($customer_hash, EntityManagerInterface $em, HashGenerator $hash)
{
$this->denyAccessUnlessGranted('customer.verify', null, 'No access.');
// get customer id from customer_hash
$cust_id = $hash->getID($customer_hash);
if ($cust_id == null)
return new APIResponse(false, 'Invalid customer hash.');
// find customer using id
$customer = $em->getRepository(Customer::class)->find($cust_id);
$data = [];
$message = '';
if ($customer == null)
{
$message = 'Customer not found.';
$data[] = [
'is_customer' => false,
'first_name' => '',
'last_name' => '',
'mobile_number' => '',
];
}
else
{
$message = 'Customer found.';
$data[] = [
'is_customer' => true,
'first_name' => $customer->getFirstName(),
'last_name' => $customer->getLastName(),
'mobile_number' => $customer->getPhoneMobile(),
];
}
return new APIResponse(true, $message, $data);
}
protected function cleanPlateNumber($plate)
{
// remove spaces and make upper case

View file

@ -21,6 +21,10 @@ class HashGenerator
$hi = new Hashids($this->salt, $this->length);
$id_array = $hi->decode($hash);
// return null if unable to decode aka invalid hash
if (empty($id_array))
return null;
// first one should be the id
return $id_array[0];
}