diff --git a/app/Http/Controllers/CommissionController.php b/app/Http/Controllers/CommissionController.php index 0d9d3ee..9634066 100755 --- a/app/Http/Controllers/CommissionController.php +++ b/app/Http/Controllers/CommissionController.php @@ -41,99 +41,4 @@ class CommissionController extends Controller } - public function sendMail(){ - - $recipients = ['dietchidjery@gmail.com']; - Mail::mailer('smtp')->raw('Message test.', function ($message) use ($recipients) { - $message->subject('This is a test to see if emails are working'); - $message->to($recipients); - }); - return $this->successResponse("mail envoye"); - } - - public function fileUpload(Request $request) { - -// if ($request->hasFile('image')) { -// $image = $request->file('image'); -// $name = time().'.'.$image->getClientOriginalExtension(); -// $destinationPath = storage_path('/storage'); -// $image->move($destinationPath, $name); -// -// -// return $this->successResponse("image envoye"); -// } - - $response = null; - $user = (object) ['image' => ""]; - - if ($request->hasFile('image')) { - $original_filename = $request->file('image')->getClientOriginalName(); - $original_filename_arr = explode('.', $original_filename); - $file_ext = end($original_filename_arr); - $destination_path = './upload/user/'; - $image = 'U-' . time() . '.' . $file_ext; -// File info -// $fileName = basename($_FILES["image"]["name"]); -// $imageUploadPath = $uploadPath . $fileName; -// $fileType = pathinfo($imageUploadPath, PATHINFO_EXTENSION); - - // Allow certain file formats - $allowTypes = array('jpg','png','jpeg','gif'); - if(in_array(strtolower($file_ext), $allowTypes)){ - // Image temp source -// $imageTemp = $_FILES["image"]["tmp_name"]; - - // Compress size and upload image - $compressedImage = $this->compressImage($request->file('image'), '/'. $image, 80); - if($compressedImage){ - return $this->successResponse("Image compressed successfully."); - }else{ - return $this->errorResponse( "Image compress failed!"); - } - }else{ - return $this->errorResponse('Sorry, only JPG, JPEG, PNG, & GIF files are allowed to upload.'); - } - -// if ($request->file('image')->move($destination_path, $image)) { -// $user->image = '/upload/user/' . $image; -// return $this->successResponse($user); -// } else { -// return $this->errorResponse('Cannot upload file'); -// } - } else { - return $this->errorResponse('File not found'); - } - - } - - /* - * Custom function to compress image size and - * upload to the server using PHP - */ - function compressImage($source, $destination, $quality) { - // Get image info - $imgInfo = getimagesize($source); - $mime = $imgInfo['mime']; - - // Create a new image from file - switch($mime){ - case 'image/jpeg': - $image = imagecreatefromjpeg($source); - break; - case 'image/png': - $image = imagecreatefrompng($source); - break; - case 'image/gif': - $image = imagecreatefromgif($source); - break; - default: - $image = imagecreatefromjpeg($source); - } - - // Save image - imagejpeg($image, $destination, $quality); - - // Return compressed image - return $destination; - } } diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 8feb7b4..93aaedc 100755 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -254,6 +254,6 @@ class TransactionController extends Controller $walletHyperviseur->save(); $transaction->save(); $transactionInverse->save(); - return $this->successResponse(trans('messages.canceled_credit_request')); + return $this->successResponse(trans('messages.canceled_transaction')); } } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php new file mode 100755 index 0000000..b9677cf --- /dev/null +++ b/app/Http/Controllers/UserController.php @@ -0,0 +1,160 @@ +validate($request, $identification->rules()); + + $dbIdentification = Identification::where('id_user', $request->id_user)->first(); + if($dbIdentification) + return $this->errorResponse(trans('errors.identification_carried_out')); + + $user = User::findOrFail($request->id_user); + $identification->fill($request->all()); + $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])); + return $this->successResponse(trans('messages.successful_identification')); + } + + public function validateIdentification(Request $request, $id_identification) + { + $identification = Identification::findOrFail($id_identification); + if ($identification->status == 1) { + return $this->errorResponse(trans('messages.identification_already_validated')); + } +// dd($request->allFiles()); + $this->validate($request, [ + 'id_network' => 'required|integer|min:0|not_in:0', + 'document_image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:6048', + 'user_image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:6048', + ]); + + $identification->idNetwork = $request->id_network; + $identification->document_image = $this->uploadImage($request,'document_image','D',"documents"); + $identification->user_image = $this->uploadImage($request,'user_image','U',"photos"); + $identification->status = 1; + + $identification->save(); + $this->sendMail($identification->user->email,trans('messages.validated_identification'),trans('messages.validated_identification_message')); + return $this->successResponse(trans('messages.validated_identification')); + } + + private function generateRandomString($length = 10) + { + $characters = '23456789abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + public function uploadImage(Request $request , $key , $imageCode, $folderName) + { + +// if ($request->hasFile('image')) { + $original_filename = $request->file($key)->getClientOriginalName(); + $original_filename_arr = explode('.', $original_filename); + $file_ext = end($original_filename_arr); + $image = $imageCode.'-' . time() . '.' . $file_ext; + + //Check if the directory already exists. + $directoryName = './'.$folderName; + if(!is_dir($directoryName)){ + //Directory does not exist, so lets create it. + mkdir($directoryName, 0755); + } + + // Allow certain file formats +// $allowTypes = array('jpg', 'png', 'jpeg', 'gif'); +// if (in_array(strtolower($file_ext), $allowTypes)) { + + $compressedImage = $this->compressImage($request->file($key), './'.$folderName.'/' . $image, 70); + if ($compressedImage) { + return $image; + } else { + return $this->errorResponse(trans('errors.compression_failed')); + } +// } else { +// return $this->errorResponse('Sorry, only JPG, JPEG, PNG, & GIF files are allowed to upload.'); +// } + +// } else { +// return $this->errorResponse('File not found'); +// } + + } + + /* + * Custom function to compress image size and + * upload to the server using PHP + */ + private function compressImage($source, $destination, $quality) + { + // Get image info + $imgInfo = getimagesize($source); + $mime = $imgInfo['mime']; + + // Create a new image from file + switch ($mime) { + case 'image/jpeg': + $image = imagecreatefromjpeg($source); + break; + case 'image/png': + $image = imagecreatefrompng($source); + break; + case 'image/gif': + $image = imagecreatefromgif($source); + break; + default: + $image = imagecreatefromjpeg($source); + } + + // Save image + imagejpeg($image, $destination, $quality); + + // Return compressed image + return $destination; + } + + private function sendMail($email , $title , $messageText){ + + $recipients = [$email]; + Mail::mailer('smtp')->raw($messageText, function ($message) use ($recipients,$title) { + $message->subject($title); + $message->to($recipients); + }); +// return $this->successResponse("mail envoye"); + } +} diff --git a/app/Http/Controllers/WalletController.php b/app/Http/Controllers/WalletController.php index e8c1471..68f7dbe 100755 --- a/app/Http/Controllers/WalletController.php +++ b/app/Http/Controllers/WalletController.php @@ -99,7 +99,7 @@ class WalletController extends Controller // Wallets users iLink public function showWalletUser($id_user){ $wallet = collect(DB::select('SELECT wu.* , c.name as country , i.user_code , n.name as network from wallets_users wu - INNER JOIN identifications i ON i.idUser = wu.idUser INNER JOIN countries c ON i.country = c.id INNER JOIN networks n ON i.idNetwork = n.id + INNER JOIN identifications i ON i.idUser = wu.idUser INNER JOIN networks n ON i.idNetwork = n.id INNER JOIN countries c ON n.country_id = c.id WHERE wu.idUser = :idUser',['idUser' => $id_user]))->first(); if($wallet) return $this->successResponse($wallet); diff --git a/app/Models/Country.php b/app/Models/Country.php new file mode 100755 index 0000000..c42327b --- /dev/null +++ b/app/Models/Country.php @@ -0,0 +1,69 @@ + 'float', + 'latitude' => 'float', + 'idCurrency' => 'int' + ]; + + protected $fillable = [ + 'code_dial', + 'name', + 'code_country', + 'longitude', + 'latitude', + 'idCurrency' + ]; + + public function currency() + { + return $this->belongsTo(Currency::class, 'idCurrency'); + } + + public function admins() + { + return $this->hasMany(Admin::class, 'country'); + } + + public function config_games() + { + return $this->hasMany(ConfigGame::class, 'id_pays'); + } + + public function identifications() + { + return $this->hasMany(Identification::class, 'country'); + } +} diff --git a/app/Models/Identification.php b/app/Models/Identification.php index 3eeed44..bc7edd8 100644 --- a/app/Models/Identification.php +++ b/app/Models/Identification.php @@ -11,23 +11,26 @@ use Illuminate\Database\Eloquent\Model; /** * Class Identification - * + * * @property int $id * @property string $firstname * @property string $lastname * @property Carbon $birth_date * @property string $town - * @property int $country + * @property string $country * @property string $identity_document * @property string $id_identity_document - * @property Carbon $validity_date_document - * @property int $idUser + * @property Carbon $expiry_date_document + * @property int $id_user * @property int $status * @property Carbon $createdAt * @property string $user_image * @property string $document_image - * + * @property string $user_code + * @property int $idNetwork + * * @property User $user + * @property Network $network * * @package App\Models */ @@ -37,14 +40,14 @@ class Identification extends Model public $timestamps = false; protected $casts = [ - 'country' => 'int', - 'idUser' => 'int', - 'status' => 'int' + 'id_user' => 'int', + 'status' => 'int', + 'idNetwork' => 'int' ]; protected $dates = [ 'birth_date', - 'validity_date_document', + 'expiry_date_document', 'createdAt' ]; @@ -53,24 +56,41 @@ class Identification extends Model 'lastname', 'birth_date', 'town', - 'country', + 'country', 'identity_document', 'id_identity_document', - 'validity_date_document', - 'idUser', + 'expiry_date_document', + 'id_user', 'status', 'createdAt', 'user_image', - 'document_image' + 'document_image', + 'user_code', + 'idNetwork' ]; - public function country() - { - return $this->belongsTo(Country::class, 'country'); - } public function user() { return $this->belongsTo(User::class, 'idUser'); } + + public function network() + { + return $this->belongsTo(Network::class, 'idNetwork'); + } + + public function rules() + { + return [ + 'lastname'=>'required', + 'birth_date'=> 'required|date|before_or_equal:today', + 'town'=>'required', + 'country'=> 'required', + 'identity_document'=> 'required', + 'id_identity_document'=> 'required', + 'expiry_date_document'=>'required|date|after_or_equal:today', + 'id_user' => 'required|integer|min:0|not_in:0' + ]; + } } diff --git a/app/Models/Network.php b/app/Models/Network.php new file mode 100755 index 0000000..548acb3 --- /dev/null +++ b/app/Models/Network.php @@ -0,0 +1,59 @@ + 'int', + 'id_networkAgent' => 'int', + 'status' => 'int' + ]; + + protected $fillable = [ + 'country_id', + 'name', + 'id_networkAgent', + 'status' + ]; + + public function config_wallets() + { + return $this->hasMany(ConfigWallet::class, 'id_network'); + } + + public function identifications() + { + return $this->hasMany(Identification::class, 'idNetwork'); + } + + public function wallets_password() + { + return $this->hasOne(WalletsPassword::class); + } +} diff --git a/app/Models/WalletTransaction.php b/app/Models/WalletTransaction.php index cce17a4..7393499 100755 --- a/app/Models/WalletTransaction.php +++ b/app/Models/WalletTransaction.php @@ -112,7 +112,7 @@ class WalletTransaction extends Model 'cvv'=>'required_if:facade,front|size:3', 'expiration_date'=>'required_if:facade,front|date_format:m/y|after_or_equal:today', 'type' =>'required|in:credit,debit', - 'id_wallet' => 'required|integer|min:0' + 'id_wallet' => 'required|integer|min:0|not_in:0' ]; } } diff --git a/resources/lang/en/errors.php b/resources/lang/en/errors.php index ed6e509..9eca328 100755 --- a/resources/lang/en/errors.php +++ b/resources/lang/en/errors.php @@ -3,5 +3,7 @@ return [ 'model_not_found' => 'Does not exist any instance of :model with given id', 'unexpected_error'=> 'Unexpected error. Try later', 'service_unavailable' => 'Service unavailable', - 'invalid_cvv' => 'Invalid CVV' + 'invalid_cvv' => 'Invalid CVV', + 'compression_failed' => 'Image compression failed!', + 'identification_carried_out' => 'Identification already carried out' ]; diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index 6925301..e66aa45 100755 --- a/resources/lang/en/messages.php +++ b/resources/lang/en/messages.php @@ -6,5 +6,23 @@ return [ 'princ_balance_inf_to_demand_amount' => 'Your main balance is less than the amount of the request, do you want to change the amount ?', 'new_wallet_added' => 'New wallet added', 'success_treated_demand' => 'Request successfully processed', - 'canceled_credit_request' => 'Canceled credit request' + 'canceled_credit_request' => 'Canceled credit request', + 'canceled_transaction' => 'Canceled transaction', + 'successful_identification'=>'Successful identification', + 'validated_identification'=>'Validated identification', + 'identification_already_validated'=>'Identification already validated', + '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! + +You can now use the services of iLink World. +Welcome to the iLink World family !!! + +Regards, +ILinkWorld team.' ]; diff --git a/resources/lang/fr/errors.php b/resources/lang/fr/errors.php index 895af46..8d83fd7 100755 --- a/resources/lang/fr/errors.php +++ b/resources/lang/fr/errors.php @@ -3,5 +3,7 @@ return [ 'model_not_found' => 'Il n\'existe aucune instance de :model avec l\'id donné', 'unexpected_error'=> 'Erreur inattendue. Essayer plus tard', 'service_unavailable' => 'Service non disponible', - 'invalid_cvv' => 'CVV invalide' + 'invalid_cvv' => 'CVV invalide', + 'compression_failed' => 'Échec de la compression d\'image', + 'identification_carried_out' => 'Identification déjà éffectuée' ]; diff --git a/resources/lang/fr/messages.php b/resources/lang/fr/messages.php index b909d90..9d503ec 100755 --- a/resources/lang/fr/messages.php +++ b/resources/lang/fr/messages.php @@ -6,5 +6,23 @@ return [ 'princ_balance_inf_to_demand_amount' => 'Votre solde principal est inférieur au montant de la demande, voulez vous modifier le montant ?', 'new_wallet_added' => 'Nouveau wallet ajouté', 'success_treated_demand' => 'Demande traitée avec succès', - 'canceled_credit_request' => 'Demande de crédit annulée' + 'canceled_credit_request' => 'Demande de crédit annulée', + 'canceled_transaction' => 'Transaction annulée', + 'successful_identification' => 'Identification réussie', + 'validated_identification' => 'Identification validée', + 'identification_already_validated' => 'Identification deja validée', + '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 ! + +Vous pouvez desormais utiliser les services de iLink World. +Bienvenue dans la famille iLink World !!! + +Cordialement, +Equipe iLinkWorld.' ]; diff --git a/routes/web.php b/routes/web.php index 9c7bbf6..4b161ed 100755 --- a/routes/web.php +++ b/routes/web.php @@ -43,5 +43,9 @@ $router->group(['prefix' => '/wallets'] , function () use ($router){ }); }); -$router->get('mail','CommissionController@sendMail'); -$router->post('file','CommissionController@fileUpload'); +// Idendification routes +$router->group(['prefix' => '/identifications'] , function () use ($router){ + $router->post('','UserController@identification'); + $router->post('{id_identification}','UserController@validateIdentification'); +}); +