From 953c154cab3240af49a97cd6ed6158367ee20832 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Thu, 19 May 2022 10:05:51 +0200 Subject: [PATCH 1/6] clean .env.example --- .env.example | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/.env.example b/.env.example index b7becba..12d4487 100644 --- a/.env.example +++ b/.env.example @@ -22,12 +22,6 @@ QUEUE_CONNECTION=sync SESSION_DRIVER=file SESSION_LIFETIME=120 -MEMCACHED_HOST=127.0.0.1 - -REDIS_HOST=127.0.0.1 -REDIS_PASSWORD=null -REDIS_PORT=6379 - MAIL_MAILER=smtp MAIL_HOST=mailhog MAIL_PORT=1025 @@ -37,16 +31,5 @@ MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS=null MAIL_FROM_NAME="${APP_NAME}" -AWS_ACCESS_KEY_ID= -AWS_SECRET_ACCESS_KEY= -AWS_DEFAULT_REGION=us-east-1 -AWS_BUCKET= -AWS_USE_PATH_STYLE_ENDPOINT=false - -PUSHER_APP_ID= -PUSHER_APP_KEY= -PUSHER_APP_SECRET= -PUSHER_APP_CLUSTER=mt1 - -MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" -MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" +MAIL_LIST_SERVICEWEB= +MAIL_LIST_CONTACTFORM= \ No newline at end of file From 0ef8dc5c1337d38adf201d8abdcec1edd6adbe48 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Thu, 19 May 2022 10:06:10 +0200 Subject: [PATCH 2/6] Fix readme.md --- README.md | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 19e088a..528136f 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,20 @@ # DOUX ## Installation - -* créer la BDD -* renseigner le .env -* composer install -* npm install -* npm run dev -* php artisan migrate:fresh --seed -* php artisan vendor:publish --provider="JoeDixon\Translation\TranslationServiceProvider" +``` +php artisan storage:link +cp .env.example .env +php artisan key:generate +composer install +php artisan vendor:publish --provider="JoeDixon\Translation\TranslationServiceProvider" +``` +- Créez la base de données +- Éditez le .env +``` +php artisan migrate --seed +``` +Pour le front : +``` +npm install +npm run prod +``` \ No newline at end of file From 5b85ba36df78b0a68362d7c31175a0bb4e6fb66f Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Thu, 19 May 2022 10:11:02 +0200 Subject: [PATCH 3/6] Fix font path --- resources/sass/frontend/_fonts.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/sass/frontend/_fonts.scss b/resources/sass/frontend/_fonts.scss index fd065dc..22d28cb 100644 --- a/resources/sass/frontend/_fonts.scss +++ b/resources/sass/frontend/_fonts.scss @@ -17,6 +17,6 @@ $font-path: "~@/fonts"; @font-face { font-family: "cocon-regular"; font-weight: normal; - src: url("~/assets/fonts/cocon/cocon-regular-webfont.woff2") format("woff2"), - url("~/assets/fonts/cocon/cocon-regular-webfont.woff") format("woff"); + src: url("#{$font-path}/cocon/cocon-regular-webfont.woff2") format("woff2"), + url("#{$font-path}/cocon/cocon-regular-webfont.woff") format("woff"); } From 69fdadd330d68c7a72e0230fbaea3eb2e31ef942 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Thu, 19 May 2022 10:22:56 +0200 Subject: [PATCH 4/6] Add Handler Exception package --- app/Exceptions/Handler.php | 49 +------------- app/Http/Controllers/HomeController.php | 1 + composer.json | 1 + composer.lock | 65 ++++++++++++++++++- config/exception-handler.php | 15 +++++ config/mail.php | 1 - .../views/emails/exception-plain.blade.php | 10 --- resources/views/emails/exception.blade.php | 16 ----- 8 files changed, 82 insertions(+), 76 deletions(-) create mode 100644 config/exception-handler.php delete mode 100644 resources/views/emails/exception-plain.blade.php delete mode 100644 resources/views/emails/exception.blade.php diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 600bf9e..f34f3c8 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -13,8 +13,7 @@ namespace App\Exceptions; -use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; -use Throwable; +use Kwaadpepper\ExceptionHandler\Exceptions\ExceptionHandler; /** * Undocumented class @@ -32,9 +31,7 @@ class Handler extends ExceptionHandler * * @var array */ - protected $dontReport = [ - // - ]; + protected $dontReport = []; /** * A list of the inputs that are never flashed for validation exceptions. @@ -46,46 +43,4 @@ class Handler extends ExceptionHandler 'password', 'password_confirmation', ]; - - /** - * Register the exception handling callbacks for the application. - * - * @return void - */ - public function register() - { - $this->reportable( - function (Throwable $e) { - try { - if (!config('app.debug')) { - if ($this->shouldntReport($e)) { - return false; - } - Mail::send( - [ - 'html' => 'emails.exception', - 'text' => 'emails.exception-plain' - ], - [ - 'exception' => $e, - 'appName' => config('app.name') - ], - function ($m) { - $m->to( - config('mail.contactsList.serviceweb'), - sprintf( - '%s Exception Handler', - config('app.name') - ) - //phpcs:ignore Generic.Files.LineLength.TooLong - )->subject('Need help !, an error occured in your application, please check Logs ASAP'); - } - ); - } - } finally { - return true; - } - } - ); - } } diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index e0e7dc8..671d030 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -9,6 +9,7 @@ use App\Models\Product; use App\Models\SeoDatum; use App\Models\Slide; use App\Models\Slider; +use Exception; use Illuminate\Support\Carbon; class HomeController extends Controller diff --git a/composer.json b/composer.json index df852f2..afe1f6a 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "guzzlehttp/guzzle": "^7.0.1", "joedixon/laravel-translation": "^1.1", "kwaadpepper/enum": "^2.1", + "kwaadpepper/exception-handler": "^0.0.8", "laravel/framework": "^8.65", "laravel/sanctum": "^2.11", "laravel/tinker": "^2.5", diff --git a/composer.lock b/composer.lock index 5ba1e10..375ed32 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9e5c04cb7369a0dfd36212e6ca2bf597", + "content-hash": "6d3d19ee0637b85edde0f49067b24cae", "packages": [ { "name": "asm89/stack-cors", @@ -1046,6 +1046,67 @@ }, "time": "2021-11-18T16:52:08+00:00" }, + { + "name": "kwaadpepper/exception-handler", + "version": "0.0.8", + "source": { + "type": "git", + "url": "https://github.com/Kwaadpepper/exception-handler.git", + "reference": "e8ba0e31ca2bf5971e459c623f0f5322a4c7a630" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Kwaadpepper/exception-handler/zipball/e8ba0e31ca2bf5971e459c623f0f5322a4c7a630", + "reference": "e8ba0e31ca2bf5971e459c623f0f5322a4c7a630", + "shasum": "" + }, + "require": { + "illuminate/support": "~7|~8|~9", + "laravel/framework": "~7|~8|~9" + }, + "require-dev": { + "orchestra/testbench": "^6.13", + "phpunit/phpunit": "~9.0", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Kwaadpepper\\ExceptionHandler\\ExceptionHandlerServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Kwaadpepper\\ExceptionHandler\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jérémy Munsch", + "email": "github@jeremydev.ovh", + "homepage": "https://jeremydev.ovh" + } + ], + "description": "Send emails when exceptions occurs", + "homepage": "https://github.com/kwaadpepper/exception-handler", + "keywords": [ + "email", + "exception", + "laravel", + "policies" + ], + "support": { + "issues": "https://github.com/Kwaadpepper/exception-handler/issues", + "source": "https://github.com/Kwaadpepper/exception-handler/tree/0.0.8" + }, + "time": "2022-02-03T15:23:22+00:00" + }, { "name": "laravel/framework", "version": "v8.83.4", @@ -8222,5 +8283,5 @@ "php": "^7.3|^8.0" }, "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.3.0" } diff --git a/config/exception-handler.php b/config/exception-handler.php new file mode 100644 index 0000000..367b948 --- /dev/null +++ b/config/exception-handler.php @@ -0,0 +1,15 @@ + !config('app.debug'), + + /** + * Put a developper secured mailbox in here + * so you can receive email if things go mad + */ + 'contactsList' => explode(",", env('MAIL_LIST_SERVICEWEB', 'equipe.web@ldc.fr')) +]; diff --git a/config/mail.php b/config/mail.php index e058936..768ed8c 100644 --- a/config/mail.php +++ b/config/mail.php @@ -98,7 +98,6 @@ return [ // Contacts List 'contactsList' => [ - 'serviceweb' => env('MAIL_LIST_SERVICEWEB', 'informatique.internet@ldc.fr'), 'contactform' => env('MAIL_LIST_CONTACTFORM', 'equipe.web@ldc.fr') ], diff --git a/resources/views/emails/exception-plain.blade.php b/resources/views/emails/exception-plain.blade.php deleted file mode 100644 index 0360447..0000000 --- a/resources/views/emails/exception-plain.blade.php +++ /dev/null @@ -1,10 +0,0 @@ -{{ $appName }} Exception Handler - -Une erreur est survenue sur le site {{ $appName }} -{{ $exception->getMessage() }} -date : {{ date('Y-m-d H:i:s') }} -code : {{$exception->getCode() }} -file : {{$exception->getFile() }} -line : {{$exception->getLine() }} - -Veuillez vérifier les logs pour en voir la trace. diff --git a/resources/views/emails/exception.blade.php b/resources/views/emails/exception.blade.php deleted file mode 100644 index 80a46d6..0000000 --- a/resources/views/emails/exception.blade.php +++ /dev/null @@ -1,16 +0,0 @@ - - - - {{ $appName }} Exception Handler - - - -

Une erreur est survenue sur le site {{ $appName }}

-

{{ $exception->getMessage() }}

-

date : {{ date('Y-m-d H:i:s') }}

-

code : {{$exception->getCode() }}

-

file : {{$exception->getFile() }}

-

line : {{$exception->getLine() }}

-

Veuillez vérifier les logs pour en voir la trace.

- - From 5acf77c872aaf0a012c0d3ff85cafe7b6202e476 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Thu, 19 May 2022 10:27:34 +0200 Subject: [PATCH 5/6] Clean Utils.php --- app/Lib/Utils.php | 261 ---------------------------------------------- 1 file changed, 261 deletions(-) diff --git a/app/Lib/Utils.php b/app/Lib/Utils.php index 2e4acd5..bd71817 100644 --- a/app/Lib/Utils.php +++ b/app/Lib/Utils.php @@ -2,20 +2,11 @@ namespace App\Lib; -use App\Models\Customers; use Exception; -use Illuminate\Http\Request; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\File; -use Illuminate\Support\Facades\Log; -use Illuminate\Support\Facades\Mail; -use Illuminate\Support\Facades\Route; use Illuminate\Support\Str; -use Illuminate\Validation\ValidationException; use SplFileInfo; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Throwable; - /** * Some utilities methods * @@ -24,145 +15,6 @@ use Throwable; // phpcs:disable Generic.Files.LineLength.TooLong class Utils { - /** - * Replace stange accents - * - * https://stackoverflow.com/questions/3371697/replacing-accented-characters-php - * @author Jérémy Munsch - * @param string $subject - * @return string - */ - public static function replaceSpecChar(string $subject): string - { - $char_map = array( - "ъ" => "-", "ь" => "-", "Ъ" => "-", "Ь" => "-", - "А" => "A", "Ă" => "A", "Ǎ" => "A", "Ą" => "A", "À" => "A", "Ã" => "A", "Á" => "A", "Æ" => "A", "Â" => "A", "Å" => "A", "Ǻ" => "A", "Ā" => "A", "א" => "A", - "Б" => "B", "ב" => "B", "Þ" => "B", - "Ĉ" => "C", "Ć" => "C", "Ç" => "C", "Ц" => "C", "צ" => "C", "Ċ" => "C", "Č" => "C", "©" => "C", "ץ" => "C", - "Д" => "D", "Ď" => "D", "Đ" => "D", "ד" => "D", "Ð" => "D", - "È" => "E", "Ę" => "E", "É" => "E", "Ë" => "E", "Ê" => "E", "Е" => "E", "Ē" => "E", "Ė" => "E", "Ě" => "E", "Ĕ" => "E", "Є" => "E", "Ə" => "E", "ע" => "E", - "Ф" => "F", "Ƒ" => "F", - "Ğ" => "G", "Ġ" => "G", "Ģ" => "G", "Ĝ" => "G", "Г" => "G", "ג" => "G", "Ґ" => "G", - "ח" => "H", "Ħ" => "H", "Х" => "H", "Ĥ" => "H", "ה" => "H", - "I" => "I", "Ï" => "I", "Î" => "I", "Í" => "I", "Ì" => "I", "Į" => "I", "Ĭ" => "I", "I" => "I", "И" => "I", "Ĩ" => "I", "Ǐ" => "I", "י" => "I", "Ї" => "I", "Ī" => "I", "І" => "I", - "Й" => "J", "Ĵ" => "J", - "ĸ" => "K", "כ" => "K", "Ķ" => "K", "К" => "K", "ך" => "K", - "Ł" => "L", "Ŀ" => "L", "Л" => "L", "Ļ" => "L", "Ĺ" => "L", "Ľ" => "L", "ל" => "L", - "מ" => "M", "М" => "M", "ם" => "M", - "Ñ" => "N", "Ń" => "N", "Н" => "N", "Ņ" => "N", "ן" => "N", "Ŋ" => "N", "נ" => "N", "ʼn" => "N", "Ň" => "N", - "Ø" => "O", "Ó" => "O", "Ò" => "O", "Ô" => "O", "Õ" => "O", "О" => "O", "Ő" => "O", "Ŏ" => "O", "Ō" => "O", "Ǿ" => "O", "Ǒ" => "O", "Ơ" => "O", - "פ" => "P", "ף" => "P", "П" => "P", - "ק" => "Q", - "Ŕ" => "R", "Ř" => "R", "Ŗ" => "R", "ר" => "R", "Р" => "R", "®" => "R", - "Ş" => "S", "Ś" => "S", "Ș" => "S", "Š" => "S", "С" => "S", "Ŝ" => "S", "ס" => "S", - "Т" => "T", "Ț" => "T", "ט" => "T", "Ŧ" => "T", "ת" => "T", "Ť" => "T", "Ţ" => "T", - "Ù" => "U", "Û" => "U", "Ú" => "U", "Ū" => "U", "У" => "U", "Ũ" => "U", "Ư" => "U", "Ǔ" => "U", "Ų" => "U", "Ŭ" => "U", "Ů" => "U", "Ű" => "U", "Ǖ" => "U", "Ǜ" => "U", "Ǚ" => "U", "Ǘ" => "U", - "В" => "V", "ו" => "V", - "Ý" => "Y", "Ы" => "Y", "Ŷ" => "Y", "Ÿ" => "Y", - "Ź" => "Z", "Ž" => "Z", "Ż" => "Z", "З" => "Z", "ז" => "Z", - "а" => "a", "ă" => "a", "ǎ" => "a", "ą" => "a", "à" => "a", "ã" => "a", "á" => "a", "æ" => "a", "â" => "a", "å" => "a", "ǻ" => "a", "ā" => "a", "א" => "a", - "б" => "b", "ב" => "b", "þ" => "b", - "ĉ" => "c", "ć" => "c", "ç" => "c", "ц" => "c", "צ" => "c", "ċ" => "c", "č" => "c", "©" => "c", "ץ" => "c", - "Ч" => "ch", "ч" => "ch", - "д" => "d", "ď" => "d", "đ" => "d", "ד" => "d", "ð" => "d", - "è" => "e", "ę" => "e", "é" => "e", "ë" => "e", "ê" => "e", "е" => "e", "ē" => "e", "ė" => "e", "ě" => "e", "ĕ" => "e", "є" => "e", "ə" => "e", "ע" => "e", - "ф" => "f", "ƒ" => "f", - "ğ" => "g", "ġ" => "g", "ģ" => "g", "ĝ" => "g", "г" => "g", "ג" => "g", "ґ" => "g", - "ח" => "h", "ħ" => "h", "х" => "h", "ĥ" => "h", "ה" => "h", - "i" => "i", "ï" => "i", "î" => "i", "í" => "i", "ì" => "i", "į" => "i", "ĭ" => "i", "ı" => "i", "и" => "i", "ĩ" => "i", "ǐ" => "i", "י" => "i", "ї" => "i", "ī" => "i", "і" => "i", - "й" => "j", "Й" => "j", "Ĵ" => "j", "ĵ" => "j", - "ĸ" => "k", "כ" => "k", "ķ" => "k", "к" => "k", "ך" => "k", - "ł" => "l", "ŀ" => "l", "л" => "l", "ļ" => "l", "ĺ" => "l", "ľ" => "l", "ל" => "l", - "מ" => "m", "м" => "m", "ם" => "m", - "ñ" => "n", "ń" => "n", "н" => "n", "ņ" => "n", "ן" => "n", "ŋ" => "n", "נ" => "n", "ʼn" => "n", "ň" => "n", - "ø" => "o", "ó" => "o", "ò" => "o", "ô" => "o", "õ" => "o", "о" => "o", "ő" => "o", "ŏ" => "o", "ō" => "o", "ǿ" => "o", "ǒ" => "o", "ơ" => "o", - "פ" => "p", "ף" => "p", "п" => "p", - "ק" => "q", - "ŕ" => "r", "ř" => "r", "ŗ" => "r", "ר" => "r", "р" => "r", "®" => "r", - "ş" => "s", "ś" => "s", "ș" => "s", "š" => "s", "с" => "s", "ŝ" => "s", "ס" => "s", - "т" => "t", "ț" => "t", "ט" => "t", "ŧ" => "t", "ת" => "t", "ť" => "t", "ţ" => "t", - "ù" => "u", "û" => "u", "ú" => "u", "ū" => "u", "у" => "u", "ũ" => "u", "ư" => "u", "ǔ" => "u", "ų" => "u", "ŭ" => "u", "ů" => "u", "ű" => "u", "ǖ" => "u", "ǜ" => "u", "ǚ" => "u", "ǘ" => "u", - "в" => "v", "ו" => "v", - "ý" => "y", "ы" => "y", "ŷ" => "y", "ÿ" => "y", - "ź" => "z", "ž" => "z", "ż" => "z", "з" => "z", "ז" => "z", "ſ" => "z", - "™" => "tm", - "@" => "at", - "Ä" => "ae", "Ǽ" => "ae", "ä" => "ae", "æ" => "ae", "ǽ" => "ae", - "ij" => "ij", "IJ" => "ij", - "я" => "ja", "Я" => "ja", - "Э" => "je", "э" => "je", - "ё" => "jo", "Ё" => "jo", - "ю" => "ju", "Ю" => "ju", - "œ" => "oe", "Œ" => "oe", "ö" => "oe", "Ö" => "oe", - "щ" => "sch", "Щ" => "sch", - "ш" => "sh", "Ш" => "sh", - "ß" => "ss", - "Ü" => "ue", - "Ж" => "zh", "ж" => "zh", - ); - return self::mbStrtr($subject, $char_map); - } - /** - * Multibyte strtr - * - * @param string $str - * @param string|array $from - * @param string|null $to - * @return void - */ - public static function mbStrtr($str, $from, $to = null): string - { - if (is_array($from)) { - $from = array_map('utf8_decode', $from); - $from = array_map('utf8_decode', array_flip($from)); - return utf8_encode(strtr(utf8_decode($str), array_flip($from))); - } - return utf8_encode(strtr(utf8_decode($str), utf8_decode($from), utf8_decode($to))); - } - /** - * Assert That no Back Office url is present on txt - * - * @param string $field - * @param string $text - * @return string - * @throws \Illuminate\Validation\ValidationException - */ - public static function assertNoInternalUrls(string $field, string $text): string - { - $routes = Route::getRoutes(); - // url replace and email replace - $text = preg_replace_callback( - '/(?P(?:http[s]?:\/\/.)?(?:www\.)?[-a-zA-Z0-9@%._\+~#=]{2,256}\.[a-z]{2,6}\b(?:[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*))/', - function ($matches) use ($routes, $field) { - $match = collect($matches)->first() ?? ''; - $url = $match; - try { - $request = Request::create($url); - // if a route is match then it do not throws exception - if ($routes->match($request)->getPrefix() === 'bo') { - // removes the matched url - throw ValidationException::withMessages([ - $field => trans($field) . " : Il est interdit de coller une url du Back Office Le Gaulois dans ce champ" - ]); - } - return $match; - } catch (NotFoundHttpException $e) { - return $match; - } - }, - $text - ); - return $text; - } - public static function dotStringToNestedArray($path, $value, $separator = '.') - { - $arr = $value; - $keys = array_reverse(explode($separator, $path)); - foreach ($keys as $key) { - $arr = [$key => $arr]; - } - return $arr; - } /** * Store an image for a model * if a string is passed then the store action is ignored and the strieng is returned @@ -212,117 +64,4 @@ class Utils } return $fullPath; } - /** - * Manually send an exception to team instead of going trough the error handler - * (requires package kwaadpepper/exception-handler) - * - * @param Throwable $e - * @return void - */ - public static function sendEmailErrorManually(Throwable $e) - { - Mail::send([ - 'html' => 'exception-handler::emails.exception', - 'text' => 'exception-handler::emails.exception-plain' - ], [ - 'appName' => config('app.name'), - 'code' => $e->getCode(), - 'line' => $e->getLine(), - 'ename' => \get_class($e), - 'emessage' => self::getAnonymizedMessage($e->getMessage()), - 'file' => str_replace(\realpath(\sprintf('%s/../', \app_path())), '', $e->getFile()), - 'stackTrace' => self::getAnonymizedStackTrace($e), - 'uri' => app()->runningInConsole() ? - 'CONSOLE' : ( - (request() and request()->fullUrl()) ? - request()->fullUrl() : 'none') - ], function ($m) { - /** @var \Illuminate\Mail\Message $m */ - $m->to( - config('mail.contactsList.serviceweb'), - sprintf('%s Exception Handler', config('app.name')) - )->subject('Need help !, an error occured in your application, please check Logs ASAP'); - }); - Log::alert(sprintf('Envoie d\'une erreur par mail : %s', json_encode($e))); - } - /** - * Generate an unique pseudo - * - * @param string $firstname - * @param string $lastname - * @param integer $i - * @return void - */ - public static function getUniquePseudo($firstname, $lastname, int $i = 0) - { - $pseudo = $firstname . '.' . substr($lastname, 0, 1); - if ($i > 0) { - $pseudo .= "-" . Str::random(8); - } - $customer = Customers::where('username', $pseudo)->first(); - if ($customer) { - return self::getUniquePseudo($firstname, $lastname, $i + 1); - } - return $pseudo; - } - /** - * Anonymize at least Sql queries - * - * @param string $message - * @return string - */ - private static function getAnonymizedMessage(string $message): string - { - $message = \preg_replace('/^(.*)( \(SQL:.*\))$/', '$1', $message) ?? $message; - return $message; - } - /** - * Anonymize stack trace - * - * @param \Exception $e - * @return string - */ - private static function getAnonymizedStackTrace(Throwable $e): string - { - $projectPath = \realpath(\sprintf('%s/../', \app_path())); - $traceStack = $e->getTrace(); - $traceStr = ''; - $maxStackStage = 0; - foreach ($traceStack as $stackStage => $stack) { - $maxStackStage = $stackStage; - $traceStr .= \sprintf( - '#%s %s(%d): ', - $stackStage, - str_replace($projectPath, '', $stack['file']), - $stack['line'] - ); - $traceStr .= "{$stack['class']}->{$stack['function']}("; - $traceArgs = ''; - if (isset($stack['args'])) { - $argsCount = count($stack['args']); - for ($i = 0; $i < $argsCount; $i++) { - $type = \gettype($stack['args'][$i]); - switch ($type) { - case 'object': - $traceArgs .= sprintf('Object(%s)', \get_class($stack['args'][$i])); - break; - case 'array': - $traceArgs .= sprintf('Array(%d)', \count($stack['args'][$i])); - break; - case 'string': - $traceArgs .= sprintf('String(%d)', \strlen($stack['args'][$i])); - break; - default: - $traceArgs .= \gettype($stack['args'][$i]); - } - $traceArgs .= ($i !== ($argsCount - 1) ? ',' : ''); - } - $traceStr .= $traceArgs; - } - $traceStr .= ")\n"; - } - $maxStackStage++; - $traceStr .= "#$maxStackStage {main}"; - return $traceStr; - } } From c39569e9cc8e609cb6a499b5bd2e3db48e5983d1 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Thu, 19 May 2022 11:32:54 +0200 Subject: [PATCH 6/6] Clean page contact --- app/Http/Controllers/ContactController.php | 20 +++------ app/Mail/SendContactMail.php | 14 +++---- config/mail.php | 2 +- resources/views/emails/send-contact.blade.php | 4 +- resources/views/front/contact.blade.php | 41 ++++++++----------- 5 files changed, 31 insertions(+), 50 deletions(-) diff --git a/app/Http/Controllers/ContactController.php b/app/Http/Controllers/ContactController.php index 4bbba97..e3f68f1 100644 --- a/app/Http/Controllers/ContactController.php +++ b/app/Http/Controllers/ContactController.php @@ -2,32 +2,22 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; use App\Http\Requests\ContactFormRequest; use App\Mail\SendContactMail; use Illuminate\Support\Facades\Mail; class ContactController extends Controller { - public function contact(Request $request) + public function contact() { - $status = $request->session()->get('status'); - - return view('front.contact', compact('status')); + return view('front.contact'); } public function contactSubmit(ContactFormRequest $request) { - $data = $request->all(); + Mail::to(config('mail.contactsList.contactform'))->send(new SendContactMail($request->validated())); - $toMail = config('mail.contactsList.contactform'); - if (!is_array($toMail)) { - $toMail = explode(',', $toMail); - } - //envoi du mail d'alerte - Mail::to($toMail) - ->send(new SendContactMail($request)); - - return back()->with('status', true); + $lang = session()->get('lang', config('app.locale')); + return redirect()->route(session()->get('lang', config('app.locale')) === 'fr' ? 'contact' : $lang . ".contact")->with('status', true); } } diff --git a/app/Mail/SendContactMail.php b/app/Mail/SendContactMail.php index ee2dac9..abfdc38 100644 --- a/app/Mail/SendContactMail.php +++ b/app/Mail/SendContactMail.php @@ -68,9 +68,9 @@ class SendContactMail extends Mailable "Contact - " . config('app.name', 'Doux') . " - " . - $data->topic + $data['topic'] ) - ->from($data->email) + ->from($data['email']) ->view('emails.send-contact', compact('data')); } @@ -82,20 +82,20 @@ class SendContactMail extends Mailable */ protected function joinFileIfProvided(): void { - if ($this->data->file) { + if (isset($this->data['file'])) { $this->joinedFileName = sprintf( 'Doux_MESSAGE-PJ-%s.%s', date("YmdHis"), - $this->data->file->extension() + $this->data['file']->extension() ); $this->attach( - $this->data->file, + $this->data['file'], [ 'as' => $this->joinedFileName, - 'mime' => $this->data->file->getMimeType() + 'mime' => $this->data['file']->getMimeType() ] ); - $this->data->file = $this->joinedFileName; + $this->data['file'] = $this->joinedFileName; } } } diff --git a/config/mail.php b/config/mail.php index 768ed8c..2524386 100644 --- a/config/mail.php +++ b/config/mail.php @@ -98,7 +98,7 @@ return [ // Contacts List 'contactsList' => [ - 'contactform' => env('MAIL_LIST_CONTACTFORM', 'equipe.web@ldc.fr') + 'contactform' => explode(",", env('MAIL_LIST_CONTACTFORM', 'equipe.web@ldc.fr')) ], /* diff --git a/resources/views/emails/send-contact.blade.php b/resources/views/emails/send-contact.blade.php index 6c55014..2ed1a32 100644 --- a/resources/views/emails/send-contact.blade.php +++ b/resources/views/emails/send-contact.blade.php @@ -154,8 +154,8 @@ -
Expediteur : {{ $data->civilite }} {{ $data->name }} {{ $data->lastname }}

Adresse : {{ $data->address }} {{ $data->postcode }} {{ $data->city }}

Téléphone : {{ $data->phone }}

Email : {{ $data->email }}

Pays : {{ $data->country }}

Département : {{ $data->departement }}

Sujet : {{ $data->topic }}

Produit : {{ $data->product_name }}

Code Barre : {{ $data->barcode }}

Lot : {{ $data->lot }}

Date limite de consommation : {{ $data->limit_date }}

Lieu d'achat : {{ $data->shop }}

Date de consommation : {{ $data->consumption_date }}

Message :

- {{ $data->message }} +
Expediteur : {{ $data['civilite'] }} {{ $data['name'] }} {{ $data['lastname'] }}

Adresse : {{ $data['address'] }} {{ $data['postcode'] }} {{ $data['city'] }}

Téléphone : {{ $data['phone'] }}

Email : {{ $data['email'] }}

Pays : {{ $data['country'] }}

Département : {{ $data['departement'] }}

Sujet : {{ $data['topic'] }}

Produit : {{ $data['product_name'] }}

Code Barre : {{ $data['barcode'] }}

Lot : {{ $data['lot'] }}

Date limite de consommation : {{ $data['limit_date'] }}

Lieu d'achat : {{ $data['shop'] }}

Date de consommation : {{ $data['consumption_date'] }}

Message :

+ {{ $data['message'] }}
diff --git a/resources/views/front/contact.blade.php b/resources/views/front/contact.blade.php index f12b858..a3a78e7 100644 --- a/resources/views/front/contact.blade.php +++ b/resources/views/front/contact.blade.php @@ -49,21 +49,12 @@

{!! __('Une question ? Une idée ? Un conseil ?
Des informations sur nos produits ?') !!}

{!! __('N’hésitez-pas à nous contacter en renseignant le formulaire ci-dessous.
Nous traiterons votre demande avec la plus grande attention dans les meilleurs délais.') !!}

- {{-- IF MAIL IS SENT --}} - @if(!is_null($status)) - @if(session()->get('status')) + @if(session()->has('status'))
{{ __('Votre message a bien été envoyé !') }}
{{ __('Nos services mettent tout en oeuvre pour y répondre au plus vite.') }}
- @else -
-
{{ __('Oups ! Une erreur s’est produite...') }}
-
{{ __('Votre message n’a pas pu être envoyé.
Nous en sommes désolés et vous prions
de bien vouloir réessayer plus tard.') }}
-
@endif - @endif -
@csrf @if ($errors->any()) @@ -75,11 +66,11 @@ {{ __('Vos coordonnées') }} : @@ -129,19 +120,19 @@