]> _ Git - psq.git/commitdiff
new notifications in DB
authorLouis Jeckel <louis.jeckel@outlook.com>
Wed, 21 Oct 2020 16:36:58 +0000 (18:36 +0200)
committerLouis Jeckel <louis.jeckel@outlook.com>
Wed, 21 Oct 2020 16:36:58 +0000 (18:36 +0200)
21 files changed:
app/EmailTemplate.php
app/Http/Controllers/Auth/VerificationController.php
app/Jobs/CheckForTrialExpirationDates.php
app/Mail/TemplateMail.php
app/Notifications/EmailValidated.php [deleted file]
app/Notifications/JustSubscribed.php [deleted file]
app/Notifications/RegistrationComplete.php [deleted file]
app/Notifications/RegistrationPending.php [deleted file]
app/Notifications/TrialExpired.php [deleted file]
app/Notifications/TrialExpiresSoon.php [deleted file]
app/Notifications/Welcome.php [deleted file]
app/Nova/Actions/SendNotification.php
app/Nova/Actions/StartTrial.php
app/Nova/Actions/SubscribeUser.php
app/Nova/Actions/ValidateAddress.php
app/Nova/EmailTemplate.php
app/Nova/User.php
app/Observers/UserObserver.php
app/PdfFile.php
app/TemplateVariables.php
app/User.php

index 55615be7122115b8bd305e0d94301422a4142796..f5fabd7811e46b338f9515471c0dcfc612e2ae62 100644 (file)
@@ -17,6 +17,17 @@ class EmailTemplate extends Model
     public $timestamps = false;
 
 
+    /**
+     * @param $slug
+     * @return EmailTemplate
+     */
+    public static function findSlug($slug)
+    {
+        return self::query()
+            ->where('slug', $slug)
+            ->firstOrFail();
+    }
+
     /**
      * @param $user
      * @param $content
index cbb8e29f9059335d330124f491e354c7e13e4b38..f637b14244ac22d06bed71cfd5717da3a14829ec 100644 (file)
@@ -3,8 +3,8 @@
 namespace App\Http\Controllers\Auth;
 
 use App\Http\Controllers\Controller;
-use App\Notifications\EmailValidated;
 use App\Providers\RouteServiceProvider;
+use App\User;
 use Illuminate\Foundation\Auth\VerifiesEmails;
 use Illuminate\Http\Request;
 
@@ -47,6 +47,13 @@ class VerificationController extends Controller
      */
     protected function verified(Request $request)
     {
-        $request->user()->notify(new EmailValidated);
+        /** @var User $user */
+        $user = $request->user();
+
+        $template = ($user->self_registered && $user->type === User::TYPE_DISCOVER) ?
+            'email_validated_with_trial' :
+            'email_validated';
+
+        $user->sendEmailFromTemplate($template);
     }
 }
index 96d345a8e24cf547485a8fcbbc4931581efd4d25..e9e07b558d26776ac02fd047e58f08ce559b4dd0 100644 (file)
@@ -2,8 +2,7 @@
 
 namespace App\Jobs;
 
-use App\Notifications\TrialExpired;
-use App\Notifications\TrialExpiresSoon;
+
 use App\User;
 use Carbon\Carbon;
 use Illuminate\Bus\Queueable;
@@ -40,9 +39,9 @@ class CheckForTrialExpirationDates implements ShouldQueue
      */
     public function handle()
     {
-        self::getExpiresSoonProfiles()->map(fn(User $user) => $user->notify(new TrialExpiresSoon));
+//        self::getExpiresSoonProfiles()->map(fn(User $user) => $user->notify(new TrialExpiresSoon));
 
-        self::getLastEditionTodayProfiles()->map(fn(User $user) => $user->notify(new TrialExpired));
+//        self::getLastEditionTodayProfiles()->map(fn(User $user) => $user->notify(new TrialExpired));
     }
 
 
index 27167b194327262a4de4dc005f346bbdf51c71a6..c3012a29a43796fab49fae974ecb373d9f6e463d 100644 (file)
@@ -22,10 +22,12 @@ class TemplateMail extends Mailable
      * Create a new message instance.
      *
      * @param $content
+     * @param $subject
      */
-    public function __construct($content)
+    public function __construct($content, $subject)
     {
         $this->content = $content;
+        $this->subject = $subject;
     }
 
     /**
diff --git a/app/Notifications/EmailValidated.php b/app/Notifications/EmailValidated.php
deleted file mode 100644 (file)
index c7a6a9e..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-
-namespace App\Notifications;
-
-use App\User;
-use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
-use Illuminate\Notifications\Messages\MailMessage;
-use Illuminate\Notifications\Notification;
-
-class EmailValidated extends Notification
-{
-    use Queueable;
-
-    /**
-     * Create a new notification instance.
-     *
-     * @return void
-     */
-    public function __construct()
-    {
-        //
-    }
-
-    /**
-     * Get the notification's delivery channels.
-     *
-     * @param  mixed  $notifiable
-     * @return array
-     */
-    public function via($notifiable)
-    {
-        return ['mail'];
-    }
-
-    /**
-     * Get the mail representation of the notification.
-     *
-     * @param  mixed  $notifiable
-     * @return \Illuminate\Notifications\Messages\MailMessage
-     */
-    public function toMail($notifiable)
-    {
-        return (new MailMessage)
-                    ->subject('Email validé !')
-                    ->line("Votre adresse email à bien été validée.");
-    }
-
-    /**
-     * Get the array representation of the notification.
-     *
-     * @param  mixed  $notifiable
-     * @return array
-     */
-    public function toArray($notifiable)
-    {
-        return [
-            //
-        ];
-    }
-}
diff --git a/app/Notifications/JustSubscribed.php b/app/Notifications/JustSubscribed.php
deleted file mode 100644 (file)
index 0bdadd9..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-<?php
-
-namespace App\Notifications;
-
-use App\Mail\MailMessage;
-use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
-use Illuminate\Notifications\Notification;
-
-class JustSubscribed extends Notification
-{
-    use Queueable;
-
-    /**
-     * Create a new notification instance.
-     *
-     * @return void
-     */
-    public function __construct()
-    {
-        //
-    }
-
-    /**
-     * Get the notification's delivery channels.
-     *
-     * @param  mixed  $notifiable
-     * @return array
-     */
-    public function via($notifiable)
-    {
-        return ['mail'];
-    }
-
-    /**
-     * Get the mail representation of the notification.
-     *
-     * @param  mixed  $notifiable
-     * @return \Illuminate\Notifications\Messages\MailMessage
-     */
-    public function toMail($notifiable)
-    {
-        $message = (new MailMessage)
-                    ->subject('PRESCRIPTION SANTÉ QUOTIDIEN : Abonnement activé !')
-                    ->line('Votre abonnement à PRESCRIPTION SANTÉ QUOTIDIEN est désormais actif !')
-                    ->addTag('just-subscribed');
-
-
-        if($notifiable->reg_complete) {
-            $message->line("Votre compte est déjà activé, vous n'avez rien de plus à faire.");
-        } else {
-            $link = $notifiable->routeWithToken('account.complete-reg', [], now()->addDays(7));
-            $message
-                ->line("Cliquez sur le bouton ci-dessous pour créer un mot de passe et activer votre compte pour ne rater aucun numéro de notre quotidien !")
-                ->action('Créer mon mot de passe', $link)
-                ->line("Cela ne prendra pas plus d'une minute !");
-        }
-
-        return $message;
-
-    }
-
-    /**
-     * Get the array representation of the notification.
-     *
-     * @param  mixed  $notifiable
-     * @return array
-     */
-    public function toArray($notifiable)
-    {
-        return [
-            //
-        ];
-    }
-}
diff --git a/app/Notifications/RegistrationComplete.php b/app/Notifications/RegistrationComplete.php
deleted file mode 100644 (file)
index 5e2c195..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php
-
-namespace App\Notifications;
-
-use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
-use App\Mail\MailMessage;
-use Illuminate\Notifications\Notification;
-
-class RegistrationComplete extends Notification implements ShouldQueue
-{
-    use Queueable;
-
-    /**
-     * Create a new notification instance.
-     *
-     * @return void
-     */
-    public function __construct()
-    {
-        //
-    }
-
-    /**
-     * Get the notification's delivery channels.
-     *
-     * @param  mixed  $notifiable
-     * @return array
-     */
-    public function via($notifiable)
-    {
-        return ['mail'];
-    }
-
-    /**
-     * Get the mail representation of the notification.
-     *
-     * @param  mixed  $notifiable
-     * @return \Illuminate\Notifications\Messages\MailMessage
-     */
-    public function toMail($notifiable)
-    {
-        return (new MailMessage)
-                    ->subject('PRESCRIPTION SANTÉ QUOTIDIEN : Activation réussie !')
-                    ->success()
-                    ->greeting('Cher lecteur,')
-                    ->line("Votre compte à bien été activé !")
-                    ->line("Vous allez pouvoir recevoir les prochains numéros de *Prescription Santé : Le Quotidien*")
-                    ->addTag('reg_complete');
-
-    }
-
-    /**
-     * Get the array representation of the notification.
-     *
-     * @param  mixed  $notifiable
-     * @return array
-     */
-    public function toArray($notifiable)
-    {
-        return [
-            //
-        ];
-    }
-}
diff --git a/app/Notifications/RegistrationPending.php b/app/Notifications/RegistrationPending.php
deleted file mode 100644 (file)
index 6d44511..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-<?php
-
-namespace App\Notifications;
-
-use App\User;
-use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
-use App\Mail\MailMessage;
-use Illuminate\Notifications\Notification;
-
-class RegistrationPending extends Notification implements ShouldQueue
-{
-    use Queueable;
-
-    /**
-     * Create a new notification instance.
-     *
-     * @return void
-     */
-    public function __construct()
-    {
-        //
-    }
-
-    /**
-     * Get the notification's delivery channels.
-     *
-     * @param  mixed  $notifiable
-     * @return array
-     */
-    public function via($notifiable)
-    {
-        return ['mail'];
-    }
-
-    /**
-     * Get the mail representation of the notification.
-     *
-     * @param  User  $notifiable
-     * @return \Illuminate\Notifications\Messages\MailMessage
-     */
-    public function toMail($notifiable)
-    {
-
-        $link = $notifiable->routeWithToken('account.complete-reg', [], now()->addDays(14));
-        return (new MailMessage)
-                    ->subject('[Relance] PRESCRIPTION SANTÉ QUOTIDIEN : Activation en attente')
-                    ->greeting('Cher lecteur,')
-                    ->line("Nous avons remarqué que votre compte n'est toujours pas activé.")
-                    ->line("Veuillez cliquer sur ce lien pour créer votre mot de passe et ne rater aucun numéro de *Prescription Santé : Le Quotidien* !")
-                    ->line("Cela ne vous prendra pas plus d'une minute.")
-                    ->action('Compléter mon inscription', $link)
-                    ->addTag('reg_pending');
-    }
-
-    /**
-     * Get the array representation of the notification.
-     *
-     * @param  mixed  $notifiable
-     * @return array
-     */
-    public function toArray($notifiable)
-    {
-        return [
-            //
-        ];
-    }
-}
diff --git a/app/Notifications/TrialExpired.php b/app/Notifications/TrialExpired.php
deleted file mode 100644 (file)
index 98880f3..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-
-namespace App\Notifications;
-
-use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
-use App\Mail\MailMessage;
-use Illuminate\Notifications\Notification;
-
-class TrialExpired extends Notification
-{
-    use Queueable;
-
-    /**
-     * Create a new notification instance.
-     *
-     * @return void
-     */
-    public function __construct()
-    {
-        //
-    }
-
-    /**
-     * Get the notification's delivery channels.
-     *
-     * @param  mixed  $notifiable
-     * @return array
-     */
-    public function via($notifiable)
-    {
-        return ['mail'];
-    }
-
-    /**
-     * Get the mail representation of the notification.
-     *
-     * @param  mixed  $notifiable
-     * @return \Illuminate\Notifications\Messages\MailMessage
-     */
-    public function toMail($notifiable)
-    {
-        return (new MailMessage)
-                    ->addTag('trial-expired')
-                    ->subject("Votre période découverte est arrivée à son terme !")
-                    ->greeting('Cher Lecteur,')
-                    ->line("Au cours des deux dernières semaines, vous avez reçu gratuitement les éditions de **Prescription Santé Quotidien** dans le cadre de notre offre Découverte.")
-                    ->line("Malheureusement, cette offre, non reconductible, est arrivée à son terme aujourd’hui et l'édition transmise ce matin est donc la dernière. **Vous pouvez dès maintenant nous contacter en cliquant sur le bouton ci-dessous** pour nous préciser le cadre d’un éventuel abonnement, et ce afin de ne pas rater une seule de nos éditions.")
-                    ->action("Nous contacter", route('contact.index'))
-                    ->line("Nous vous répondrons sous 24 heures et vous pourrez ainsi faire un choix éclairé.")
-                    ->line("En espérant vous compter bientôt parmi nos abonnés")
-                    ->salutation("LE RÉDACTEUR EN CHEF, OLIVIER ROBICHON");
-    }
-
-    /**
-     * Get the array representation of the notification.
-     *
-     * @param  mixed  $notifiable
-     * @return array
-     */
-    public function toArray($notifiable)
-    {
-        return [
-            //
-        ];
-    }
-}
diff --git a/app/Notifications/TrialExpiresSoon.php b/app/Notifications/TrialExpiresSoon.php
deleted file mode 100644 (file)
index 209a9a8..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-<?php
-
-namespace App\Notifications;
-
-use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
-use App\Mail\MailMessage;
-use Illuminate\Notifications\Notification;
-
-class TrialExpiresSoon extends Notification
-{
-    use Queueable;
-
-    /**
-     * Create a new notification instance.
-     *
-     * @return void
-     */
-    public function __construct()
-    {
-        //
-    }
-
-    /**
-     * Get the notification's delivery channels.
-     *
-     * @param  mixed  $notifiable
-     * @return array
-     */
-    public function via($notifiable)
-    {
-        return ['mail'];
-    }
-
-    /**
-     * Get the mail representation of the notification.
-     *
-     * @param  mixed  $notifiable
-     * @return \Illuminate\Notifications\Messages\MailMessage
-     */
-    public function toMail($notifiable)
-    {
-        return (new MailMessage)
-                    ->addTag('trial-expires-soon')
-                    ->subject("Votre période découverte expire bientôt !")
-                    ->greeting('Cher Lecteur,')
-                    ->line("Depuis quelques jours vous recevez gratuitement les éditions de **Prescription Santé Quotidien** dans le cadre de notre offre Découverte.")
-                    ->line("Nous espérons que vous appréciez ce média différent à destination des acteurs industriels de la santé et de leurs partenaires.")
-                    ->line("**Dans 48 heures cette offre, non reconductible, arrivera à son terme.** Vous pouvez dès maintenant **nous contacter en cliquant sur le bouton ci-dessous** pour nous préciser le cadre d’un éventuel abonnement, et ce afin de ne pas rater une seule de nos éditions.")
-                    ->action("Nous contacter", route('contact.index'))
-                    ->line("Nous vous répondrons sous 24 heures et vous pourrez ainsi faire un choix éclairé.")
-                    ->line("En espérant vous compter bientôt parmi nos abonnés")
-                    ->salutation("LE RÉDACTEUR EN CHEF, OLIVIER ROBICHON");
-    }
-
-    /**
-     * Get the array representation of the notification.
-     *
-     * @param  mixed  $notifiable
-     * @return array
-     */
-    public function toArray($notifiable)
-    {
-        return [
-            //
-        ];
-    }
-}
diff --git a/app/Notifications/Welcome.php b/app/Notifications/Welcome.php
deleted file mode 100644 (file)
index 1d58a4a..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-
-namespace App\Notifications;
-
-use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
-use App\Mail\MailMessage;
-use Illuminate\Notifications\Notification;
-
-class Welcome extends Notification implements ShouldQueue
-{
-    use Queueable;
-
-    /**
-     * Create a new notification instance.
-     *
-     * @return void
-     */
-    public function __construct()
-    {
-        //
-    }
-
-    /**
-     * Get the notification's delivery channels.
-     *
-     * @param  mixed  $notifiable
-     * @return array
-     */
-    public function via($notifiable)
-    {
-        return ['mail'];
-    }
-
-    /**
-     * Get the mail representation of the notification.
-     *
-     * @param  mixed  $notifiable
-     * @return \Illuminate\Notifications\Messages\MailMessage
-     */
-    public function toMail($notifiable)
-    {
-        $link = $notifiable->routeWithToken('account.index', [], now()->addDays(7));
-        return (new MailMessage)
-                    ->subject('PRESCRIPTION SANTÉ QUOTIDIEN : Votre nouvelle plateforme')
-                    ->greeting('Cher Lecteur abonné à notre « petit » quotidien !')
-                    ->line("Ce dernier est justement de moins en moins petit et nous allons donc vous faire profiter, dès lundi d’une nouvelle formule dont le contenu comme la forme seront tout à la fois plus riches et plus « agréables » à lire.")
-                    ->line("Mais pour cela, nous devons vous demander un tout petit effort de quelques secondes à peine !")
-                    ->line("En cliquant sur le bouton ci-dessous vous devez vous créer un mot de passe.")
-                    ->action('Créer mon mot de passe', $link)
-                    ->line("Ainsi dès Lundi prochain vous pourrez accéder en un clic à votre quotidien préféré.")
-                    ->line("A très vite, donc ! ")
-                    ->salutation("OLIVIER ROBICHON")
-                    ->addTag('welcome');
-    }
-
-    /**
-     * Get the array representation of the notification.
-     *
-     * @param  mixed  $notifiable
-     * @return array
-     */
-    public function toArray($notifiable)
-    {
-        return [
-            //
-        ];
-    }
-}
index 8155480f70372b77bcaec5a9dce942ef20c3a6a3..b24e3e56c50fe60cfe50547343f2cd0f10eaa379 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace App\Nova\Actions;
 
+use App\EmailTemplate;
 use App\User;
 use FontLib\Table\Type\name;
 use Illuminate\Bus\Queueable;
@@ -34,7 +35,9 @@ class SendNotification extends Action
      */
     public function handle(ActionFields $fields, Collection $models)
     {
-        $models->map(fn(User $user) => $user->notify(new $fields->notification));
+
+        $models->map(fn(User $user) => $user->sendEmailFromTemplate($fields->notification));
+
         return Action::message(sprintf('%d messages envoyés', $models->count()));
     }
 
@@ -45,12 +48,12 @@ class SendNotification extends Action
      */
     public function fields()
     {
+        $options = EmailTemplate::query()
+            ->pluck('name', 'slug')
+            ->toArray();
+
         return [
-            Select::make('Notification')->options([
-//                Notifications\Welcome::class => 'Message de bienvenue',
-                Notifications\RegistrationPending::class => 'Rappel',
-                Notifications\JustSubscribed::class => 'Message abonnement activé'
-            ])
+            Select::make('Notification')->options($options)
         ];
     }
 }
index 3c9fad6727199871aaa32766bb0079b4cdbe6b6f..7be1b45a0093c04313c432bdf4eb3ba84157969f 100644 (file)
@@ -3,12 +3,16 @@
 namespace App\Nova\Actions;
 
 use App\User;
+use Carbon\Carbon;
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Queue\InteractsWithQueue;
 use Illuminate\Support\Collection;
 use Laravel\Nova\Actions\Action;
 use Laravel\Nova\Fields\ActionFields;
+use Laravel\Nova\Fields\Date;
+use Laravel\Nova\Fields\Number;
+use Laravel\Nova\Fields\Trix;
 
 class StartTrial extends Action
 {
@@ -16,7 +20,8 @@ class StartTrial extends Action
 
     public $showOnTableRow = true;
     public $confirmButtonText = "Appliquer";
-    public $name = "Démarrer période de découverte";
+    public $name = "Période de découverte";
+
 
     public function __construct()
     {
@@ -35,7 +40,20 @@ class StartTrial extends Action
      */
     public function handle(ActionFields $fields, Collection $models)
     {
-        $models->map->startDiscover();
+        $endDate = Carbon::parse($fields->end_date)->endOfDay();
+        $models->map(function(User $user) use($endDate){
+            $wasOnTrial = $user->onTrial() || $user->isOnDiscoverUser();
+
+            if($user->reg_complete) {
+                $user->startTrial($endDate);
+            } else {
+                $user->startDiscover($endDate);
+            }
+
+            if(! $wasOnTrial){
+                $user->sendEmailFromTemplate('start_trial');
+            }
+        });
 
         return Action::message(sprintf("La période de découverte à bien été activée pour %d utilisteur(s)", $models->count()));
     }
@@ -47,6 +65,10 @@ class StartTrial extends Action
      */
     public function fields()
     {
-        return [];
+        return [
+            Date::make('Date de fin', 'end_date')
+                ->withMeta(['value' => now()->addMonth()->format('Y-m-d')])
+                ->firstDayOfWeek(1)
+        ];
     }
 }
index 215fd259672d37bc41d718b4db23b0a2f2f0ca74..995d5dea84b61871b3b910d0085e5b60c7c048f3 100644 (file)
@@ -38,7 +38,10 @@ class SubscribeUser extends Action
             $user->organization()->associate(\App\Organization::query()->findOrFail($fields->org_id));
             $user->save();
             if(! $fields->dont_notify) {
-                $user->notify(new JustSubscribed);
+                $template = $user->reg_complete ?
+                    'just_subscribed_reg_ok' :
+                    'just_subscribed_need_reg';
+                $user->sendEmailFromTemplate($template);
             }
         });
 
index c82905f086cb6d1c83b7621774753e75768a8e58..e52ea18556a612242d944b3f14e28db443178371 100644 (file)
@@ -13,6 +13,7 @@ class ValidateAddress extends Action implements ShouldQueue
 {
     use InteractsWithQueue, Queueable;
 
+    public $name = "Validation Mailgun";
     /**
      * Perform the action on the given models.
      *
index c0db024d1a0cc5ea2c428324a27bc382bf7f9a0f..ba51fbcf02f7ecaac4a5c217d92965439d24d655 100644 (file)
@@ -57,7 +57,7 @@ class EmailTemplate extends Resource
             Text::make('Nom code', 'slug')->hideFromIndex(),
             Text::make('Nom', 'name'),
             Text::make('Sujet', 'subject'),
-            CKEditor5Classic::make('Contenu', 'content')->alwaysShow(),
+            Trix::make('Contenu', 'content')->alwaysShow(),
         ];
     }
 
index ac29fe409e332dc25002405f0b06466b41d5a6ac..0fdac4b0a956a336058ef705ec77a66b8077ba0e 100644 (file)
@@ -194,7 +194,7 @@ class User extends Resource
             new ImportUsers,
             new SendNotification,
             new StartTrial,
-            new VerifyEmail,
+//            new VerifyEmail,
             new ValidateAddress,
         ];
     }
index d39dc178ad5cb83b75d1abc5cf6a7e9c9a30c67b..ffb38c229752342dd0771d92dab0afdf92d19402 100644 (file)
@@ -2,7 +2,6 @@
 
 namespace App\Observers;
 
-use App\Notifications\RegistrationComplete;
 use App\User;
 
 class UserObserver
@@ -40,7 +39,7 @@ class UserObserver
             $user->isDirty('reg_complete') &&
             $user->getOriginal()['reg_complete'] === false
         ) {
-            $user->notify(new RegistrationComplete);
+            $user->sendEmailFromTemplate('reg_complete');
             \Session::flash('registration_complete');
         }
 
index d03f764c0fe4505555b92a17a6d07706b60761cd..90d065f0d7a68819d9387bbc6225bcf681fab2b4 100644 (file)
@@ -390,7 +390,7 @@ class PdfFile extends TwillModel implements Sortable
         if($user->receives_pdf) {
             return $this->getDownloadUrl();
         }
-        return ($user->type === User::TYPE_DISCOVER && !$user->self_registered) ?
+        return ($user->type === User::TYPE_DISCOVER && !$user->reg_complete) ?
             $this->getSignedUrl($user) :
             $this->getUrlWithToken($user);
 
index a7c5d2db3ba40f604f4291a1912561ddbfdfc5f3..f9f3cded47b5b6564cd0fc8205a233560782659b 100644 (file)
@@ -4,6 +4,7 @@
 namespace App;
 
 
+use App\Mail\TemplateMail;
 use Illuminate\Support\Str;
 
 trait TemplateVariables
@@ -15,6 +16,21 @@ trait TemplateVariables
     ];
 
 
+    /**
+     * @param string|EmailTemplate $template
+     */
+    public function sendEmailFromTemplate($template)
+    {
+        if(is_string($template)) {
+            $template = EmailTemplate::findSlug($template);
+        }
+
+        \Mail::to($this)->send(new TemplateMail(
+            $template->fillFor($this),
+            $template->subject
+        ));
+    }
+
     /**
      * Determine if a getter exists for a template attribute.
      *
@@ -59,12 +75,40 @@ trait TemplateVariables
      * @return string
      * @throws \Throwable
      */
-    public function getMyAccountTemplate()
+    public function getMyAccountButtonTemplate()
     {
         return EmailTemplate::button(
-            $this->routeWithToken('account.index'),
+            $this->routeWithToken('account.index', [], now()->addDays(7)),
             'Accéder à mon compte'
         );
     }
 
+
+    /**
+     * @return string
+     * @throws \Throwable
+     */
+    public function getCompleteRegistrationButtonTemplate()
+    {
+        return EmailTemplate::button(
+            $this->routeWithToken('account.complete-reg', [], now()->addDays(7)),
+            'Créer mon mot de passe'
+        );
+
+    }
+
+
+    /**
+     * @return string
+     * @throws \Throwable
+     */
+    public function getContactButtonTemplate()
+    {
+        return EmailTemplate::button(
+            route('contact.index'),
+            'Nous contacter'
+        );
+
+    }
+
 }
index 246d820500c70415cc4871185441ddb5ee5e687a..251a5d70b1d97d47f99dc5ce3573960abe5688d8 100644 (file)
@@ -13,7 +13,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
 use Illuminate\Foundation\Auth\VerifiesEmails;
 use Illuminate\Notifications\Notifiable;
 use Illuminate\Support\Arr;
-use Illuminate\Support\Carbon;
+use Carbon\Carbon;
 use Laravel\Cashier\Billable;
 use Laravel\Scout\Searchable;
 
@@ -70,6 +70,7 @@ class User extends Authenticatable implements MustVerifyEmail
         'position',
         'wants_pdf',
         'accepts_polls',
+        'self_registered'
     ];
 
     /**
@@ -105,11 +106,12 @@ class User extends Authenticatable implements MustVerifyEmail
     /**
      * Trial duration in days
      */
-    public const TRIAL_DURATION_DAYS = 15;
+    public const TRIAL_DURATION_DAYS = 30;
+
     /**
      * Discover duration in days
      */
-    public const DISCOVER_DURATION_DAYS = 15;
+    public const DISCOVER_DURATION_DAYS = 30;
 
     /**
      * Possible Statuses
@@ -263,19 +265,21 @@ class User extends Authenticatable implements MustVerifyEmail
 
     /**
      * Starts trial period
+     * @param Carbon|null $endDate
      */
-    public function startTrial(): void
+    public function startTrial(?Carbon $endDate = null): void
     {
-        $this->trial_ends_at = now()->addDays(self::TRIAL_DURATION_DAYS)->endOfDay();
+        $this->trial_ends_at = $endDate ?? now()->addDays(self::TRIAL_DURATION_DAYS)->endOfDay();
         $this->save();
     }
 
     /**
      * Starts discover period
+     * @param Carbon|null $endDate
      */
-    public function startDiscover(): void
+    public function startDiscover(?Carbon $endDate = null): void
     {
-        $this->discover_ends_at = now()->addDays(self::DISCOVER_DURATION_DAYS)->endOfDay();
+        $this->discover_ends_at = $endDate ?? now()->addDays( self::DISCOVER_DURATION_DAYS)->endOfDay();
         $this->type = self::TYPE_DISCOVER;
         $this->save();
     }