From a0e27c10ba1bad026af0404b810f98e3f43fdd2e Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Sun, 14 Jun 2020 08:37:30 +0100 Subject: [PATCH] + Verify users identification --- app/Http/Controllers/UserController.php | 24 +++++++++++++----------- resources/lang/en/messages.php | 2 +- resources/lang/fr/messages.php | 2 +- routes/web.php | 4 ++-- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index e14c6ed..ca0bcb4 100755 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -42,12 +42,11 @@ class UserController extends Controller $identification->fill($request->all()); $identification->id_user = $user->id; - $identification->user_code = $this->generateRandomString(); $identification->status = 0; $identification->save(); $this->sendMail($user->email,trans('messages.successful_identification'), - trans('messages.successful_identification_message',['name'=>$identification->lastname.' '.$identification->firstname,'user_code'=>$identification->user_code])); + trans('messages.successful_identification_message',['name'=>$identification->lastname.' '.$identification->firstname])); return $this->successResponse(trans('messages.successful_identification')); } @@ -71,25 +70,28 @@ class UserController extends Controller $identification->document_image_front = $this->uploadImage($request,'document_image_front','D-F',"documents"); $identification->document_image_back = $this->uploadImage($request,'document_image_back','D-B',"documents"); $identification->user_image = $this->uploadImage($request,'user_image','U',"photos"); + $identification->user_code = $this->generateRandomString(); $identification->status = 1; $identification->save(); - $this->sendMail($identification->user->email,trans('messages.validated_identification'),trans('messages.validated_identification_message')); + $this->sendMail($identification->user->email,trans('messages.validated_identification'),trans('messages.validated_identification_message',['user_code'=>$identification->user_code])); return $this->successResponse(trans('messages.validated_identification')); } - public function fetchIdentification($user_code) + public function fetchIdentification($user_phone) { - return Identification::where('user_code', $user_code)->firstOrFail(); + $user = User::where('phone', $user_phone)->firstOrFail(); + return Identification::where('id_user', $user->id)->firstOrFail(); } - public function verifyIdentification($id_user) + public function verifyIdentification($user_phone) { - $identification = Identification::where('id_user', $id_user)->firstOrFail(); - if($identification->status == 1) - return $this->successResponse(trans('messages.user_identificated'),Response::HTTP_NO_CONTENT); - else - return $this->successResponse($identification); + $user = User::where('phone', $user_phone)->firstOrFail(); + $identification = Identification::where('id_user', $user->id)->first(); + if($identification){ + return $this->errorResponse(trans('messages.user_identificated')); + }else + return $this->successResponse($user); } private function generateRandomString($length = 10) diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index de6f4fc..6740292 100755 --- a/resources/lang/en/messages.php +++ b/resources/lang/en/messages.php @@ -15,12 +15,12 @@ return [ 'successful_identification_message' => 'Hi :name, Your identification has been taken into account. Contact an iLink World agent with your ID to validate your identity. -Your username: :user_code Regards, iLinkWorld team.', 'validated_identification_message' => 'Your identification is confirmed! +Your username: :user_code You can now use the services of iLink World. Welcome to the iLink World family !!! diff --git a/resources/lang/fr/messages.php b/resources/lang/fr/messages.php index bff0a8d..88bff9c 100755 --- a/resources/lang/fr/messages.php +++ b/resources/lang/fr/messages.php @@ -15,12 +15,12 @@ return [ 'successful_identification_message' => 'Salut :name, Votre identification a été prise en compte . Rapprochez vous auprès d\'un agent iLink World muni de votre pièce d\'identité pour faire valider de votre identité. -Votre identifiant : :user_code Cordialement, Equipe iLinkWorld.', 'validated_identification_message' => 'Votre identification est confirmée ! +Votre identifiant : :user_code Vous pouvez desormais utiliser les services de iLink World. Bienvenue dans la famille iLink World !!! diff --git a/routes/web.php b/routes/web.php index 321e3d0..e10870a 100755 --- a/routes/web.php +++ b/routes/web.php @@ -47,7 +47,7 @@ $router->group(['prefix' => '/wallets'] , function () use ($router){ $router->group(['prefix' => '/identifications'] , function () use ($router){ $router->post('','UserController@identification'); $router->post('{id_identification}','UserController@validateIdentification'); - $router->get('{user_code}','UserController@fetchIdentification'); - $router->get('verify/{id_user}','UserController@verifyIdentification'); + $router->get('{user_phone}','UserController@fetchIdentification'); + $router->get('verify/{user_phone}','UserController@verifyIdentification'); });