From c411153dcaec500ddbc47a15dda7d90c979160bc Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Wed, 17 Feb 2021 14:38:37 +0100 Subject: [PATCH] - Update login management --- .../Controllers/Api/v1/CustomerController.php | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/Api/v1/CustomerController.php b/app/Http/Controllers/Api/v1/CustomerController.php index 9c92b76..28ae3c6 100644 --- a/app/Http/Controllers/Api/v1/CustomerController.php +++ b/app/Http/Controllers/Api/v1/CustomerController.php @@ -196,18 +196,38 @@ class CustomerController extends Controller if ($customer) { $login = $customer->logins()->where('brand_id', $brandId)->first(); if ($login) { - if ($login->status === 0) { - // "Le compte de l'utilisateur n'est pas activé" - return new StatusResource(['status' => 'KO', 'code' => 116, 'message' => 'Account not activated.']); - } else { - if (Hash::check($password, $login->password)) { - $login->last_connection = now(); - $customer->logins()->save($login); - return new CustomerResource($customer, $brandId); + if (Hash::check($password, $login->password)) { + if ($login->status === 0) { + // "Le compte de l'utilisateur n'est pas activé" + return new StatusResource( + [ + 'status' => 'KO', + 'code' => 116, + 'message' => 'Account not activated.', + 'user' => [ + 'crm_id' => $customer->id, + 'firstname' => $customer->infos()->firstname, + 'lastname' => $customer->infos()->lastname, + 'birth_date' => $customer->infos()->birth_date, + 'address' => $customer->infos()->address, + 'address2' => $customer->infos()->address2, + 'phone' => $customer->infos()->phone, + 'country' => $customer->infos()->country, + 'city' => $customer->infos()->city, + 'postcode' => $customer->infos()->postcode, + 'opt_in' => $customer->infos()->opt_in, + 'hashcode' => $customer->infos()->hashcode, + 'status' => $login->status, + ] + ]); } - // "Mot de passe incorrect" - return new StatusResource(['status' => 'KO', 'code' => 117, 'message' => 'Authentication failed.']); + + $login->last_connection = now(); + $customer->logins()->save($login); + return new CustomerResource($customer, $brandId); } + // "Mot de passe incorrect" + return new StatusResource(['status' => 'KO', 'code' => 117, 'message' => 'Authentication failed.']); } else { // "Ce compte n'est pas enregistré pour cette marque" return new StatusResource(['status' => 'KO', 'code' => 118, 'message' => 'User not found.']);