+ Add Modification of User identification

This commit is contained in:
Djery-Tom 2020-07-30 16:59:31 +01:00
parent b1a6d7d786
commit 95de0364c0
7 changed files with 128 additions and 55 deletions

View File

@ -10,12 +10,13 @@ use App\Traits\Helper;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Illuminate\Support\Facades\Date; use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\File;
class UserController extends Controller class UserController extends Controller
{ {
use ApiResponser; use ApiResponser;
use Helper; use Helper;
/** /**
* Create a new controller instance. * Create a new controller instance.
* *
@ -33,22 +34,45 @@ class UserController extends Controller
$this->validate($request, $identification->rules()); $this->validate($request, $identification->rules());
$dbIdentification = Identification::where('id_user', $request->id_user)->first(); $dbIdentification = Identification::where('id_user', $request->id_user)->first();
if($dbIdentification) if ($dbIdentification)
return $this->errorResponse(trans('errors.identification_carried_out')); return $this->errorResponse(trans('errors.identification_carried_out'));
if($request->has('id_user')) if ($request->has('id_user'))
$user = User::findOrFail($request->id_user); $user = User::findOrFail($request->id_user);
elseif ($request->has('phone_number')) elseif ($request->has('phone_number'))
$user = User::where('phone',$request->phone_number)->firstOrFail(); $user = User::where('phone', $request->phone_number)->firstOrFail();
$identification->fill($request->all()); $identification->fill($request->all());
$identification->id_user = $user->id; $identification->id_user = $user->id;
$identification->status = 0; $identification->status = 0;
$identification->save(); $identification->save();
$this->sendMail($user->email,trans('messages.successful_identification'), $this->sendMail($user->email, trans('messages.successful_identification'),
trans('messages.successful_identification_message',['name'=>$identification->lastname.' '.$identification->firstname])); trans('messages.successful_identification_message', ['name' => $identification->lastname . ' ' . $identification->firstname]));
return $this->successResponse(trans('messages.successful_identification',['name'=>$identification->lastname.' '.$identification->firstname])); return $this->successResponse(trans('messages.successful_identification', ['name' => $identification->lastname . ' ' . $identification->firstname]));
}
public function updateIdentification(Request $request)
{
$identification = Identification::findOrFail($request->id);
$identification->fill($request->all());
$identification->status = 0;
$this->deleteImageFile($identification->user_image, "photos");
$this->deleteImageFile($identification->document_image_front, "documents");
$this->deleteImageFile($identification->document_image_back, "documents");
$identification->user_image = '';
$identification->document_image_front = '';
$identification->document_image_back = '';
$identification->save();
$this->sendMail($identification->user->email, trans('messages.successful_identification_modification'),
trans('messages.successful_identification_modification_message', ['name' => $identification->lastname . ' ' . $identification->firstname]));
return $this->successResponse(trans('messages.successful_identification_modification', ['name' => $identification->lastname . ' ' . $identification->firstname]));
} }
public function validateIdentification(Request $request, $id_identification) public function validateIdentification(Request $request, $id_identification)
@ -64,14 +88,14 @@ class UserController extends Controller
'user_image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:6048', 'user_image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:6048',
]); ]);
$identification->document_image_front = $this->uploadImage($request,'document_image_front','D-F',"documents"); $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->document_image_back = $this->uploadImage($request, 'document_image_back', 'D-B', "documents");
$identification->user_image = $this->uploadImage($request,'user_image','U',"photos"); $identification->user_image = $this->uploadImage($request, 'user_image', 'U', "photos");
$identification->status = 1; $identification->status = 1;
$identification->save(); $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'));
return $this->successResponse(trans('messages.validated_identification')); return $this->successResponse(trans('messages.validated_identification'));
} }
@ -79,18 +103,18 @@ class UserController extends Controller
{ {
// return Identification::where('id_user', $id_user)->firstOrFail(); // return Identification::where('id_user', $id_user)->firstOrFail();
$user = User::where('phone', $user_phone)->first(); $user = User::where('phone', $user_phone)->first();
if($user){ if ($user) {
$identification = Identification::where('id_user', $user->id)->first(); $identification = Identification::where('id_user', $user->id)->first();
$data['isIdentified'] = false; $data['isIdentified'] = false;
$data['isIdentifiedValidated'] = false; $data['isIdentifiedValidated'] = false;
$data['data'] = $identification; $data['data'] = $identification;
if($identification){ if ($identification) {
$data['isIdentified'] = true; $data['isIdentified'] = true;
$data['isIdentifiedValidated'] = $identification->status == 1 ; $data['isIdentifiedValidated'] = $identification->status == 1;
} }
return $this->successResponse($data); return $this->successResponse($data);
}else{ } else {
return $this->errorResponse(trans('errors.user_phone_not_exist'),Response::HTTP_NOT_FOUND); return $this->errorResponse(trans('errors.user_phone_not_exist'), Response::HTTP_NOT_FOUND);
} }
} }
@ -98,14 +122,14 @@ class UserController extends Controller
public function verifyIdentification($user_phone) public function verifyIdentification($user_phone)
{ {
$user = User::where('phone', $user_phone)->first(); $user = User::where('phone', $user_phone)->first();
if($user){ if ($user) {
$identification = Identification::where('id_user', $user->id)->first(); $identification = Identification::where('id_user', $user->id)->first();
if($identification){ if ($identification) {
return $this->errorResponse(trans('messages.user_identificated')); return $this->errorResponse(trans('messages.user_identificated'));
}else } else
return $this->successResponse($user); return $this->successResponse($user);
}else{ } else {
return $this->errorResponse(trans('errors.user_phone_not_exist'),Response::HTTP_NOT_FOUND); return $this->errorResponse(trans('errors.user_phone_not_exist'), Response::HTTP_NOT_FOUND);
} }
} }
@ -121,11 +145,12 @@ class UserController extends Controller
return $randomString; return $randomString;
} }
public function rattachCard(Request $request , $id_user){ public function rattachCard(Request $request, $id_user)
{
$this->validate($request, [ $this->validate($request, [
// 'id_user' => 'required|integer|min:0|not_in:0', // 'id_user' => 'required|integer|min:0|not_in:0',
'numero_carte'=>'required', 'numero_carte' => 'required',
'expiration_date'=>'required_if:facade,front|date_format:m/y|after_or_equal:today', 'expiration_date' => 'required_if:facade,front|date_format:m/y|after_or_equal:today',
]); ]);
$user = User::findOrFail($id_user); $user = User::findOrFail($id_user);
$user->numero_carte = $request->numero_carte; $user->numero_carte = $request->numero_carte;
@ -137,32 +162,32 @@ class UserController extends Controller
return $this->successResponse(trans('messages.successful_card_attachment')); return $this->successResponse(trans('messages.successful_card_attachment'));
} }
public function uploadImage(Request $request , $key , $imageCode, $folderName) public function uploadImage(Request $request, $key, $imageCode, $folderName)
{ {
// if ($request->hasFile('image')) { // if ($request->hasFile('image')) {
$original_filename = $request->file($key)->getClientOriginalName(); $original_filename = $request->file($key)->getClientOriginalName();
$original_filename_arr = explode('.', $original_filename); $original_filename_arr = explode('.', $original_filename);
$file_ext = end($original_filename_arr); $file_ext = end($original_filename_arr);
$image = $imageCode.'-' . time() . '.' . $file_ext; $image = $imageCode . '-' . time() . '.' . $file_ext;
//Check if the directory already exists. //Check if the directory already exists.
$directoryName = './'.$folderName; $directoryName = './' . $folderName;
if(!is_dir($directoryName)){ if (!is_dir($directoryName)) {
//Directory does not exist, so lets create it. //Directory does not exist, so lets create it.
mkdir($directoryName, 0755); mkdir($directoryName, 0755);
} }
// Allow certain file formats // Allow certain file formats
// $allowTypes = array('jpg', 'png', 'jpeg', 'gif'); // $allowTypes = array('jpg', 'png', 'jpeg', 'gif');
// if (in_array(strtolower($file_ext), $allowTypes)) { // if (in_array(strtolower($file_ext), $allowTypes)) {
$compressedImage = $this->compressImage($request->file($key), './'.$folderName.'/' . $image, 70); $compressedImage = $this->compressImage($request->file($key), './' . $folderName . '/' . $image, 70);
if ($compressedImage) { if ($compressedImage) {
return $image; return $image;
} else { } else {
return $this->errorResponse(trans('errors.compression_failed')); return $this->errorResponse(trans('errors.compression_failed'));
} }
// } else { // } else {
// return $this->errorResponse('Sorry, only JPG, JPEG, PNG, & GIF files are allowed to upload.'); // return $this->errorResponse('Sorry, only JPG, JPEG, PNG, & GIF files are allowed to upload.');
// } // }
@ -173,6 +198,14 @@ class UserController extends Controller
} }
private function deleteImageFile($filename, $folderName)
{
// unlink(storage_path('./'.$folderName.'/' . $filename));
$path = './' . $folderName . '/' . $filename;
if (File::exists($path))
File::delete($path);
}
/* /*
* Custom function to compress image size and * Custom function to compress image size and
* upload to the server using PHP * upload to the server using PHP

View File

@ -31,6 +31,7 @@ use Illuminate\Database\Eloquent\Model;
* @property Carbon $date_modified * @property Carbon $date_modified
* @property Carbon $date_created * @property Carbon $date_created
* @property int $network_id * @property int $network_id
* @property int $group_id
* *
* @property Collection|Identification[] $identifications * @property Collection|Identification[] $identifications
* @property Collection|WalletsUser[] $wallets_users * @property Collection|WalletsUser[] $wallets_users
@ -45,7 +46,8 @@ class User extends Model
protected $casts = [ protected $casts = [
'solde' => 'float', 'solde' => 'float',
'active' => 'int', 'active' => 'int',
'network_id' => 'int' 'network_id' => 'int',
'group_id' => 'int'
]; ];
protected $dates = [ protected $dates = [

View File

@ -17,12 +17,18 @@ return [
'transaction_not_exist' => 'This transaction does not exist', 'transaction_not_exist' => 'This transaction does not exist',
'withdrawal_already_made' => 'Withdrawal already made', 'withdrawal_already_made' => 'Withdrawal already made',
'invalid_withdrawal_code' => 'Invalid withdrawal code', 'invalid_withdrawal_code' => 'Invalid withdrawal code',
'incorrect_withdrawal_amount'=> 'Incorrect withdrawal amount', 'incorrect_withdrawal_amount' => 'Incorrect withdrawal amount',
'operation_cannot_performed_in_country' => 'This operation cannot be performed in this country', 'operation_cannot_performed_in_country' => 'This operation cannot be performed in this country',
'withdrawal_network_unauthorized' => 'This withdrawal cannot be made in this network. 'withdrawal_network_unauthorized' => 'This withdrawal cannot be made in this network.
Paying network : :network :country', Paying network : :network :country',
'user_identification_required' => 'User identification is required to continue the operation', 'user_identification_required' => 'User identification is required to continue the operation',
'validation_user_identification_required' => 'Validation of user identification is required to continue the operation', 'validation_user_identification_required' => 'Validation of user identification is required to continue the operation',
'incorrect_net_amount' => 'Net amount is less than zero', 'incorrect_net_amount' => 'Net amount is less than zero',
'agent_unauthorized'=> 'This agent cannot make this withdrawal' 'agent_unauthorized' => 'This agent cannot make this withdrawal',
'sponsor_identification_required' => 'Sponsor :id identification is required to continue the operation',
'validation_sponsor_identification_required' => 'Validation of sponsor :id identification is required to continue the operation',
'not_group_sponsor' => 'You are not a sponsor of this group',
'group_already_activated' => 'This group is already activated',
'sponsor_belongs_to_group' => 'Sponsor :id already belongs to a group',
'treated_group_demand' => 'Group validation request already processed',
]; ];

View File

@ -131,7 +131,7 @@ Transaction information :
- User code : :sender_code - User code : :sender_code
- Card number : :cart_number - Card number : :cart_number
- Withdrawal code : :code', - Withdrawal code : :code',
'successful_agent_remove_cash'=>'Withdrawal of money from a geolocated agent 'successful_agent_remove_cash' => 'Withdrawal of money from a geolocated agent
Transaction information : Transaction information :
- Number : :id_transaction - Number : :id_transaction
- Country of departure : :init_country - Country of departure : :init_country
@ -141,4 +141,14 @@ Transaction information :
- Withdrawal amount : :amount - Withdrawal amount : :amount
- Withdrawal transaction number : :id_transaction_retrait - Withdrawal transaction number : :id_transaction_retrait
- Withdrawal code : :code', - Withdrawal code : :code',
'successful_user_group_created' => 'The group was created successfully. Awaiting validation from the 3 sponsors to activate it',
'successful_group_validation' => 'Group validation successful. Only :count validation remaining|Group validation successful. Only :count validations remaining',
'successful_identification_modification' => 'Successful identification modification',
'successful_identification_modification_message' => 'Hi :name,
Your new identification has been taken into account. Contact an iLink World agent with your ID to validate your identity.
Regards,
iLinkWorld team.',
]; ];

View File

@ -17,12 +17,18 @@ return [
'transaction_not_exist' => 'Cette transaction n\'existe pas', 'transaction_not_exist' => 'Cette transaction n\'existe pas',
'withdrawal_already_made' => 'Retrait déjà éffectué', 'withdrawal_already_made' => 'Retrait déjà éffectué',
'invalid_withdrawal_code' => 'Code de retrait invalide', 'invalid_withdrawal_code' => 'Code de retrait invalide',
'incorrect_withdrawal_amount'=> 'Montant de retrait incorrect', 'incorrect_withdrawal_amount' => 'Montant de retrait incorrect',
'operation_cannot_performed_in_country' => 'Cette operation ne peut pas etre effectuée dans ce pays', 'operation_cannot_performed_in_country' => 'Cette operation ne peut pas etre effectuée dans ce pays',
'withdrawal_network_unauthorized' => 'Ce retrait ne peut etre effectué dans ce reseau. 'withdrawal_network_unauthorized' => 'Ce retrait ne peut etre effectué dans ce reseau.
Réseau payeur : :network :country', Réseau payeur : :network :country',
'user_identification_required' => 'L\'identification de l\'utilisateur est requise pour continuer l\'operation', 'user_identification_required' => 'L\'identification de l\'utilisateur est requise pour continuer l\'operation',
'validation_user_identification_required' => 'La validation de l\'identification de l\'utilisateur est requise pour continuer l\'operation', 'validation_user_identification_required' => 'La validation de l\'identification de l\'utilisateur est requise pour continuer l\'operation',
'incorrect_net_amount' => 'Le montant net est inférieur à zéro', 'incorrect_net_amount' => 'Le montant net est inférieur à zéro',
'agent_unauthorized'=> 'Cet agent ne peut pas effectuer ce retrait', 'agent_unauthorized' => 'Cet agent ne peut pas effectuer ce retrait',
'sponsor_identification_required' => 'L\'identification du sponsor :id est requise pour continuer l\'operation',
'validation_sponsor_identification_required' => 'La validation de l\'identification du sponsor :id est requise pour continuer l\'operation',
'not_group_sponsor' => 'Vous n\'êtes pas un sponsor de ce groupe',
'group_already_activated' => 'Ce groupe est déjà activé',
'sponsor_belongs_to_group' => 'Sponsor :id appartient déjà à un groupe',
'treated_group_demand' => 'Demande de validation de groupe déjà traitée',
]; ];

View File

@ -131,7 +131,7 @@ Informations de la transaction :
- Code utilisateur : :sender_code - Code utilisateur : :sender_code
- Numero de la carte : :cart_number - Numero de la carte : :cart_number
- Code de retrait : :code', - Code de retrait : :code',
'successful_agent_remove_cash'=>'Retrait d\'argent chez un agent géolocalisé 'successful_agent_remove_cash' => 'Retrait d\'argent chez un agent géolocalisé
Informations de la transaction : Informations de la transaction :
- Numéro : :id_transaction - Numéro : :id_transaction
- Pays de départ : :init_country - Pays de départ : :init_country
@ -140,5 +140,15 @@ Informations de la transaction :
- Noms du destinataire : :receiver_name - Noms du destinataire : :receiver_name
- Montant de retrait : :amount - Montant de retrait : :amount
- Numero de transaction de retrait : :id_transaction_retrait - Numero de transaction de retrait : :id_transaction_retrait
- Code de retrait : :code' - Code de retrait : :code',
'successful_user_group_created' => 'Le groupe a été crée avec succes. En attente de validation des 3 sponsors pour l\'activer',
'successful_group_validation' => 'Validation du groupe réussie. Plus que :count validation restante|Validation du groupe réussie. Plus que :count validations restantes',
'successful_identification_modification' => 'Modification de l\'identification réussie',
'successful_identification_modification_message' => 'Salut :name,
Votre nouvelle identification a bien été bien 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é.
Cordialement,
Equipe iLinkWorld.',
]; ];

View File

@ -60,11 +60,17 @@ $router->group(['prefix' => '/wallets'] , function () use ($router){
}); });
// Idendification routes // Idendification routes
$router->group(['prefix' => '/identifications'] , function () use ($router){ $router->group(['prefix' => '/identifications'], function () use ($router) {
$router->post('','UserController@identification'); $router->post('', 'UserController@identification');
$router->post('{id_identification}','UserController@validateIdentification'); $router->put('', 'UserController@updateIdentification');
$router->get('{user_phone}','UserController@fetchIdentification'); $router->post('{id_identification}', 'UserController@validateIdentification');
$router->get('verify/{user_phone}','UserController@verifyIdentification'); $router->get('{user_phone}', 'UserController@fetchIdentification');
$router->get('verify/{user_phone}', 'UserController@verifyIdentification');
$router->post('rattach_card/{id_user}', 'UserController@rattachCard'); $router->post('rattach_card/{id_user}', 'UserController@rattachCard');
}); });
// Users groups routes
$router->group(['prefix' => '/groups'], function () use ($router) {
$router->post('', 'NanoCreditController@createGroup');
$router->put('', 'NanoCreditController@validateGroup');
});