diff --git a/app/Http/Controllers/Fo/Auth/RegisterController.php b/app/Http/Controllers/Fo/Auth/RegisterController.php index b2eafad..6386028 100644 --- a/app/Http/Controllers/Fo/Auth/RegisterController.php +++ b/app/Http/Controllers/Fo/Auth/RegisterController.php @@ -15,11 +15,10 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Validator; -use Illuminate\Validation\ValidationException; +use Illuminate\Validation\ValidationException as IlluminateValidationException; use LDC\LDCCRM\Enums\ApiError; -use LDC\LDCCRM\Enums\Country; use LDC\LDCCRM\Exceptions\ApiErrorException; -use LDC\LDCCRM\Exceptions\ValidationException as ExceptionsValidationException; +use LDC\LDCCRM\Exceptions\ValidationException as CrmValidationException; use LDC\LDCCRM\Models\Customer as CrmCustomer; class RegisterController extends Controller @@ -53,7 +52,7 @@ class RegisterController extends Controller */ public function showRegistrationForm() { - $staticPageModel = StaticPage::query()->where('type', StaticPageType::klub_register)->first(); + $staticPageModel = StaticPage::query()->where('type', StaticPageType::klub_register)->firstOrFail(); return view('fo.auth.register', compact('staticPageModel')); } @@ -62,34 +61,20 @@ class RegisterController extends Controller * * @param array $data * @return \Illuminate\Contracts\Validation\Validator - * @throws \Illuminate\Validation\ValidationException If data is incorrect. + * @throws IlluminateValidationException If data is incorrect. + * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass */ protected function validator(array $data): ValidationValidator { - $data['ok_cgv'] = \request()->boolean('ok_cgv'); - $data['phone'] = $data['phone'] ?? null; - $data['opt_in'] = ($data['opt_in'] ?? false) ? true : false; - - $request = new CreateAccountRequest(); - - $validateData = Validator::make( - $data, + // phpcs:enable + $request = CreateAccountRequest::capture(); + $request->prepareForValidation(); + return Validator::make( + $request->validationData(), $request->rules(), $request->messages(), $request->attributes() ); - - if ($validateData) { - return $validateData; - } else { - try { - (new CrmCustomer())->fill($this->getOnlyCrmData($data)); - } catch (ExceptionsValidationException $e) { - throw ValidationException::withMessages([ - 'error' => $e->getMessage() - ]); - } - } } /** @@ -97,22 +82,29 @@ class RegisterController extends Controller * * @param array $data * @return \App\Models\Customer - * @throws \Illuminate\Validation\ValidationException If there are validation errors. + * @throws IlluminateValidationException If there are validation errors. * @throws \RuntimeException On unhandled api Error. */ protected function create(array $data): Customer { - $data['country'] = Country::france(); - $data['ok_cgv'] = \request()->boolean('ok_cgv'); - $data['phone'] = $data['phone'] ?? null; - $data['opt_in'] = ($data['opt_in'] ?? false) ? true : false; + $data['ok_cgv'] = \request()->boolean('ok_cgv'); + $data['opt_in'] = \request()->boolean('opt_in'); + $data['phone'] = Arr::get($data, 'phone'); + // * This field is not standard in crm + $data['postcode'] = Arr::get($data, 'postal_code'); + Arr::forget($data, 'postal_code'); try { return DB::transaction(function () use ($data) { - $crmCustomer = new CrmCustomer($this->getOnlyCrmData($data)); + $crmCustomer = new CrmCustomer(Arr::only( + $data, + [ + 'firstname', 'lastname', 'birth_date', 'address', + 'address2', 'postcode', 'country', 'city', 'phone', + 'email', 'password', 'opt_in', + ] + )); - // * Country Is forced to france - $crmCustomer->country = Country::france(); $crmCustomer->save(); // * Enregistrement du Hashcode @@ -133,20 +125,20 @@ class RegisterController extends Controller }); } catch (ApiErrorException $e) { if ($e->getApiError()->equals(ApiError::customerExists())) { - throw ValidationException::withMessages([ - 'error' => 'Un compte est déjà associé à cette adresse email.' + throw IlluminateValidationException::withMessages([ + 'error' => trans('Un compte est déjà associé à cette adresse email.') ]); } if ($e->getApiError()->equals(ApiError::validationFailed())) { - throw ValidationException::withMessages([ + throw IlluminateValidationException::withMessages([ 'error' => $e->getMessage() ]); } report($e); Log::error(__CLASS__ . '::create reached end of possibilities.'); throw new \RuntimeException(__CLASS__ . '::create reached end of possibilities.'); - } catch (ExceptionsValidationException $e) { - throw ValidationException::withMessages([ + } catch (CrmValidationException $e) { + throw IlluminateValidationException::withMessages([ 'error' => $e->getMessage() ]); } //end try @@ -161,30 +153,4 @@ class RegisterController extends Controller { return $this->authLoggedRedirectPath(); } - - /** - * Get only data used in crm - * - * @param array $data - * @return array - */ - private function getOnlyCrmData(array $data): array - { - return \array_intersect_key( - $data, - [ - 'firstname' => '', - 'lastname' => '', - 'birth_date' => '', - 'address' => '', - 'postcode' => '', - 'country' => '', - 'city' => '', - 'phone' => '', - 'email' => '', - 'password' => '', - 'opt_in' => '', - ] - ); - } } diff --git a/app/Http/Controllers/Fo/Auth/ResetPasswordController.php b/app/Http/Controllers/Fo/Auth/ResetPasswordController.php index 231fd8c..da89ff5 100644 --- a/app/Http/Controllers/Fo/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Fo/Auth/ResetPasswordController.php @@ -68,7 +68,7 @@ class ResetPasswordController extends Controller */ protected function resetPassword(mixed $customer, mixed $password): void { - /** @var \App\Models\Customer\Customer $user */ + /** @var \App\Models\Customer $customer */ /** @var string $password */ /** @var \LDC\LDCCRM\CrmApiV2 */ @@ -77,7 +77,7 @@ class ResetPasswordController extends Controller try { if (!($crmCustomer = $crm->getCustomer($customer->hashcode))) { throw ValidationException::withMessages([ - 'error' => 'Changement impossible, compte inexistant.' + 'error' => trans('Changement impossible, compte inexistant.') ]); } $crmCustomer->password = $password; @@ -85,11 +85,11 @@ class ResetPasswordController extends Controller } catch (\TypeError | CrmException | ApiErrorException $e) { report($e); throw ValidationException::withMessages([ - 'error' => 'Une erreur est survenue, merci de réessayer ultérieurement.' + 'error' => trans('Une erreur est survenue, merci de réessayer ultérieurement.') ]); } catch (ExceptionsValidationException $e) { throw ValidationException::withMessages([ - 'error' => $e->getMessage() + 'password' => $e->getMessage() ]); } diff --git a/app/Http/Controllers/Fo/HomeController.php b/app/Http/Controllers/Fo/HomeController.php index 9533083..65f9e6e 100644 --- a/app/Http/Controllers/Fo/HomeController.php +++ b/app/Http/Controllers/Fo/HomeController.php @@ -18,10 +18,13 @@ class HomeController extends Controller */ public function index(): \Illuminate\Contracts\View\View { - $rangeModels = Range::all(); - $klubBloc = KlubBloc::first(); + $rangeModels = Range::query()->limit(3)->inRandomOrder()->get(); $newsModels = News::query()->where('published', true)->orderBy('created_at', 'desc')->limit(6)->get(); - $staticPageModel = StaticPage::query()->where('type', StaticPageType::home)->first(); + $staticPageModel = StaticPage::query()->where('type', StaticPageType::home)->firstOrFail(); + $klubBloc = KlubBloc::first(); + + \throw_if(empty($klubBloc), 'empty klubBloc'); + return view('fo.pages.home', compact('staticPageModel', 'rangeModels', 'klubBloc', 'newsModels')); } } diff --git a/app/Http/Controllers/Fo/Klub/MesBrController.php b/app/Http/Controllers/Fo/Klub/MesBrController.php index 735d60d..5d6adcd 100644 --- a/app/Http/Controllers/Fo/Klub/MesBrController.php +++ b/app/Http/Controllers/Fo/Klub/MesBrController.php @@ -4,9 +4,15 @@ namespace App\Http\Controllers\Fo\Klub; use App\Http\Controllers\Controller; use App\Http\Requests\Fo\MesBr\PrintCouponsRequest; +use App\Models\Customer; use Illuminate\Contracts\View\View; +use Illuminate\Http\Exceptions\HttpResponseException; use Illuminate\Support\Arr; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; +use LDC\LDCCRM\Enums\ApiError; +use LDC\LDCCRM\Exceptions\ApiErrorException; +use LDC\LDCCRM\Exceptions\CrmException; use Symfony\Component\HttpFoundation\StreamedResponse; class MesBrController extends Controller @@ -68,33 +74,81 @@ class MesBrController extends Controller * @param \App\Models\Customer $customer * @param array $coupons * @return string|null + * @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh */ - private function fetchBrPdfFromMesBr(\App\Models\Customer $customer, array $coupons): string|null + private function fetchBrPdfFromMesBr(Customer $customer, array $coupons): string|null { - /** @var \LDCWEB\MesBR */ - $mesBr = app('mesbr'); - - $message = null; + // phpcs:enable + // * Phase - 1 Recupération des informations CRM + /** @var \LDC\LDCCRM\Models\Customer*/ + $crmUser = $this->fetchCrmCustomer($customer); + // * Phase - 2 Mise à jour du coupon dans MesBr try { - $res = $mesBr->printCoupons($customer->hashcode, $coupons); - if (!$res) { - $message = "ERROR MesBR API : printCoupons on api failed {$customer->hashcode}"; - } elseif (Arr::get((array)$res, 'status') === 'KO') { - $message = Arr::get( - (array)$res, - 'message', - "ERROR MesBR API : printCoupons on api failed (no message) {$customer->hashcode}" - ); + /** @var \LDC\MESBR\MesBr */ + $mesBr = app('mesBrAPI'); + + // * MaJ Customer + /** @var integer */ + retry(3, function () use ($mesBr, $crmUser) { + /** + * Parce que MesBr n'est pas fiable il faut retenter pour avoir + * l'id client, des fois cet id sera dans hashcode... + * + * Id est necessaire pour update panier.. + */ + $result = $mesBr->updateCustomer($crmUser->hashcode, $crmUser->email, $crmUser->country); + if (optional($result)->status !== "OK") { + throw new \RuntimeException( + \sprintf( + 'MESBR : Une erreur est survenue. Code : %s Message : %s', + $result->code ?? 'Undefined', + $result->message ?? 'Undefined' + ) + ); + } + /** @var object|null */ + $crm_customer = optional($result)->customer; + if (empty(optional($crm_customer)->id)) { + throw new \RuntimeException( + 'MESBR : Une erreur est survenue. Update Customer n\'as pas retourné le customer id' + ); + } + + return intval($crm_customer->id); + }, 100); + + // * Maj Panier + $result = $mesBr->printCoupons($crmUser->hashcode, $coupons); + $result = \is_object($result) ? (array)$result : $result; + + if (Arr::get($result, 'status') !== "OK") { + report(new \RuntimeException( + \sprintf( + 'MESBR : Une erreur est survenue. Code : %s Message : %s', + Arr::get($result, 'code') ?? 'Undefined', + Arr::get($result, 'message') ?? 'Undefined', + ) + )); + return null; } - if ($message === null) { - return \base64_decode(strval(optional($res)->pdf)); + // * La réponse est conforme ? + $needed_fields = ['pdf']; + if (!Arr::has($result, $needed_fields)) { + report(new \RuntimeException(sprintf( + 'MESBR : Il manques des champs dans la réponse, attendu => %s, donné => %s', + json_encode($needed_fields), + json_encode($result), + ))); + return null; } - report(new \RuntimeException($message)); - return null; - } catch (\Exception $e) { + + // * Tout est OK + return \base64_decode(Arr::get($result, 'pdf')) ?: null; + } catch (\RuntimeException $e) { report($e); + // * Retenter ? return null; } //end try } @@ -130,8 +184,8 @@ class MesBrController extends Controller return null; } - /** @var \LDCWEB\MesBR */ - $mesBr = app('mesbr'); + /** @var \LDC\MESBR\MesBR */ + $mesBr = app('mesBrAPI'); $message = null; @@ -171,8 +225,8 @@ class MesBrController extends Controller private function createOrUpdateMesBrCustomer(\LDC\LDCCRM\Models\Customer $customer): bool { // * Ajout du customer sur mes BR - /** @var \LDCWEB\MesBR */ - $mesBr = app('mesbr'); + /** @var \LDC\MESBR\MesBR */ + $mesBr = app('mesBrAPI'); $message = null; @@ -205,6 +259,49 @@ class MesBrController extends Controller } //end try } + /** + * Fetch Crm Customer + * + * @param \App\Models\Customer $customer + * @return \LDC\LDCCRM\Models\Customer + * @throws \Illuminate\Http\Exceptions\HttpResponseException In case of failure or customer not activated. + */ + private function fetchCrmCustomer(Customer $customer): \LDC\LDCCRM\Models\Customer + { + try { + $crmUser = $customer->api_data; + + // ? Le compte est vérifié ? + if (!$crmUser->status) { + // * Doit avoir un compte vérifié pour imprimer. + response()->redirectToRoute('fo.verification.notice') + ->with('error', trans('Votre compte doit être activé')) + ->throwResponse(); + } + return $crmUser; + } catch (ApiErrorException $e) { + // * Customer is not found. + if ($e->getApiError()->equals(ApiError::modelNotFound())) { + // * Déconnexion immédiate et retour maison. + auth('frontend')->logout(); + response()->redirectToRoute('fo.homepage') + ->with('error', trans('Une erreur est survenue, compte introuvable.')) + ->throwResponse(); + } + report($e); + Log::error('Unhandled response ' . $e->getApiError()->label); + // * Retenter ? + back()->with('error', trans('Une erreur est survenue, veuillez réssayer.'))->throwResponse(); + } catch (HttpResponseException $e) { + // * continue this + throw $e; + } catch (CrmException | \Exception $e) { + report($e); + // * Retenter ? + back()->with('error', trans('Une erreur est survenue, veuillez réssayer.'))->throwResponse(); + } //end try + } + // * STATIC Fetch BR /** @@ -216,8 +313,8 @@ class MesBrController extends Controller */ public static function getStaticBr(): object|null { - /** @var \LDCWEB\MesBR */ - $mesBr = app('mesbr'); + /** @var \LDC\MESBR\MesBR */ + $mesBr = app('mesBrAPI'); $message = null; diff --git a/app/Http/Controllers/Fo/StaticPageController.php b/app/Http/Controllers/Fo/StaticPageController.php index c9fcccd..b2a6a1e 100644 --- a/app/Http/Controllers/Fo/StaticPageController.php +++ b/app/Http/Controllers/Fo/StaticPageController.php @@ -47,7 +47,7 @@ class StaticPageController extends Controller ->orderBy('created_at', 'desc') ->limit(6) ->get(); - $rangeModels = Range::all(); + $rangeModels = Range::query()->limit(3)->inRandomOrder()->get(); $milestoneModels = HistoricalMilestone::orderBy('year', 'asc')->where('published', true)->get(); $staticPageModel = StaticPage::query()->where('type', StaticPageType::history)->first(); return view('fo.pages.history', compact('staticPageModel', 'newsModels', 'rangeModels', 'milestoneModels')); diff --git a/app/Http/Middleware/CrmMiddlewareQuestions.php b/app/Http/Middleware/CrmMiddlewareQuestions.php index 992a11c..2096021 100644 --- a/app/Http/Middleware/CrmMiddlewareQuestions.php +++ b/app/Http/Middleware/CrmMiddlewareQuestions.php @@ -26,8 +26,7 @@ class CrmMiddlewareQuestions $user = \auth('frontend')->user() and $user->last_connection !== null ) { - /** @var \LDC\LDCCRM\Models\Customer */ - $crmCustomer = $user->apiData; + $crmCustomer = $user->api_data; $questions = Customer::cacheCrm( $user->hashcode, 'questions', diff --git a/app/Http/Middleware/SecureHeaders.php b/app/Http/Middleware/SecureHeaders.php index c5e47cf..8360f99 100644 --- a/app/Http/Middleware/SecureHeaders.php +++ b/app/Http/Middleware/SecureHeaders.php @@ -53,14 +53,21 @@ class SecureHeaders "default-src 'none';", "manifest-src 'self';", // * CKEDITOR Specific https://ckeditor.com/docs/ckeditor5/latest/installation/advanced/csp.html - "connect-src 'self' " . implode(' ', [ + "connect-src 'self' blob: " . implode(' ', [ // * VITE DEV config('app.debug') ? "wss://{$host}:4443" : '', config('app.debug') ? "https://{$host}:4443" : '', 'https://yl.s-web.fr' ]) . ';', - "img-src * data: blob:;", - 'frame-src ' . implode(' ', [ + "img-src 'self' data: blob: " . implode(' ', [ + // * VITE DEV + config('app.debug') ? "https://{$host}:4443" : '', + // * MESBR + 'https://dev.mesbr.eu', + 'https://www.mesbr.eu' + ]) . ';', + "object-src 'self' " . implode(' ', []) . ';', + "frame-src 'self' " . implode(' ', [ 'https://www.google.com/recaptcha/', 'https://recaptcha.google.com/recaptcha/', 'https://www.google.com/maps/' diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php index 74bd812..608f711 100644 --- a/app/Http/Middleware/TrustProxies.php +++ b/app/Http/Middleware/TrustProxies.php @@ -10,6 +10,8 @@ class TrustProxies extends Middleware /** * The trusted proxies for this application. * + * ! Added * as tmp Fix for #13 + * * @var array|string|null */ protected $proxies = '*'; diff --git a/app/Http/Requests/Bo/StaticPages/UpdateStaticPageRequest.php b/app/Http/Requests/Bo/StaticPages/UpdateStaticPageRequest.php index f648d40..7c7b193 100644 --- a/app/Http/Requests/Bo/StaticPages/UpdateStaticPageRequest.php +++ b/app/Http/Requests/Bo/StaticPages/UpdateStaticPageRequest.php @@ -3,6 +3,7 @@ namespace App\Http\Requests\Bo\StaticPages; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Support\Facades\Gate; use Illuminate\Support\Str; class UpdateStaticPageRequest extends FormRequest @@ -12,9 +13,9 @@ class UpdateStaticPageRequest extends FormRequest * * @return boolean */ - public function authorize(): bool + public function authorize() { - return auth('backend')->check(); + return Gate::check('update', $this->route('static_page')); } /** @@ -25,7 +26,7 @@ class UpdateStaticPageRequest extends FormRequest public function prepareForValidation(): void { $this->merge([ - 'content' => Str::of($this->post('content'))->value() + 'content' => (string)Str::of($this->input('content')) ]); } @@ -55,7 +56,7 @@ class UpdateStaticPageRequest extends FormRequest 'seo_title' => trans('validation.custom.seo_title'), 'seo_description' => trans('validation.custom.seo_description'), 'title' => trans('validation.attributes.title'), - 'content' => trans('validation.custom.content'), + 'content' => trans('validation.attributes.content'), ]; } } diff --git a/app/Http/Requests/Bo/UpdateChangeOrderRequest.php b/app/Http/Requests/Bo/UpdateChangeOrderRequest.php index b88283e..48f10c3 100644 --- a/app/Http/Requests/Bo/UpdateChangeOrderRequest.php +++ b/app/Http/Requests/Bo/UpdateChangeOrderRequest.php @@ -24,7 +24,7 @@ class UpdateChangeOrderRequest extends FormRequest protected function prepareForValidation(): void { $this->merge([ - 'direction' => $this->direction === 'up' ? true : false + 'direction' => $this->string('direction') === 'up' ? true : false ]); } diff --git a/app/Http/Requests/Bo/Users/StoreUserRequest.php b/app/Http/Requests/Bo/Users/StoreUserRequest.php index eb68d84..be77bc0 100644 --- a/app/Http/Requests/Bo/Users/StoreUserRequest.php +++ b/app/Http/Requests/Bo/Users/StoreUserRequest.php @@ -3,7 +3,9 @@ namespace App\Http\Requests\Bo\Users; use App\Enums\Users\RoleEnum; +use App\Models\User; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Support\Facades\Gate; use Illuminate\Validation\Rules\Enum; use Illuminate\Validation\Rules\Password; @@ -14,9 +16,9 @@ class StoreUserRequest extends FormRequest * * @return boolean */ - public function authorize(): bool + public function authorize() { - return auth('backend')->check(); + return Gate::check('create', User::class); } /** @@ -27,7 +29,7 @@ class StoreUserRequest extends FormRequest protected function prepareForValidation() { $this->merge([ - 'published' => $this->published ? true : false + 'published' => $this->boolean('published') ]); } @@ -40,9 +42,9 @@ class StoreUserRequest extends FormRequest { return [ 'first_name' => 'required|string|min:3|max:255', - 'last_name' => 'required|string|min:3|max:255', - 'email' => 'required|email:rfc,strict,dns,spoof,filter|unique:users,email', - 'password' => [ + 'last_name' => 'required|string|min:3|max:255', + 'email' => 'required|email:rfc,strict,dns,spoof,filter|unique:users,email', + 'password' => [ 'required', 'required_with:password_confirmation', 'confirmed', 'max:255', Password::min(8) ->letters() ->mixedCase() @@ -50,8 +52,8 @@ class StoreUserRequest extends FormRequest ->symbols() ->uncompromised() ], - 'role' => ['required', new Enum(RoleEnum::class)], - 'published' => 'required|boolean', + 'role' => ['required', new Enum(RoleEnum::class)], + 'published' => 'required|boolean', ]; } diff --git a/app/Http/Requests/Bo/Users/UpdateUserRequest.php b/app/Http/Requests/Bo/Users/UpdateUserRequest.php index 8744be6..6c8da8b 100644 --- a/app/Http/Requests/Bo/Users/UpdateUserRequest.php +++ b/app/Http/Requests/Bo/Users/UpdateUserRequest.php @@ -2,10 +2,22 @@ namespace App\Http\Requests\Bo\Users; +use Illuminate\Support\Facades\Gate; +use Illuminate\Validation\Rule; use Illuminate\Validation\Rules\Password; class UpdateUserRequest extends StoreUserRequest { + /** + * Determine if the user is authorized to make this request. + * + * @return boolean + */ + public function authorize() + { + return Gate::check('update', $this->route('user')); + } + /** * Prepare the data for validation. * @@ -14,10 +26,10 @@ class UpdateUserRequest extends StoreUserRequest protected function prepareForValidation() { $this->merge([ - 'published' => $this->published ? true : false, - 'password' => $this->password ? $this->password : $this->route('user')->password, - 'password_confirmation' => $this->password_confirmation ? - $this->password_confirmation : + 'published' => $this->boolean('published'), + 'password' => $this->input('password') ?? + $this->route('user')->password, + 'password_confirmation' => $this->input('password_confirmation') ?? $this->route('user')->password ]); } @@ -30,10 +42,10 @@ class UpdateUserRequest extends StoreUserRequest public function rules(): array { return array_merge(parent::rules(), [ - 'email' => [ + 'email' => [ 'required', 'email:rfc,strict,dns,spoof,filter', - 'unique:users,email,' . $this->route('user')->id . ',id', + Rule::unique('users', 'email')->ignore($this->route('user')->getRouteKey()) ], 'password' => [ 'required', 'required_with:password_confirmation', 'confirmed', 'max:255', Password::min(8) diff --git a/app/Http/Requests/Fo/Customers/CreateAccountRequest.php b/app/Http/Requests/Fo/Customers/CreateAccountRequest.php index 6680449..f882105 100644 --- a/app/Http/Requests/Fo/Customers/CreateAccountRequest.php +++ b/app/Http/Requests/Fo/Customers/CreateAccountRequest.php @@ -2,10 +2,11 @@ namespace App\Http\Requests\Fo\Customers; -use App\Rules\IsAdult; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Facades\Auth; +use Illuminate\Validation\Rule; use Illuminate\Validation\Rules\Password; +use Kwaadpepper\Enum\Rules\EnumIsValidRule; use LDC\LDCCRM\Enums\Country; use LDC\LDCCRM\Models\Customer as CrmCustomer; @@ -29,8 +30,9 @@ class CreateAccountRequest extends FormRequest public function prepareForValidation() { $this->merge([ - 'phone' => $this->phone, - 'opt_in' => $this->opt_in ? true : false + 'phone' => $this->input('phone'), + 'opt_in' => $this->boolean('opt_in'), + 'ok_cgv' => $this->boolean('ok_cgv') ]); } @@ -42,14 +44,19 @@ class CreateAccountRequest extends FormRequest public function rules() { return [ - 'lastname' => 'required|string|max:255', - 'firstname' => 'required|string|max:255', - 'phone' => 'nullable|max:255|phone:FR', - 'address' => 'required|string|min:1|max:255', - 'postcode' => 'required|string|min:1|postal_code:FR', - 'city' => 'required|string|min:1|max:255', - 'birth_date' => ['required', new IsAdult(trans('Vous devez être majeur pour vous inscrire.'))], - 'email' => [ + 'lastname' => 'required|string|max:255', + 'firstname' => 'required|string|max:255', + 'phone' => 'nullable|max:255|phone:FR', + 'address' => 'required|string|min:1|max:255', + 'address2' => 'nullable|string|min:1|max:255', + 'postal_code' => 'required|string|min:1|postal_code:FR', + 'city' => 'required|string|min:2|max:255', + 'birth_date' => 'required|date', + 'country' => [ + 'required', new EnumIsValidRule(Country::class), + Rule::in(Country::getValidCountries()) + ], + 'email' => [ 'required', 'email:rfc,dns,spoof', 'max:255', // * Does email already exists in CRM ? // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed @@ -60,11 +67,12 @@ class CreateAccountRequest extends FormRequest }, 'unique:customers,email', ], - 'password' => [ - 'required', 'confirmed', Password::min(8)->mixedCase()->numbers()->symbols() + 'password' => [ + 'required', 'confirmed', Password::min(8)->mixedCase() + ->numbers()->symbols()->uncompromised() ], - 'ok_cgv' => 'accepted', - 'opt_in' => 'required|boolean', + 'ok_cgv' => 'accepted', + 'opt_in' => 'required|boolean', ]; } @@ -76,17 +84,20 @@ class CreateAccountRequest extends FormRequest public function attributes() { return [ - 'lastname' => trans('nom'), - 'firstname' => trans('prénom'), - 'phone' => trans('téléphone'), - 'address' => trans('adresse'), - 'postcode' => trans('code postal'), - 'city' => trans('ville'), - 'birth_date' => trans('date de naissance'), - 'email' => trans('email'), - 'password' => trans('mot de passe'), - 'ok_cgv' => trans('conditions d\'utilisation'), - 'opt_in' => trans('newsletter'), + 'lastname' => trans('validation.attributes.first_name'), + 'firstname' => trans('validation.attributes.first_name'), + 'phone' => trans('validation.attributes.phone'), + 'address' => trans('validation.attributes.line_address_1'), + 'address2' => trans('validation.attributes.line_address_2'), + 'country' => trans('validation.attributes.country'), + 'postal_code' => trans('validation.attributes.postal_code'), + 'city' => trans('validation.attributes.city'), + 'birth_date' => trans('validation.attributes.date_of_birth'), + 'email' => trans('validation.attributes.email'), + 'password' => trans('validation.attributes.password'), + 'password_confirmation' => trans('validation.attributes.password_confirmation'), + 'ok_cgv' => trans('conditions d\'utilisation'), + 'opt_in' => trans('newsletter'), ]; } @@ -98,11 +109,13 @@ class CreateAccountRequest extends FormRequest public function messages() { return [ - 'postal_code' => trans('validation.custom.postal_code', [ - 'countries' => Country::france()->label, 'examples' => 72000 + 'postal_code' => trans('validation.postal_code', [ + 'countries' => \implode(', ', Country::getValidCountriesLabel()), 'examples' => 72000 ]), - 'phone.phone' => trans('validation.custom.phone'), - 'email.unique' => trans('Un compte existe déjà avec cette adresse.'), + 'phone.phone' => trans('validation.phone', [ + 'countries' => \implode(', ', Country::getValidCountriesLabel()) + ]), + 'email.unique' => trans('Un compte existe déjà avec cette adresse.'), 'ok_cgv.accepted' => trans('Vous devez accepter les conditions d\'utilisation du site pour continuer.') ]; } diff --git a/app/Http/Requests/Fo/Customers/UpdateAccountRequest.php b/app/Http/Requests/Fo/Customers/UpdateAccountRequest.php index 8073ce5..ef2e28f 100644 --- a/app/Http/Requests/Fo/Customers/UpdateAccountRequest.php +++ b/app/Http/Requests/Fo/Customers/UpdateAccountRequest.php @@ -2,20 +2,20 @@ namespace App\Http\Requests\Fo\Customers; -use App\Rules\IsAdult; - class UpdateAccountRequest extends CreateAccountRequest { /** @var array */ private static $skeleton = [ 'lastname', 'firstname', + 'birth_date', 'phone', 'address', + 'address2', 'postcode', 'city', + 'country', 'opt_in', - 'birth_date' ]; /** @@ -29,13 +29,7 @@ class UpdateAccountRequest extends CreateAccountRequest \array_intersect_key( parent::rules(), \array_flip(self::$skeleton) - ), - [ - 'birth_date' => [ - 'required', - new IsAdult(trans('Vous devez être majeur pour utiliser le site.')) - ], - ] + ) ); } } diff --git a/app/Jobs/GamesStatusUpdate.php b/app/Jobs/GamesStatusUpdate.php index c724c34..63f6d08 100644 --- a/app/Jobs/GamesStatusUpdate.php +++ b/app/Jobs/GamesStatusUpdate.php @@ -19,9 +19,9 @@ class GamesStatusUpdate */ public function handle() { - /** @var \Illuminate\Database\Eloquent\Collection */ + /** @var \Illuminate\Database\Eloquent\Collection */ $gamesListToUnPublish = Game::query() - ->where('unpublish_at', '<=', Carbon::now()->toDateTime()) + ->where('unpublish_at', '<=', Carbon::now()) ->whereNotNull('unpublish_at') ->where('published', true)->get(); Log::debug(__CLASS__ . " games to unpublish " . $gamesListToUnPublish->count()); @@ -31,18 +31,19 @@ class GamesStatusUpdate $game->published = false; $game->saveOrFail(); } - /** @var \Illuminate\Database\Eloquent\Collection */ + /** @var \Illuminate\Database\Eloquent\Collection */ $gamesListToPublish = Game::query() - ->where('publish_at', '<=', Carbon::now()->toDateTime()) + ->where('publish_at', '<=', Carbon::now()) ->whereNotNull('publish_at') ->where('published', false)->get(); Log::debug(__CLASS__ . " games to publish " . $gamesListToPublish->count()); // Unpublish all game with no date because only 1 game can be published. if ($gamesListToPublish->count()) { - Game::query()->where('published', true)->each(function (Game $game) { - $game->published = false; - $game->saveOrFail(); - }); + Game::query()->where('published', true) + ->each(function (Game $game) { + $game->published = false; + $game->saveOrFail(); + }); } foreach ($gamesListToPublish as $game) { $game->publish_at = null; diff --git a/app/Jobs/NewsStatusUpdate.php b/app/Jobs/NewsStatusUpdate.php index 5e13fe4..aa2d221 100644 --- a/app/Jobs/NewsStatusUpdate.php +++ b/app/Jobs/NewsStatusUpdate.php @@ -19,9 +19,9 @@ class NewsStatusUpdate */ public function handle() { - /** @var \Illuminate\Database\Eloquent\Collection */ + /** @var \Illuminate\Database\Eloquent\Collection */ $newsListToPublish = News::query() - ->where('publish_at', '<=', Carbon::now()->toDateTime()) + ->where('publish_at', '<=', Carbon::now()) ->whereNotNull('publish_at') ->where('published', false)->get(); Log::debug(__CLASS__ . " news to publish " . $newsListToPublish->count()); @@ -30,9 +30,9 @@ class NewsStatusUpdate $news->published = true; $news->saveOrFail(); } - /** @var \Illuminate\Database\Eloquent\Collection */ + /** @var \Illuminate\Database\Eloquent\Collection */ $newsListToUnPublish = News::query() - ->where('unpublish_at', '<=', Carbon::now()->toDateTime()) + ->where('unpublish_at', '<=', Carbon::now()) ->whereNotNull('unpublish_at') ->where('published', true)->get(); Log::debug(__CLASS__ . " news to unpublish " . $newsListToPublish->count()); diff --git a/app/Lib/Helpers/FileStorageHelper.php b/app/Lib/Helpers/FileStorageHelper.php index 0e691d6..08a9f8c 100644 --- a/app/Lib/Helpers/FileStorageHelper.php +++ b/app/Lib/Helpers/FileStorageHelper.php @@ -30,6 +30,20 @@ use Illuminate\Support\Str; */ class FileStorageHelper { + /** + * Remove all files from string attribute html that are stored in public + * + * @param string $publicStorageFilePath The file path from public directory. + * @return string The local storage path. + */ + public static function getFileFullPath(string $publicStorageFilePath): string + { + /** @var \Illuminate\Filesystem\FilesystemAdapter */ + $disk = Storage::disk('uploads'); + $path = ToolboxHelper::mbReplace('storage/', '', \ltrim(\urldecode($publicStorageFilePath), '/')); + return $disk->path($path); + } + /** * Destroy the file associate with the attribute. * @@ -451,22 +465,4 @@ class FileStorageHelper $filename = trim($filename, '.-'); return $filename; } - - /** - * Remove all model files for the given Model. - * - * @param \Illuminate\Database\Eloquent\Model $model - * @return void - */ - public static function removeModelFiles(Model $model): void - { - $tableName = $model::query()->getModel()->getTable(); - - if (!empty(Storage::disk('public')->allFiles("modelfiles/{$tableName}"))) { - Storage::disk('public')->deleteDirectory("modelfiles/{$tableName}"); - } - if (!empty(Storage::disk('private')->allFiles("modelfiles/{$tableName}"))) { - Storage::disk('private')->deleteDirectory("modelfiles/{$tableName}"); - } - } } diff --git a/app/Lib/vendor/LDCWEB/MesBR.php b/app/Lib/vendor/LDCWEB/MesBR.php deleted file mode 100644 index 5115481..0000000 --- a/app/Lib/vendor/LDCWEB/MesBR.php +++ /dev/null @@ -1,73 +0,0 @@ -endpoint = $endpoint; - $this->refCamp = $refCamp; - } - public function createCustomer(string $hashcode, string $email, string $country) - { - return $this->callAPI("POST", '/customer', ['hashcode' => $hashcode, 'email' => $email, 'country' => $country]); - } - public function updateCustomer(string $hashcode, string $email, string $country) - { - return $this->callAPI("POST", '/customer', ['hashcode' => $hashcode, 'email' => $email, 'country' => $country]); - } - public function getMurCustomer(string $hashcode) - { - return $this->callAPI("GET", '/customer/mur', ['refcamp' => $this->refCamp, 'hashcode' => $hashcode]); - } - public function getMur() - { - return $this->callAPI("GET", '/mur', ['refcamp' => $this->refCamp]); - } - public function printCoupons(string $hashcode, array $coupons) - { - return $this->callAPI("GET", '/coupons/print', ['refcamp' => $this->refCamp, 'hashcode' => $hashcode, 'coupons' => implode(",", $coupons)]); - } - private function callAPI($method, $url, $data = []) - { - $url = $this->endpoint . '/api/v1' . $url; - $curl = curl_init(); - switch ($method) { - case "POST": - curl_setopt($curl, CURLOPT_POST, 1); - if ($data) { - curl_setopt($curl, CURLOPT_POSTFIELDS, $data); - } - break; - case "PUT": - case "DELETE": - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); - if ($data) { - curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); - } - break; - default: - if ($data) { - $url = sprintf("%s?%s", $url, http_build_query($data)); - } - } - curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_COOKIESESSION, true); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - - $result = curl_exec($curl); - if (!curl_errno($curl)) { - $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); - if (!in_array($http_code, [200, 201])) { - return (object)['status' => 'KO', 'code' => 500, 'message' => 'Connection to API failed - Code HTTP : ' . $http_code]; - } - } else { - return (object)['status' => 'KO', 'code' => 500, 'message' => 'Connection to API failed : ' . curl_error($curl)]; - } - curl_close($curl); - return json_decode($result); - } -} diff --git a/app/Lib/vendor/LDCWEB/MesBr.php b/app/Lib/vendor/LDCWEB/MesBr.php new file mode 100644 index 0000000..594807e --- /dev/null +++ b/app/Lib/vendor/LDCWEB/MesBr.php @@ -0,0 +1,150 @@ +endpoint = $endpoint; + $this->refCamp = $refCamp; + } + + public function createCustomer(string $hashcode, string $email, string $country) + { + return $this->callApi("POST", '/customer', ['hashcode' => $hashcode, 'email' => $email, 'country' => $country]); + } + public function updateCustomer(string $hashcode, string $email, string $country) + { + return $this->callApi("POST", '/customer', ['hashcode' => $hashcode, 'email' => $email, 'country' => $country]); + } + public function getMurCustomer(string $hashcode) + { + return $this->callApi("GET", '/customer/mur', ['refcamp' => $this->refCamp, 'hashcode' => $hashcode]); + } + public function getMur() + { + return $this->callApi("GET", '/mur', ['refcamp' => $this->refCamp]); + } + public function printCoupons(string $hashcode, array $coupons) + { + return $this->callApi("GET", '/coupons/print', [ + 'refcamp' => $this->refCamp, 'hashcode' => $hashcode, 'coupons' => implode(",", $coupons) + ]); + } + private function callApi($method, $url, $data = [], $path = '/api/v1') + { + $url = $this->endpoint . $path . $url; + $curl = curl_init(); + switch ($method) { + case "POST": + curl_setopt($curl, CURLOPT_POST, 1); + if ($data) { + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); + } + break; + case "PUT": + case "DELETE": + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); + if ($data) { + curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); + } + break; + default: + if ($data) { + $url = sprintf("%s?%s", $url, http_build_query($data)); + } + } + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_COOKIESESSION, true); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + + $result = curl_exec($curl); + if (!curl_errno($curl)) { + $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); + if (!in_array($http_code, [200, 201])) { + return (object)[ + 'status' => 'KO', 'code' => 500, 'message' => 'Connection to API failed - Code HTTP : ' . $http_code + ]; + } + } else { + return (object)[ + 'status' => 'KO', 'code' => 500, 'message' => 'Connection to API failed : ' . curl_error($curl) + ]; + } + curl_close($curl); + return json_decode($result); + } + + // * Added METHODS + + /** . + * Update panier + * + * @param \LDC\LDCCRM\Models\Customer $crm_customer + * @param integer $crm_customer_id + * @param string $ref_site + * @param string $coupon_id + * @param integer $quantity + * @return array + * 'status' => 'OK', + * 'link' => URL, + * 'verif' => URL, + * 'basketId' => 'ID' + */ + public function updatePanier( + Customer $crm_customer, + int $crm_customer_id, + string $ref_site, + string $coupon_id, + int $quantity = 1 + ): array { + $res = $this->callAPI("GET", "/updatebasket", [ + 'refsite' => $ref_site, + 'refcamp' => $this->refCamp, + 'refadherent' => $crm_customer_id, + 'nom' => $crm_customer->lastname, + 'prenom' => $crm_customer->firstname, + 'email' => $crm_customer->email, + 'code_postal' => $crm_customer->postcode, + 'commune' => $crm_customer->city, + 'pays' => $this->getCountry($crm_customer->country), + 'panier' => "({$quantity}){$coupon_id}" + ], ''); + + if (!$res) { + error_log("MESBR - CODE : 999 - MESSAGE : Cannot read API Response (non json)"); + return ['status' => 'KO', 'code' => 999, 'message' => 'Cannot read API Response (non json)']; + } + if ($res->Statut === 'KO') { + error_log("MESBR - CODE : $res->Code - MESSAGE : $res->Message"); + return ['status' => 'KO', 'code' => $res->Code, 'message' => $res->Message]; + } + $panierVerification = $this->endpoint . '/showbasket?basketid=' . $res->Panier->Panier; + $panier_link = $this->endpoint . '/?basketid=' . $res->Panier->Panier; + return ['status' => 'OK', 'link' => $panier_link, 'verif' => $panierVerification, 'basketId' => $res->Panier->Panier]; + } + + /** + * Translate country to MesBr Country + * + * @param \LDC\LDCCRM\Enums\Country $country + * @return inteager + */ + private function getCountry(Country $country): int + { + return match ($country) { + Country::belgium() => 56, + Country::luxembourg() => 442, + // * France + default => 250 + }; + } +} diff --git a/app/Listeners/LogVerifiedUser.php b/app/Listeners/LogVerifiedUser.php deleted file mode 100644 index 7c7092b..0000000 --- a/app/Listeners/LogVerifiedUser.php +++ /dev/null @@ -1,24 +0,0 @@ -user; - Auth::guard('frontend')->login($customer); - Session::flash('success', trans('Votre compte à bien été validé, vous êtes à présent connecté.')); - } -} diff --git a/app/Models/ActivityLog.php b/app/Models/ActivityLog.php index 59be331..0eca06b 100644 --- a/app/Models/ActivityLog.php +++ b/app/Models/ActivityLog.php @@ -10,11 +10,11 @@ use Illuminate\Notifications\Notifiable; use Illuminate\Support\Facades\Schema; /** - * @property string $model Target model. - * @property string $model_id Id of the target model. - * @property string $event Event of this activity (ActivityLogsEventEnum). - * @property string $data Changes. - * @property-read \Carbon\Carbon $created_at Created date. + * @property string $model Target model. + * @property string $model_id Id of the target model. + * @property string $event Event of this activity (ActivityLogsEventEnum). + * @property string $data Changes. + * @property-read \Illuminate\Support\Carbon $created_at Created date. * * @property-read \App\Models\User $user User BelongsTo relation. */ @@ -122,7 +122,7 @@ class ActivityLog extends Model * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ - public function user() + public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(User::class); } diff --git a/app/Models/Range.php b/app/Models/Range.php index 7a70e62..0688fa4 100644 --- a/app/Models/Range.php +++ b/app/Models/Range.php @@ -4,6 +4,7 @@ namespace App\Models; use App\Lib\Helpers\FileStorageHelper; use App\Lib\Helpers\ToolboxHelper; +use App\Traits\Models\IsCachedAsCollection; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; @@ -34,6 +35,7 @@ use Illuminate\Support\Str; */ class Range extends Model { + use IsCachedAsCollection; use HasFactory; /** @@ -71,10 +73,12 @@ class Range extends Model static::creating(function () { throw new \RuntimeException("Creating a new range is not authorized"); }); + static::created(fn () => self::removeCached()); static::updating(function (self $model) { self::manageFields($model); }); static::updated(function (self $model) { + self::removeCached(); FileStorageHelper::removeOldFile($model, 'picture'); FileStorageHelper::removeOldFile($model, 'picture_ambiance'); FileStorageHelper::removeOldFile($model, 'picto1_picture'); @@ -83,6 +87,7 @@ class Range extends Model static::deleting(function () { throw new \RuntimeException('Deleting a range is not authorized'); }); + static::deleted(fn () => self::removeCached()); } // * METHODS diff --git a/app/Models/StaticPage.php b/app/Models/StaticPage.php index 06151be..413f6f2 100644 --- a/app/Models/StaticPage.php +++ b/app/Models/StaticPage.php @@ -10,14 +10,14 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; /** - * @property \App\Enums\StaticPageType $type Page type (StaticPageEnum). - * @property string $seo_title Seo title about 70 chars as recommended. - * @property string $seo_description Seo description about 160 chars as recommended. - * @property string $title Title for the page. - * @property string $slug Slug of the title for the page. - * @property string $content WYSIWYG text content using ckeditor. - * @property-read \Carbon\Carbon $created_at Created date. - * @property-read \Carbon\Carbon $updated_at Updated date. + * @property \App\Enums\StaticPageType $type Page type (StaticPageEnum). + * @property string $seo_title Seo title about 70 chars as recommended. + * @property string $seo_description Seo description about 160 chars as recommended. + * @property string $title Title for the page. + * @property string $slug Slug of the title for the page. + * @property string $content WYSIWYG text content using ckeditor. + * @property-read \Illuminate\Support\Carbon $created_at Created date. + * @property-read \Illuminate\Support\Carbon $updated_at Updated date. */ class StaticPage extends Model { @@ -67,6 +67,32 @@ class StaticPage extends Model }); } + // * ROUTABLE + + /** + * Get the value of the model's route key. + * + * @return mixed + */ + public function getRouteKey() + { + /** @var \App\Enums\StaticPageType */ + $enum = $this->getAttribute($this->getRouteKeyName()); + return $enum->value(); + } + + /** + * Get the route key for the model. + * + * ! Type is the routable parameter + * + * @return string + */ + public function getRouteKeyName(): string + { + return 'type'; + } + // * METHODS /** diff --git a/app/Models/User.php b/app/Models/User.php index 4d0cd97..e91e8c2 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -4,21 +4,22 @@ namespace App\Models; use App\Enums\Users\RoleEnum; use App\Traits\Models\ActivityLog; +use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Facades\Hash; /** - * @property string $first_name Prénom. - * @property string $last_name Nom. - * @property string $email Email. - * @property string $password Mot de passe. - * @property \App\Enums\Users\RoleEnum $role Rôle. - * @property \Carbon\Carbon $published État de publication. - * @property \Carbon\Carbon $published_at Date de mise à jour de l'état de publication. - * @property-read \Carbon\Carbon $created_at Created date. - * @property-read \Carbon\Carbon $updated_at Updated date. + * @property string $first_name Prénom. + * @property string $last_name Nom. + * @property string $email Email. + * @property string $password Mot de passe. + * @property \App\Enums\Users\RoleEnum $role Rôle. + * @property \Illuminate\Support\Carbon $published État de publication. + * @property \Illuminate\Support\Carbon $published_at Date de mise à jour de l'état de publication. + * @property-read \Illuminate\Support\Carbon $created_at Created date. + * @property-read \Illuminate\Support\Carbon $updated_at Updated date. * * @property-read \App\Models\ActivityLog $activityLogs Activities logs One-to-many relationship. */ diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 53070fb..dfdb2ed 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -2,11 +2,9 @@ namespace App\Providers; -use App\Listeners\LogVerifiedUser; use App\Listeners\PasswordHasReset; use Illuminate\Auth\Events\PasswordReset; use Illuminate\Auth\Events\Registered; -use Illuminate\Auth\Events\Verified; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; @@ -21,9 +19,6 @@ class EventServiceProvider extends ServiceProvider Registered::class => [ SendEmailVerificationNotification::class, ], - Verified::class => [ - LogVerifiedUser::class - ], PasswordReset::class => [ PasswordHasReset::class ], diff --git a/app/Providers/MesBrServiceProvider.php b/app/Providers/MesBrApiServiceProvider.php similarity index 69% rename from app/Providers/MesBrServiceProvider.php rename to app/Providers/MesBrApiServiceProvider.php index 5a992e0..6a9a056 100644 --- a/app/Providers/MesBrServiceProvider.php +++ b/app/Providers/MesBrApiServiceProvider.php @@ -4,9 +4,9 @@ namespace App\Providers; use Illuminate\Support\Facades\App; use Illuminate\Support\ServiceProvider; -use LDCWEB\MesBR; +use LDC\MESBR\MesBr; -class MesBrServiceProvider extends ServiceProvider +class MesBrApiServiceProvider extends ServiceProvider { /** * Bootstrap the application services. @@ -15,8 +15,8 @@ class MesBrServiceProvider extends ServiceProvider */ public function boot() { - App::singleton('mesbr', function () { - return new MesBR( + App::singleton('mesBrAPI', function () { + return new MesBr( config('mesbr.endpoint'), config('mesbr.camp') ); diff --git a/app/Providers/ViewServiceProvider.php b/app/Providers/ViewServiceProvider.php index 87eaea4..b068b11 100644 --- a/app/Providers/ViewServiceProvider.php +++ b/app/Providers/ViewServiceProvider.php @@ -45,7 +45,7 @@ class ViewServiceProvider extends ServiceProvider if (!app()->runningInConsole()) { // Shares this data with all views. if (Schema::hasTable('ranges')) { - View::share('allRanges', Range::query()->get()); + View::share('allRanges', Range::getCached()); } // * FORCE BOOTSTRAP PAGINATOR (or custom if in front) diff --git a/app/Rules/IsAdult.php b/app/Rules/IsAdult.php deleted file mode 100644 index 4bbe241..0000000 --- a/app/Rules/IsAdult.php +++ /dev/null @@ -1,105 +0,0 @@ -error_message = $message ?? trans('Vous devez être majeur.'); - } - - /** - * Run the validation rule. - * - * @param string $attribute - * @param mixed $value - * @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail - * @return void - * @throws \RuntimeException If date cannot be parsed. - * @phpcs:disable Squiz.Commenting.FunctionComment.IncorrectTypeHint - */ - public function validate(string $attribute, mixed $value, \Closure $fail): void - { - //@phpcs:enable - $MJ = Carbon::now()->subYears(18); - - if ($this->isIsoFormat($value)) { - $d = Carbon::parse($value); - } - if ($this->isSqlDate($value)) { - $d = Carbon::createFromFormat('Y-m-d', $value); - } - if ($this->isFormDate($value)) { - $d = Carbon::createFromFormat('d/m/Y', $value); - } - // * Could not parse date. - if (!$d) { - throw new \RuntimeException("Could not parse date {$value} for attribute '{$attribute}'."); - } - if (!$d->lessThanOrEqualTo($MJ)) { - $fail($this->error_message); - } - } - - /** - * Check if provided string is formatted for mysql - * - * @param string $date - * @return boolean - */ - private function isSqlDate(string $date) - { - if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $date)) { - return true; - } - return false; - } - - /** - * Check if provided string is formatted DD/MM/AAAA - * - * @param string $date - * @return boolean - */ - private function isFormDate(string $date) - { - if (preg_match("/^(0[1-9]|[1-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\/[0-9]{4}$/", $date)) { - return true; - } - return false; - } - - /** - * Check if provided string is iso format - * - * * https://www.w3.org/TR/NOTE-datetime - * - * @param string $date - * @return boolean - */ - private function isIsoFormat(string $date) - { - // phpcs:ignore Generic.Files.LineLength.TooLong - if (preg_match("/^(\d{4})(?:-?W(\d+)(?:-?(\d+)D?)?|(?:-(\d+))?-(\d+))(?:[T ](\d+):(\d+)(?::(\d+)(?:\.(\d+))?)?)?(?:Z(-?\d*))?$/", $date)) { - return true; - } - return false; - } -} diff --git a/composer.json b/composer.json index 0c48fea..5672aef 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "autoload-dev": { "psr-4": { "Tests\\": "tests/", - "LDCWEB\\": "app/Lib/vendor/LDCWEB" + "LDC\\MESBR\\": "app/Lib/vendor/LDCWEB" } }, "scripts": { diff --git a/config/app.php b/config/app.php index 92fc94f..b002a6c 100644 --- a/config/app.php +++ b/config/app.php @@ -197,7 +197,7 @@ return [ App\Providers\TranslationServiceProvider::class, App\Providers\ViewServiceProvider::class, App\Providers\CrmApiServiceProvider::class, - App\Providers\MesBrServiceProvider::class, + App\Providers\MesBrApiServiceProvider::class, ], /* diff --git a/database/factories/ProductFactory.php b/database/factories/ProductFactory.php index 2ed290b..a806b2e 100644 --- a/database/factories/ProductFactory.php +++ b/database/factories/ProductFactory.php @@ -51,9 +51,9 @@ class ProductFactory extends Factory ], ]; - $label = fake()->text(15); + $label = fake()->unique()->slug(3); return [ - 'label' => $label, + 'label' => Str::of($label)->replace('-', ' ')->title(), 'slug' => Str::slug($label), 'seo_title' => fake()->sentence(), 'seo_description' => fake()->sentence(), diff --git a/database/migrations/2023_10_19_094711_create_static_pages.php b/database/migrations/2023_10_19_094711_create_static_pages.php index a28d0c0..9ce6b75 100644 --- a/database/migrations/2023_10_19_094711_create_static_pages.php +++ b/database/migrations/2023_10_19_094711_create_static_pages.php @@ -2,7 +2,6 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Schema; return new class extends Migration @@ -29,9 +28,6 @@ return new class extends Migration $table->timestamps(); }); - Artisan::call('db:seed', [ - 'class' => 'StaticPageSeeder' - ]); } /** diff --git a/database/migrations/2030_01_01_000001_mandatory_seeds.php b/database/migrations/2030_01_01_000001_mandatory_seeds.php new file mode 100644 index 0000000..9d718ce --- /dev/null +++ b/database/migrations/2030_01_01_000001_mandatory_seeds.php @@ -0,0 +1,30 @@ + MandatorySeeder::class + ]); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + // Do nothing. + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 6f9f3ec..911f218 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -14,17 +14,9 @@ class DatabaseSeeder extends Seeder public function run() { $this->call([ - UserSeeder::class, - PictoSeeder::class, - CommitmentPageSeeder::class, - GameSeeder::class, - HistoricalMilestoneSeeder::class, - KlubBlocSeeder::class, - LocalCommitmentSeeder::class, - NewsSeeder::class, - RangeSeeder::class, - ProductSeeder::class, - ReductionSeeder::class, + MandatorySeeder::class, + DevelopmentSeeder::class, + UserSeeder::class ]); } } diff --git a/database/seeders/GameSeeder.php b/database/seeders/Development/GameSeeder.php similarity index 80% rename from database/seeders/GameSeeder.php rename to database/seeders/Development/GameSeeder.php index 6384c77..65f1415 100644 --- a/database/seeders/GameSeeder.php +++ b/database/seeders/Development/GameSeeder.php @@ -1,10 +1,12 @@ getTable())->truncate(); + File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new Game())->getTable())); $publish_at = now()->addMonth(); $unpublish_at = $publish_at->copy()->addDays(rand(10, 20)); diff --git a/database/seeders/HistoricalMilestoneSeeder.php b/database/seeders/Development/HistoricalMilestoneSeeder.php similarity index 83% rename from database/seeders/HistoricalMilestoneSeeder.php rename to database/seeders/Development/HistoricalMilestoneSeeder.php index f532fa2..a68c22b 100644 --- a/database/seeders/HistoricalMilestoneSeeder.php +++ b/database/seeders/Development/HistoricalMilestoneSeeder.php @@ -1,10 +1,12 @@ getTable())->truncate(); + File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new HistoricalMilestone())->getTable())); HistoricalMilestone::factory(7)->make()->each(function (HistoricalMilestone $historicalMilestone) { $historicalMilestone->picture1 = FileStorageHelper::storeFile( diff --git a/database/seeders/LocalCommitmentSeeder.php b/database/seeders/Development/LocalCommitmentSeeder.php similarity index 84% rename from database/seeders/LocalCommitmentSeeder.php rename to database/seeders/Development/LocalCommitmentSeeder.php index 03a096d..18eda67 100644 --- a/database/seeders/LocalCommitmentSeeder.php +++ b/database/seeders/Development/LocalCommitmentSeeder.php @@ -1,10 +1,12 @@ getTable())->truncate(); + File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new LocalCommitment())->getTable())); LocalCommitment::factory(7)->make()->each(function (LocalCommitment $localCommitment) { $localCommitment->picture1 = FileStorageHelper::storeFile( diff --git a/database/seeders/NewsSeeder.php b/database/seeders/Development/NewsSeeder.php similarity index 69% rename from database/seeders/NewsSeeder.php rename to database/seeders/Development/NewsSeeder.php index 272ca57..ca62116 100644 --- a/database/seeders/NewsSeeder.php +++ b/database/seeders/Development/NewsSeeder.php @@ -1,10 +1,12 @@ getTable())->truncate(); + File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new News())->getTable())); News::factory(20)->make()->each(function (News $news) { $news->picture = FileStorageHelper::storeFile( diff --git a/database/seeders/ProductSeeder.php b/database/seeders/Development/ProductSeeder.php similarity index 75% rename from database/seeders/ProductSeeder.php rename to database/seeders/Development/ProductSeeder.php index afdcd2f..56c429a 100644 --- a/database/seeders/ProductSeeder.php +++ b/database/seeders/Development/ProductSeeder.php @@ -1,11 +1,14 @@ getTable())->truncate(); + Schema::enableForeignKeyConstraints(); + + File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new Product())->getTable())); Product::factory(12)->make()->each(function (Product $product) { $product->picture = FileStorageHelper::storeFile( diff --git a/database/seeders/ReductionSeeder.php b/database/seeders/Development/ReductionSeeder.php similarity index 70% rename from database/seeders/ReductionSeeder.php rename to database/seeders/Development/ReductionSeeder.php index 53cf996..baadec8 100644 --- a/database/seeders/ReductionSeeder.php +++ b/database/seeders/Development/ReductionSeeder.php @@ -1,10 +1,12 @@ getTable())->truncate(); + File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new Reduction())->getTable())); Reduction::factory(10)->make()->each(function (Reduction $reduction) { $reduction->picture_packshot = FileStorageHelper::storeFile( diff --git a/database/seeders/DevelopmentSeeder.php b/database/seeders/DevelopmentSeeder.php new file mode 100644 index 0000000..a0575b6 --- /dev/null +++ b/database/seeders/DevelopmentSeeder.php @@ -0,0 +1,31 @@ +call([ + GameSeeder::class, + HistoricalMilestoneSeeder::class, + LocalCommitmentSeeder::class, + NewsSeeder::class, + ProductSeeder::class, + ReductionSeeder::class, + ]); + } +} diff --git a/database/seeders/CommitmentPageSeeder.php b/database/seeders/Mandatory/CommitmentPageSeeder.php similarity index 56% rename from database/seeders/CommitmentPageSeeder.php rename to database/seeders/Mandatory/CommitmentPageSeeder.php index 8b098ec..b7d2a2e 100644 --- a/database/seeders/CommitmentPageSeeder.php +++ b/database/seeders/Mandatory/CommitmentPageSeeder.php @@ -1,10 +1,13 @@ getTable())->truncate(); + Schema::enableForeignKeyConstraints(); + + File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new Picto())->getTable())); + CommitmentPage::factory(1)->createQuietly(); $pictos = Picto::query()->get(); diff --git a/database/seeders/KlubBlocSeeder.php b/database/seeders/Mandatory/KlubBlocSeeder.php similarity index 70% rename from database/seeders/KlubBlocSeeder.php rename to database/seeders/Mandatory/KlubBlocSeeder.php index 08227fd..11b5b6a 100644 --- a/database/seeders/KlubBlocSeeder.php +++ b/database/seeders/Mandatory/KlubBlocSeeder.php @@ -1,10 +1,12 @@ getTable())->truncate(); + File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new KlubBloc())->getTable())); + KlubBloc::factory(1)->make()->each(function (KlubBloc $klubBloc) { $klubBloc->picture = FileStorageHelper::storeFile( new KlubBloc(), diff --git a/database/seeders/PictoSeeder.php b/database/seeders/Mandatory/PictoSeeder.php similarity index 60% rename from database/seeders/PictoSeeder.php rename to database/seeders/Mandatory/PictoSeeder.php index fd5d63f..732e21c 100644 --- a/database/seeders/PictoSeeder.php +++ b/database/seeders/Mandatory/PictoSeeder.php @@ -1,10 +1,13 @@ getTable())->truncate(); + Schema::enableForeignKeyConstraints(); + + File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new Picto())->getTable())); Picto::factory(10)->make()->each(function (Picto $picto) { $picto->picture = FileStorageHelper::storeFile( diff --git a/database/seeders/RangeSeeder.php b/database/seeders/Mandatory/RangeSeeder.php similarity index 79% rename from database/seeders/RangeSeeder.php rename to database/seeders/Mandatory/RangeSeeder.php index 984b7ac..ea04cd6 100644 --- a/database/seeders/RangeSeeder.php +++ b/database/seeders/Mandatory/RangeSeeder.php @@ -1,10 +1,13 @@ getTable())->truncate(); + Schema::enableForeignKeyConstraints(); + + File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new Range())->getTable())); Range::factory(3)->make()->each(function (Range $range) { $range->picture = FileStorageHelper::storeFile( diff --git a/database/seeders/StaticPageSeeder.php b/database/seeders/Mandatory/StaticPageSeeder.php similarity index 96% rename from database/seeders/StaticPageSeeder.php rename to database/seeders/Mandatory/StaticPageSeeder.php index 6e56f96..9106d13 100644 --- a/database/seeders/StaticPageSeeder.php +++ b/database/seeders/Mandatory/StaticPageSeeder.php @@ -1,10 +1,11 @@ getTable())->truncate(); + StaticPage::query()->make( [ 'seo_title' => 'Seo title pour la page contactez nous', @@ -23,7 +26,7 @@ class StaticPageSeeder extends Seeder 'title' => 'Contactez-nous', 'slug' => Str::slug('Contactez-nous'), 'type' => StaticPageType::contact, - 'content' => \clean(\fake()->randomHtml(6, 7)), + 'content' => \clean(\fake()->randomHtml(2, 3)), ] )->saveQuietly(); StaticPage::query()->make( @@ -33,7 +36,7 @@ class StaticPageSeeder extends Seeder 'title' => 'Mentions légales', 'slug' => Str::slug('Mentions légales'), 'type' => StaticPageType::legals, - 'content' => \clean(\fake()->randomHtml(6, 7)), + 'content' => \clean(\fake()->randomHtml(2, 3)), ] )->saveQuietly(); StaticPage::query()->make( @@ -43,7 +46,7 @@ class StaticPageSeeder extends Seeder 'title' => 'Charte de confidentialité', 'slug' => Str::slug('Charte de confidentialité'), 'type' => StaticPageType::confidentiality, - 'content' => \clean(\fake()->randomHtml(6, 7)), + 'content' => \clean(\fake()->randomHtml(2, 3)), ] )->saveQuietly(); StaticPage::query()->make( @@ -53,7 +56,7 @@ class StaticPageSeeder extends Seeder 'title' => 'Accueil', 'slug' => Str::slug('Accueil'), 'type' => StaticPageType::home, - 'content' => \clean(\fake()->randomHtml(6, 7)), + 'content' => \clean(\fake()->randomHtml(2, 3)), ] )->saveQuietly(); StaticPage::query()->make( @@ -63,7 +66,7 @@ class StaticPageSeeder extends Seeder 'title' => 'Nos gammes', 'slug' => Str::slug('Nos gammes'), 'type' => StaticPageType::ranges, - 'content' => \clean(\fake()->randomHtml(6, 7)), + 'content' => \clean(\fake()->randomHtml(2, 3)), ] )->saveQuietly(); StaticPage::query()->make( @@ -73,7 +76,7 @@ class StaticPageSeeder extends Seeder 'title' => 'Une Gamme', 'slug' => Str::slug('Une Gamme'), 'type' => StaticPageType::range, - 'content' => \clean(\fake()->randomHtml(6, 7)), + 'content' => \clean(\fake()->randomHtml(2, 3)), ] )->saveQuietly(); StaticPage::query()->make( @@ -83,7 +86,7 @@ class StaticPageSeeder extends Seeder 'title' => 'Actualités', 'slug' => Str::slug('Actualités'), 'type' => StaticPageType::news, - 'content' => \clean(\fake()->randomHtml(6, 7)), + 'content' => \clean(\fake()->randomHtml(2, 3)), ] )->saveQuietly(); StaticPage::query()->make( @@ -93,7 +96,7 @@ class StaticPageSeeder extends Seeder 'title' => 'Le Klub', 'slug' => Str::slug('Le Klub'), 'type' => StaticPageType::klub, - 'content' => \clean(\fake()->randomHtml(6, 7)), + 'content' => \clean(\fake()->randomHtml(2, 3)), ] )->saveQuietly(); StaticPage::query()->make( @@ -103,7 +106,7 @@ class StaticPageSeeder extends Seeder 'title' => 'Le Klub - Inscription', 'slug' => Str::slug('Le Klub - Inscription'), 'type' => StaticPageType::klub_register, - 'content' => \clean(\fake()->randomHtml(6, 7)), + 'content' => \clean(\fake()->randomHtml(2, 3)), ] )->saveQuietly(); StaticPage::query()->make( @@ -113,7 +116,7 @@ class StaticPageSeeder extends Seeder 'title' => 'Notre Histoire', 'slug' => Str::slug('Notre Histoire'), 'type' => StaticPageType::history, - 'content' => \clean(\fake()->randomHtml(6, 7)), + 'content' => \clean(\fake()->randomHtml(2, 3)), ] )->saveQuietly(); StaticPage::query()->make( diff --git a/database/seeders/MandatorySeeder.php b/database/seeders/MandatorySeeder.php new file mode 100644 index 0000000..05144b0 --- /dev/null +++ b/database/seeders/MandatorySeeder.php @@ -0,0 +1,29 @@ +call([ + StaticPageSeeder::class, + PictoSeeder::class, + CommitmentPageSeeder::class, + RangeSeeder::class, + KlubBlocSeeder::class + ]); + } +} diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index 3c4c266..d46aee1 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -3,10 +3,13 @@ namespace Database\Seeders; use App\Models\User; +use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; class UserSeeder extends Seeder { + use WithoutModelEvents; + /** * Run the database seeds. * @@ -14,6 +17,6 @@ class UserSeeder extends Seeder */ public function run() { - User::factory(20)->createQuietly(); + User::factory(20)->create(); } } diff --git a/resources/lang/fr/validation.php b/resources/lang/fr/validation.php index ecff9c1..a79fe21 100644 --- a/resources/lang/fr/validation.php +++ b/resources/lang/fr/validation.php @@ -217,6 +217,12 @@ return [ 'username' => 'nom d\'utilisateur', 'year' => 'année', ], + + 'postal_code' => 'le champ :attribute accepte les codes postaux des pays suivants + :countries comme par exemple :examples', + 'phone' => 'Le champ :attribute n\'est pas un numéro de téléphone valide, il accepte les + numéros des pays suivants :countries.', + 'custom' => [ 'of_the' => [ 'male' => 'du ', diff --git a/resources/ts/fo/components/InputBirthDate.vue b/resources/ts/fo/components/InputBirthDate.vue index ea97ed8..9c07787 100644 --- a/resources/ts/fo/components/InputBirthDate.vue +++ b/resources/ts/fo/components/InputBirthDate.vue @@ -9,6 +9,7 @@ v-model="ipt_value" :autocomplete="String(ipt_autocomplete)" :required="Boolean(ipt_required)" + :aria-label="__(ipt_placeholder)" @focus="startEditing" @change="changed" > diff --git a/resources/views/bo/pages/static_pages/form.blade.php b/resources/views/bo/pages/static_pages/form.blade.php index 4b3d529..ae2aae6 100644 --- a/resources/views/bo/pages/static_pages/form.blade.php +++ b/resources/views/bo/pages/static_pages/form.blade.php @@ -1,17 +1,18 @@
- {{-- ROLE --}} + {{-- TYPE --}}
{{ Str::ucfirst(__('validation.custom.static_page_type')) }}
@include('bo.partials.inputs.tinyint-enum', [ - 'id' => 'userRole', - 'label' => __('Associer un rôle'), - 'name' => 'role', + 'id' => 'staticPageType', + 'label' => __('Type de page'), + 'name' => 'type', 'model' => $staticPageModel ?? null, 'required' => false, 'disabled' => true, + 'value' => optional(optional($staticPageModel ?? null)->type)->value(), 'associatedModels' => \App\Enums\StaticPageType::toArray(), 'helper' => '', ]) diff --git a/resources/views/bo/partials/inputs/bigint-foreign-id.blade.php b/resources/views/bo/partials/inputs/bigint-foreign-id.blade.php index c0f9f1e..3965cce 100644 --- a/resources/views/bo/partials/inputs/bigint-foreign-id.blade.php +++ b/resources/views/bo/partials/inputs/bigint-foreign-id.blade.php @@ -1,3 +1,4 @@ +{{-- blade-formatter-disable --}} {{-- VARIABLE || COMMENT || TYPE || REQUIRED || DEFAULT @@ -17,15 +18,18 @@ @endif + @if(isset($appendText)) + +
+@endif +@include('modules.input-error', [ + 'inputName' => $name, + 'helperId' => "{$id}Help", + 'helper' => $helper +]) + +@push('scripts') + +@endpush diff --git a/resources/views/bo/partials/inputs/int-number.blade.php b/resources/views/bo/partials/inputs/int-number.blade.php index 2a7ee83..6885a98 100644 --- a/resources/views/bo/partials/inputs/int-number.blade.php +++ b/resources/views/bo/partials/inputs/int-number.blade.php @@ -1,3 +1,4 @@ +{{-- blade-formatter-disable --}} {{-- VARIABLE || COMMENT || TYPE || REQUIRED || DEFAULT @@ -28,7 +29,10 @@ name="{{ $name }}" type="number" value="{{ Str::replace(',', '.', strval(old($name, $value ?? $model->{$name} ?? 0))) }}" - class="form-control @if($errors->has($name)) is-invalid @endif" + @class([ + 'form-control', + 'is-invalid' => $errors->has($name) + ]) aria-describedby="{{ $id }}Help" @if(!empty($step)) step="{{ Str::replace(',', '.', strval($step)) }}" @@ -43,15 +47,15 @@ @else min="{{ !empty($unsigned) ? '0' : '-2147483648' }}" @endif - @if(!empty($required)) - required - @endif> + @disabled(!empty($disabled)) + @readonly(!empty($readonly)) + @required(!empty($required))> @if(isset($appendText))
@endif @include('modules.input-error', [ 'inputName' => $name, - 'helperId' => '{{ $id }}Help', + 'helperId' => "{$id}Help", 'helper' => $helper ]) diff --git a/resources/views/bo/partials/inputs/pivot-belongsToMany.blade.php b/resources/views/bo/partials/inputs/pivot-belongsToMany.blade.php index 44d72cb..2f8adbe 100644 --- a/resources/views/bo/partials/inputs/pivot-belongsToMany.blade.php +++ b/resources/views/bo/partials/inputs/pivot-belongsToMany.blade.php @@ -13,7 +13,7 @@ @php $data = [ 'name' => $name, - 'value' => old($name) ?? ($model->{$name} ?? []) ?? [], + 'value' => Arr::wrap(old($name) ?? ($model->{$name} ?? [])), 'placeholder' => $placeholder, 'itemsList' => $itemsList, 'itemLimit' => $itemLimit ?? null, diff --git a/resources/views/bo/partials/inputs/select-multiple-enum.blade.php b/resources/views/bo/partials/inputs/select-multiple-enum.blade.php index c0b7c82..240496e 100644 --- a/resources/views/bo/partials/inputs/select-multiple-enum.blade.php +++ b/resources/views/bo/partials/inputs/select-multiple-enum.blade.php @@ -1,16 +1,16 @@ @php -$data = [ - "name" => $name, - "label" => $label, - "value" => $value ?? [], - "placeholder" => $placeholder, - "itemsSelected" => $itemsSelected, - "itemsList" => $itemsList, - "itemLimit" => $itemLimit, - "showSpecificItem" => $showSpecificItem ?? null, - "errors" => $errors->getBag("default")->getMessages() ?? [], - 'helper' => $helper, - 'require' => $require -]; + $data = [ + 'name' => $name, + 'label' => $label, + 'value' => $value ?? [], + 'placeholder' => $placeholder, + 'itemsSelected' => $itemsSelected, + 'itemsList' => $itemsList, + 'itemLimit' => $itemLimit, + 'showSpecificItem' => $showSpecificItem ?? null, + 'errors' => $errors->getBag('default')->getMessages() ?? [], + 'helper' => $helper, + 'require' => $require, + ]; @endphp
diff --git a/resources/views/bo/partials/inputs/text-html.blade.php b/resources/views/bo/partials/inputs/text-html.blade.php index 3f3c814..c164c70 100644 --- a/resources/views/bo/partials/inputs/text-html.blade.php +++ b/resources/views/bo/partials/inputs/text-html.blade.php @@ -10,23 +10,27 @@ $model || The model we're creating/editing || Model class || OPTIONNAL || null --}} -@if(!empty($label)) - +@if (!empty($label)) + @endif @php -$data = [ - 'name' => $name, - 'text' => old($name, $model->{$name} ?? $value ?? '') -]; + $data = [ + 'name' => $name, + 'text' => old($name, $model->{$name} ?? ($value ?? '')), + ]; @endphp
@include('modules.input-error', [ 'inputName' => $name, 'helperId' => "{$id}Help", - 'helper' => $helper ?? __('crud.minicrud.text_warning') . '. ' . __('validation.min.string', [ - 'attribute' => $input['label'], - 'min' => 15 - ]), + 'helper' => + $helper ?? + __('crud.minicrud.text_warning') . + '. ' . + __('validation.min.string', [ + 'attribute' => $input['label'], + 'min' => 15, + ]), ]) diff --git a/resources/views/bo/partials/inputs/text-list-items.blade.php b/resources/views/bo/partials/inputs/text-list-items.blade.php index 6262b0b..8b44327 100644 --- a/resources/views/bo/partials/inputs/text-list-items.blade.php +++ b/resources/views/bo/partials/inputs/text-list-items.blade.php @@ -1,7 +1,7 @@ -
+
-
@@ -9,16 +9,16 @@
@php - $data = [ - 'itemList' => old($name, $model->{$name} ?? []) ?? [], - 'itemColumns' => $itemColumns, - 'itemType' => $itemType, - 'itemLimit' => $itemLimit ?? [], - 'inputName' => $name, - 'inputPlaceholder' => $inputPlaceholder, - 'header' => $header ?? false, - 'errors' => $errors->getBag('default')->getMessages() ?? [] - ]; + $data = [ + 'itemList' => old($name, $model->{$name} ?? []) ?? [], + 'itemColumns' => $itemColumns, + 'itemType' => $itemType, + 'itemLimit' => $itemLimit ?? [], + 'inputName' => $name, + 'inputPlaceholder' => $inputPlaceholder, + 'header' => $header ?? false, + 'errors' => $errors->getBag('default')->getMessages() ?? [], + ]; @endphp
@include('modules.input-error', [ diff --git a/resources/views/bo/partials/inputs/timestamp-datetime.blade.php b/resources/views/bo/partials/inputs/timestamp-datetime.blade.php index 9c6a5e6..0cdb81e 100644 --- a/resources/views/bo/partials/inputs/timestamp-datetime.blade.php +++ b/resources/views/bo/partials/inputs/timestamp-datetime.blade.php @@ -1,3 +1,4 @@ +{{-- blade-formatter-disable --}} {{-- VARIABLE || COMMENT || TYPE || REQUIRED || DEFAULT @@ -16,8 +17,11 @@ {{ $label }} {{ $required ?? false ? '*' : '' }} @endif - @include('modules.input-error', [ diff --git a/resources/views/bo/partials/inputs/tinyint-boolean.blade.php b/resources/views/bo/partials/inputs/tinyint-boolean.blade.php index 05a7455..1c1e537 100644 --- a/resources/views/bo/partials/inputs/tinyint-boolean.blade.php +++ b/resources/views/bo/partials/inputs/tinyint-boolean.blade.php @@ -1,3 +1,4 @@ +{{-- blade-formatter-disable --}} {{-- VARIABLE || COMMENT || TYPE || REQUIRED || DEFAULT @@ -9,7 +10,7 @@ --}}
- + {$name} ?? false)))) checked @endif> + @disabled(!empty($disabled)) + @readonly(!empty($readonly)) + @required(!empty($required)) + @checked(old($name, (old('_token') ? false : ($model->{$name} ?? false))))>
@include('modules.input-error', [ 'inputName' => $name, - 'helperId' => '{{ $id }}Help' , + 'helperId' => "{$id}Help", 'helper' => $helper ]) diff --git a/resources/views/bo/partials/inputs/tinyint-enum.blade.php b/resources/views/bo/partials/inputs/tinyint-enum.blade.php index f9ab473..68f183f 100644 --- a/resources/views/bo/partials/inputs/tinyint-enum.blade.php +++ b/resources/views/bo/partials/inputs/tinyint-enum.blade.php @@ -1,3 +1,4 @@ +{{-- blade-formatter-disable --}} {{-- VARIABLE || COMMENT || TYPE || REQUIRED || DEFAULT @@ -17,7 +18,10 @@ @endif @include('modules.input-error', [ 'inputName' => $name, - 'helperId' => "{{ $id }}Help", + 'helperId' => "{$id}Help", 'helper' => $helper ]) diff --git a/resources/views/bo/partials/inputs/varchar-email.blade.php b/resources/views/bo/partials/inputs/varchar-email.blade.php index 4a2c2e1..24e9e26 100644 --- a/resources/views/bo/partials/inputs/varchar-email.blade.php +++ b/resources/views/bo/partials/inputs/varchar-email.blade.php @@ -1,3 +1,4 @@ +{{-- blade-formatter-disable --}} {{-- VARIABLE || COMMENT || TYPE || REQUIRED || DEFAULT @@ -10,8 +11,8 @@ $model || The model we're creating/editing || Model class || OPTIONNAL || null --}} -@if(!empty($label)) -
@include('modules.input-error', [ diff --git a/resources/views/bo/partials/inputs/varchar-password.blade.php b/resources/views/bo/partials/inputs/varchar-password.blade.php index c779b0e..c6ec688 100644 --- a/resources/views/bo/partials/inputs/varchar-password.blade.php +++ b/resources/views/bo/partials/inputs/varchar-password.blade.php @@ -1,3 +1,4 @@ +{{-- blade-formatter-disable --}} {{-- VARIABLE || COMMENT || TYPE || REQUIRED || DEFAULT @@ -24,14 +25,18 @@ name="{{ $name }}" type="password" value="{{ old($name, $model->{$name} ?? '') }}" - class="form-control @if($errors->has($name)) is-invalid @endif @if(!empty($hasWordCounter ?? false)) need-word-counter-password @endif" + @class([ + 'form-control', + 'is-invalid' => $errors->has($name), + 'need-word-counter-password' => !empty($hasWordCounter ?? false) + ]) id="{{ $id }}" aria-describedby="{{ $id }}Help" placeholder="{{ $placeholder ?? __('Un beau mot de passe') }}" autocomplete="current-password" - @if(!empty($required)) - required - @endif> + @disabled(!empty($disabled)) + @readonly(!empty($readonly)) + @required(!empty($required))> @php $dataPassword = ['inputId' => $id]; @endphp @@ -39,6 +44,6 @@
@include('modules.input-error', [ 'inputName' => $name, - 'helperId' => $id . 'Help', + 'helperId' => "{$id}Help", 'helper' => $helper ]) diff --git a/resources/views/bo/partials/inputs/varchar-picture.blade.php b/resources/views/bo/partials/inputs/varchar-picture.blade.php index c41f82b..3d2af0a 100644 --- a/resources/views/bo/partials/inputs/varchar-picture.blade.php +++ b/resources/views/bo/partials/inputs/varchar-picture.blade.php @@ -15,17 +15,17 @@ --}} @php -$data = [ - 'id' => $id, - 'name' => $name, - 'helper' => $helper, - 'width' => $width, - 'height' => $height, - 'value' => $model->{$name} ?? $value ?? '', - 'preview' => $preview ?? false, - 'browseEvent' => $browseEvent ?? false, - 'required' => $required ?? false, -]; + $data = [ + 'id' => $id, + 'name' => $name, + 'helper' => $helper, + 'width' => $width, + 'height' => $height, + 'value' => $model->{$name} ?? ($value ?? ''), + 'preview' => $preview ?? false, + 'browseEvent' => $browseEvent ?? false, + 'required' => $required ?? false, + ]; @endphp
@include('modules.input-error', ['inputName' => $name, 'helper' => null]) diff --git a/resources/views/bo/partials/inputs/varchar.blade.php b/resources/views/bo/partials/inputs/varchar.blade.php index 083a7f4..52edee3 100644 --- a/resources/views/bo/partials/inputs/varchar.blade.php +++ b/resources/views/bo/partials/inputs/varchar.blade.php @@ -1,3 +1,4 @@ +{{-- blade-formatter-disable --}} {{-- VARIABLE || COMMENT || TYPE || REQUIRED || DEFAULT @@ -24,12 +25,16 @@ type="text" value="{{ old($name, $model->{$name} ?? $value ?? '') }}" class="form-control @if($errors->has($name)) is-invalid @endif" + @class([ + 'form-control', + 'is-invalid' => $errors->has($name) + ]) id="{{ $id }}" aria-describedby="{{ $id }}Help" placeholder="{{ $placeholder ?? __('A beautiful title') }}" - @if(!empty($required)) - required - @endif> + @disabled(!empty($disabled)) + @readonly(!empty($readonly)) + @required(!empty($required))> @include('modules.input-error', [ 'inputName' => $name, 'helperId' => $id.'Help', diff --git a/resources/views/emails/send-contact-form.blade.php b/resources/views/emails/send-contact-form.blade.php index f10b3f5..4c32b75 100644 --- a/resources/views/emails/send-contact-form.blade.php +++ b/resources/views/emails/send-contact-form.blade.php @@ -19,13 +19,13 @@ {{ __('Code postal :') }} __{{ $data->postal_code }}__ @if ($data->product) -{{ __('Produit concerné :') }} __{{ $data->product->label }}__ +{{ __('Produit concerné :') }} __{{ $data->product->label }}__
@endif @if ($data->expiration_date) -{{ __('DCR :') }} __{{ $data->expiration_date->isoFormat('LLLL') }}__ +{{ __('DCR :') }} __{{ $data->expiration_date->isoFormat('LLLL') }}__
@endif @if ($data->batch_number) -{{ __('Numéro de lot :') }} __{{ $data->batch_number }}__ +{{ __('Numéro de lot :') }} __{{ $data->batch_number }}__
@endif {{ __('Message :') }} diff --git a/resources/views/fo/auth/register.blade.php b/resources/views/fo/auth/register.blade.php index dd6498e..1a80097 100644 --- a/resources/views/fo/auth/register.blade.php +++ b/resources/views/fo/auth/register.blade.php @@ -14,20 +14,21 @@

{{ __('Le Klub') }} {{ config('app.name') }} !

{{ __('Trait souligné') }} - {{ __('Inscrivez vous au Klub Tre Galette') }}
@csrf
+ {{ __('Inscrivez vous au Klub Tre Galette') }} + @include('fo.pages.klub.customer-form')
- -
@@ -39,9 +40,9 @@
- -