From 799792a0dd160b4705a78cdda16d72f3c013dca8 Mon Sep 17 00:00:00 2001 From: Daniel Wilkowski Date: Wed, 20 Sep 2023 16:36:25 +0200 Subject: [PATCH] Add "newsletter agreement" to user profile and admin --- app/Domain/User/UserSettings.php | 5 +++++ .../Controllers/Auth/RegisterController.php | 11 +++++----- app/Http/Forms/User/SettingsForm.php | 4 ++++ app/Models/User.php | 11 +++++----- ...2803_add_newsletter_agreement_to_users.php | 22 +++++++++++++++++++ resources/views/adm/users/save.twig | 1 + resources/views/user/settings.twig | 1 + 7 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 database/migrations/2023_09_20_162803_add_newsletter_agreement_to_users.php diff --git a/app/Domain/User/UserSettings.php b/app/Domain/User/UserSettings.php index e0616a9757..64bc0495a4 100644 --- a/app/Domain/User/UserSettings.php +++ b/app/Domain/User/UserSettings.php @@ -18,6 +18,11 @@ public function marketingAgreement(): Html konta albo poprzez wysłanie stosownej wiadomości na adres e-mail: $gdpr lub adres siedziby $_4programmers."); } + public function newsletterAgreement(): Html + { + return new Html('Zgadzam się na otrzymywanie newslettera.'); + } + public function termsAndPrivacyPolicyAgreement(): Html { $terms = 'regulamin'; diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index c5e3e1df8a..87c221bda6 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -40,11 +40,12 @@ public function signup(RegisterForm $form): RedirectResponse $this->transaction(function () use ($request) { $user = User::forceCreate([ - 'name' => $request->input('name'), - 'email' => $request->input('email'), - 'password' => bcrypt($request->input('password')), - 'guest_id' => $request->session()->get('guest_id'), - 'marketing_agreement' => $request->input('marketing_agreement') + 'name' => $request->input('name'), + 'email' => $request->input('email'), + 'password' => bcrypt($request->input('password')), + 'guest_id' => $request->session()->get('guest_id'), + 'marketing_agreement' => $request->input('marketing_agreement'), + 'newsletter_agreement' => true ]); app(MailQueue::class) diff --git a/app/Http/Forms/User/SettingsForm.php b/app/Http/Forms/User/SettingsForm.php index 66fbcf6b4a..3974e4cd3f 100644 --- a/app/Http/Forms/User/SettingsForm.php +++ b/app/Http/Forms/User/SettingsForm.php @@ -100,6 +100,10 @@ public function buildForm(): void 'rules' => 'boolean', 'label' => new TwigHtml((new UserSettings)->marketingAgreement()) ]) + ->add('newsletter_agreement', 'checkbox', [ + 'rules' => 'boolean', + 'label' => new TwigHtml((new UserSettings)->newsletterAgreement()) + ]) ->add('firm', 'text', [ 'rules' => 'nullable|string|max:100', 'label' => 'Nazwa firmy', diff --git a/app/Models/User.php b/app/Models/User.php index 91e516839e..46d9096cf9 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -5,17 +5,17 @@ use Carbon\Carbon; use Coyote\Models\Scopes\ExcludeBlocked; use Coyote\Notifications\ResetPasswordNotification; -use Coyote\Services\Media\Photo; use Coyote\Services\Media\Factory as MediaFactory; +use Coyote\Services\Media\Photo; use Coyote\User\Relation; use Illuminate\Auth\Authenticatable; -use Illuminate\Database\Eloquent\Model; use Illuminate\Auth\Passwords\CanResetPassword; -use Illuminate\Database\Eloquent\SoftDeletes; -use Illuminate\Foundation\Auth\Access\Authorizable; -use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; +use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Foundation\Auth\Access\Authorizable; use Illuminate\Notifications\RoutesNotifications; use Laravel\Passport\HasApiTokens; use NotificationChannels\WebPush\HasPushSubscriptions; @@ -40,6 +40,7 @@ * @property int $allow_sig * @property int $allow_sticky_header * @property bool $marketing_agreement + * @property bool $newsletter_agreement * @property int $birthyear * @property int $reputation * @property string $name diff --git a/database/migrations/2023_09_20_162803_add_newsletter_agreement_to_users.php b/database/migrations/2023_09_20_162803_add_newsletter_agreement_to_users.php new file mode 100644 index 0000000000..c43588eb63 --- /dev/null +++ b/database/migrations/2023_09_20_162803_add_newsletter_agreement_to_users.php @@ -0,0 +1,22 @@ +boolean('newsletter_agreement')->default(false); + }); + } + + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('newsletter_agreement'); + }); + } +} diff --git a/resources/views/adm/users/save.twig b/resources/views/adm/users/save.twig index 25aad5cbba..3bd122158c 100644 --- a/resources/views/adm/users/save.twig +++ b/resources/views/adm/users/save.twig @@ -29,6 +29,7 @@ {{ form_row(form.allow_subscribe) }} {{ form_row(form.allow_sticky_header) }} {{ form_row(form.marketing_agreement) }} + {{ form_row(form.newsletter_agreement) }} {{ form_row(form.delete_photo) }} {{ form_row(form.firm) }} {{ form_row(form.position) }} diff --git a/resources/views/user/settings.twig b/resources/views/user/settings.twig index d086c7754f..a385d69212 100644 --- a/resources/views/user/settings.twig +++ b/resources/views/user/settings.twig @@ -19,6 +19,7 @@
{{ form_row(form.terms) }} {{ form_row(form.marketing_agreement) }} + {{ form_row(form.newsletter_agreement) }} {{ form_row(form.submit) }}