]> _ Git - psq.git/commitdiff
email tempaltes
authorLouis Jeckel <louis.jeckel@outlook.com>
Tue, 20 Oct 2020 18:08:30 +0000 (20:08 +0200)
committerLouis Jeckel <louis.jeckel@outlook.com>
Tue, 20 Oct 2020 18:08:30 +0000 (20:08 +0200)
17 files changed:
.idea/lettre-pharma.iml
.idea/php.xml
app/EmailTemplate.php [new file with mode: 0644]
app/Http/Controllers/Auth/RegisterController.php
app/Http/Controllers/DebugController.php [new file with mode: 0644]
app/Mail/TemplateMail.php [new file with mode: 0644]
app/Nova/EmailTemplate.php [new file with mode: 0644]
app/TemplateVariables.php [new file with mode: 0644]
app/User.php
composer.json
composer.lock
config/ckeditor5Classic.php [new file with mode: 0644]
database/migrations/2020_10_20_132301_create_email_templates_table.php [new file with mode: 0644]
resources/views/auth/register.blade.php
resources/views/emails/template.blade.php [new file with mode: 0644]
resources/views/home/index.blade.php
routes/web.php

index 958a20cf306c6b146340989f66356c607da7a206..ec9195805e7459e3836962cbf39e826f8e9eb6b7 100644 (file)
@@ -38,6 +38,7 @@
       <excludeFolder url="file://$MODULE_DIR$/vendor/masterminds/html5" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/maximebf/debugbar" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/moneyphp/money" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/numaxlab/nova-ckeditor5-classic" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/nyholm/psr7" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/paragonie/random_compat" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/paragonie/sodium_compat" />
index 89cd65d16b5cc62d15e4678b8bf6ed30ad478963..c3e55ffea6fb163d41203a9adf59b0e58f291d8e 100644 (file)
       <path value="$PROJECT_DIR$/vendor/judev/php-htmltruncator" />
       <path value="$PROJECT_DIR$/vendor/html2text/html2text" />
       <path value="$PROJECT_DIR$/vendor/psq/psq-theme" />
+      <path value="$PROJECT_DIR$/vendor/numaxlab/nova-ckeditor5-classic" />
     </include_path>
   </component>
   <component name="PhpInterpreters">
diff --git a/app/EmailTemplate.php b/app/EmailTemplate.php
new file mode 100644 (file)
index 0000000..55615be
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Str;
+
+/**
+ * Class EmailTemplate
+ * @package App
+ * @property string $subject
+ * @property string $content
+ * @property string $slug
+ */
+class EmailTemplate extends Model
+{
+    public $timestamps = false;
+
+
+    /**
+     * @param $user
+     * @param $content
+     * @return string
+     */
+    public static function fillWithContentFor($user, $content)
+    {
+        $content = preg_replace('/<a /', '<a target="_blank"', $content);
+
+        return preg_replace_callback('/%[^(% )]*%/', function($matches) use($user){
+
+            $match = Str::before(Str::after($matches[0], '%'), '%');
+
+            return $user->templateAttribute($match);
+
+        }, $content);
+
+    }
+
+    /**
+     * @param User $user
+     * @return string
+     */
+    public function fillFor(User $user)
+    {
+        return self::fillWithContentFor($user, $this->content);
+    }
+
+
+    /**
+     * @param $url
+     * @param $label
+     * @param null $color
+     * @return string
+     * @throws \Throwable
+     */
+    public static function button($url, $label, $color = null)
+    {
+        return view('vendor.mail.html.button', [
+            'url' => $url,
+            'slot' => $label,
+            'color' => $color
+        ])->render();
+    }
+}
index 5c9ec415086844141a189a2c1ed807830ce4bb86..c25e7ac13e15a61f86aca3c121fd62c58daf566c 100644 (file)
@@ -90,6 +90,11 @@ class RegisterController extends Controller
      */
     protected function create(array $data)
     {
+
+        $type = request()->boolean('trial') ?
+            User::TYPE_DISCOVER :
+            User::TYPE_PLATFORM_ONLY;
+
         /** @var User $user */
         $user = User::query()->updateOrCreate(
             [
@@ -101,16 +106,11 @@ class RegisterController extends Controller
                 'employer' => $data['employer'],
                 'password' => Hash::make($data['password']),
                 'reg_complete' => true,
-                'type' => User::TYPE_DISCOVER,
+                'type' => $type,
                 'self_registered' => true,
             ]
         );
 
-        if(! request()->boolean('no_trial')){
-            $user->startTrial();
-        }
-
-//        $user->sendEmailVerificationNotification();
 
         return $user;
     }
diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.php
new file mode 100644 (file)
index 0000000..5300018
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\EmailTemplate;
+use App\Mail\TemplateMail;
+use App\User;
+use Illuminate\Http\Request;
+
+class DebugController extends Controller
+{
+    public function test()
+    {
+        return new TemplateMail(EmailTemplate::first()->fillFor(User::first()));
+    }
+}
diff --git a/app/Mail/TemplateMail.php b/app/Mail/TemplateMail.php
new file mode 100644 (file)
index 0000000..27167b1
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+namespace App\Mail;
+
+use App\EmailTemplate;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Mail\Mailable;
+use Illuminate\Queue\SerializesModels;
+
+class TemplateMail extends Mailable
+{
+    use Queueable, SerializesModels;
+
+    /**
+     * @var string
+     */
+    public $content;
+
+
+    /**
+     * Create a new message instance.
+     *
+     * @param $content
+     */
+    public function __construct($content)
+    {
+        $this->content = $content;
+    }
+
+    /**
+     * Build the message.
+     *
+     * @return $this
+     */
+    public function build()
+    {
+        return $this->markdown('emails.template');
+    }
+}
diff --git a/app/Nova/EmailTemplate.php b/app/Nova/EmailTemplate.php
new file mode 100644 (file)
index 0000000..c0db024
--- /dev/null
@@ -0,0 +1,107 @@
+<?php
+
+namespace App\Nova;
+
+use Illuminate\Http\Request;
+use Laravel\Nova\Fields\ID;
+use Laravel\Nova\Fields\Text;
+use Laravel\Nova\Fields\Trix;
+use Laravel\Nova\Http\Requests\NovaRequest;
+use NumaxLab\NovaCKEditor5Classic\CKEditor5Classic;
+
+class EmailTemplate extends Resource
+{
+    /**
+     * The model the resource corresponds to.
+     *
+     * @var string
+     */
+    public static $model = \App\EmailTemplate::class;
+
+    public static $group = "Emails";
+
+
+    /**
+     * The single value that should be used to represent the resource when being displayed.
+     *
+     * @var string
+     */
+    public static $title = 'name';
+
+
+    /**
+     * @return string
+     */
+    public static function label()
+    {
+        return "Modèles d'email";
+    }
+
+    /**
+     * @return string
+     */
+    public static function singularLabel()
+    {
+        return "Modèle d'email";
+    }
+
+    /**
+     * Get the fields displayed by the resource.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return array
+     */
+    public function fields(Request $request)
+    {
+        return [
+            Text::make('Nom code', 'slug')->hideFromIndex(),
+            Text::make('Nom', 'name'),
+            Text::make('Sujet', 'subject'),
+            CKEditor5Classic::make('Contenu', 'content')->alwaysShow(),
+        ];
+    }
+
+    /**
+     * Get the cards available for the request.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return array
+     */
+    public function cards(Request $request)
+    {
+        return [];
+    }
+
+    /**
+     * Get the filters available for the resource.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return array
+     */
+    public function filters(Request $request)
+    {
+        return [];
+    }
+
+    /**
+     * Get the lenses available for the resource.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return array
+     */
+    public function lenses(Request $request)
+    {
+        return [];
+    }
+
+    /**
+     * Get the actions available for the resource.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return array
+     */
+    public function actions(Request $request)
+    {
+        return [];
+    }
+}
diff --git a/app/TemplateVariables.php b/app/TemplateVariables.php
new file mode 100644 (file)
index 0000000..a7c5d2d
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+
+
+namespace App;
+
+
+use Illuminate\Support\Str;
+
+trait TemplateVariables
+{
+    protected $templateVariables = [
+        'first_name',
+        'last_name',
+        'name',
+    ];
+
+
+    /**
+     * Determine if a getter exists for a template attribute.
+     *
+     * @param string $key
+     * @return bool
+     */
+    public function hasTemplateGetter(string $key)
+    {
+        return method_exists($this, 'get'.Str::studly($key).'Template');
+    }
+
+
+    /**
+     * Get the value of a template attribute using its getter.
+     *
+     * @param string $key
+     * @return mixed
+     */
+    public function templateAttribute(string $key, $default = null)
+    {
+        $snake = Str::snake($key);
+        if(in_array($snake, $this->templateVariables)) {
+            return $this->{$snake};
+        }
+
+        return $this->hasTemplateGetter($key) ?
+            $this->{'get'.Str::studly($key).'Template'}() :
+            $default;
+    }
+
+
+    /**
+     * @return string
+     * @throws \Throwable
+     */
+    public function getLoginButtonTemplate()
+    {
+        return EmailTemplate::button(route('login'), 'Login');
+    }
+
+    /**
+     * @return string
+     * @throws \Throwable
+     */
+    public function getMyAccountTemplate()
+    {
+        return EmailTemplate::button(
+            $this->routeWithToken('account.index'),
+            'Accéder à mon compte'
+        );
+    }
+
+}
index 111e36384ed8d2d89ffac3805c2fe0f6dfdc9b4c..246d820500c70415cc4871185441ddb5ee5e687a 100644 (file)
@@ -4,7 +4,6 @@ namespace App;
 
 
 use App\Notifications\EmailValidated;
-use DemeterChain\B;
 use Illuminate\Contracts\Auth\MustVerifyEmail;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -45,6 +44,7 @@ class User extends Authenticatable implements MustVerifyEmail
     use Notifiable;
     use Searchable;
     use Billable;
+    use TemplateVariables;
 
     /**
      * The attributes that are mass assignable.
@@ -160,6 +160,7 @@ class User extends Authenticatable implements MustVerifyEmail
     public const TYPE_PROSPECT = 1;
     public const TYPE_SPECIAL = 2;
     public const TYPE_DISCOVER = 3;
+    public const TYPE_PLATFORM_ONLY = 4;
 
     /**
      * @return array
index 4a34a45107108693386eaa9c0de1f527b235713d..3e4e85c3987b70472c09a79e4d5fcd0858202b2f 100644 (file)
@@ -36,6 +36,7 @@
         "league/html-to-markdown": "^4.9",
         "mailgun/mailgun-php": "^3.0",
         "masterminds/html5": "^2.7",
+        "numaxlab/nova-ckeditor5-classic": "^1.1",
         "nyholm/psr7": "^1.2",
         "psq/psq-theme": "*",
         "pusher/pusher-php-server": "~4.0",
index 99992a6af490a4fa05195bebf4e00cb68077ac59..c3ddfae9fcc5d0fbd447f1eda755695d9a48ad71 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "d48521f562f0e300ac0313ea4875d488",
+    "content-hash": "ca6ddddface6393f6a339cd2a7233c9b",
     "packages": [
         {
             "name": "algolia/algoliasearch-client-php",
             ],
             "time": "2020-08-18T19:48:01+00:00"
         },
+        {
+            "name": "numaxlab/nova-ckeditor5-classic",
+            "version": "1.1.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/numaxlab/nova-ckeditor5-classic.git",
+                "reference": "1a2f045b5df699ada4bae055a0a5c331c74d3c61"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/numaxlab/nova-ckeditor5-classic/zipball/1a2f045b5df699ada4bae055a0a5c331c74d3c61",
+                "reference": "1a2f045b5df699ada4bae055a0a5c331c74d3c61",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=7.1.0"
+            },
+            "type": "library",
+            "extra": {
+                "laravel": {
+                    "providers": [
+                        "NumaxLab\\NovaCKEditor5Classic\\FieldServiceProvider"
+                    ]
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "NumaxLab\\NovaCKEditor5Classic\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "description": "A Laravel Nova CKEditor5 Classic Field.",
+            "keywords": [
+                "ckeditor5",
+                "laravel",
+                "nova",
+                "wysiwyg"
+            ],
+            "time": "2020-02-17T15:42:14+00:00"
+        },
         {
             "name": "nyholm/psr7",
             "version": "1.3.0",
diff --git a/config/ckeditor5Classic.php b/config/ckeditor5Classic.php
new file mode 100644 (file)
index 0000000..5b8f73a
--- /dev/null
@@ -0,0 +1,107 @@
+<?php
+return [
+
+    /*
+    |--------------------------------------------------------------------------------
+    | CKEditor Options
+    |--------------------------------------------------------------------------------
+    |
+    | To view a list of all available options checkout the CKEditor API documentation
+    | https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/configuration.html
+    |
+    */
+
+    'options' => [
+        'language' => 'fr',
+        'toolbar' => [
+            'Heading',
+            'Bold',
+            'Italic',
+            'fontColor',
+            'fontSize',
+            '-',
+            'Link',
+            '-',
+            'NumberedList',
+            'BulletedList',
+            'BlockQuote',
+            '-',
+            'MediaEmbed',
+            'imageUpload',
+        ],
+        'image' => [
+            'toolbar' => [
+                'imageTextAlternative', '|',
+                'imageStyle:alignLeft',
+                'imageStyle:full',
+                'imageStyle:alignRight'
+            ],
+            'styles' => [
+                // This option is equal to a situation where no style is applied.
+                'full',
+                // This represents an image aligned to the left.
+                'alignLeft',
+                // This represents an image aligned to the right.
+                'alignRight',
+            ]
+        ],
+        'fontColor' => [
+            'colors' => [
+                [
+                    'label' => 'psq_red',
+                    'color' => '#d04d4a',
+                ],
+                [
+                    'label' => 'psq_blue',
+                    'color' => '#074e9c',
+                ],
+                [
+                    'label' => 'psq_light_blue',
+                    'color' => '#cddceb',
+                ],
+                [
+                    'label' => 'psq_purple',
+                    'color' => '#AD5ED3',
+                ],
+                [
+                    'label' => 'psq_cyan',
+                    'color' => '#288ed7',
+                ],
+                [
+                    'label' => 'psq_magenta',
+                    'color' => '#ce317c',
+                ],
+                [
+                    'label' => 'psq_orange',
+                    'color' => '#e79817',
+                ],
+                [
+                    'label' => 'psq_grey',
+                    'color' => '#546983',
+                ],
+                [
+                    'label' => 'psq_denim',
+                    'color' => '#0c2c50',
+                ],
+                [
+                    'label' => 'psq_green',
+                    'color' => '#41BD53',
+                ],
+                [
+                    'label' => 'psq_mag_blue',
+                    'color' => '#2a6ba3',
+                ],
+
+            ]
+
+        ],
+        'heading' => [
+            'options' => [
+                [ 'model' => 'paragraph', 'title' => 'Paragraph', 'class' => 'ck-heading_paragraph' ],
+                [ 'model' => 'heading1', 'view' => 'h2', 'title' => 'Titre 1', 'class' => 'ck-heading_heading1' ],
+                [ 'model' => 'heading2', 'view' => 'h3', 'title' => 'Titre 2', 'class' => 'ck-heading_heading2' ]
+            ]
+        ],
+    ]
+
+];
diff --git a/database/migrations/2020_10_20_132301_create_email_templates_table.php b/database/migrations/2020_10_20_132301_create_email_templates_table.php
new file mode 100644 (file)
index 0000000..8f385ca
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateEmailTemplatesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('email_templates', function (Blueprint $table) {
+            $table->id();
+            $table->string('slug');
+            $table->string('name');
+            $table->text('subject')->nullable();
+            $table->text('content');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('email_templates');
+    }
+}
index a1961d0c9b6398e5125c109e59b7ce9f5ebcb382..ad6f4cfe229b5bd8449c359d838d81d19f7586b1 100644 (file)
                         <div class="form-group row">
                             <div class="col-md-6 offset-md-4">
                                 <div class="form-check">
-                                    <input class="form-check-input" type="checkbox" id="no_trial" name="no_trial" {{old('no_trial', false) ? 'checked' : ''}}>
+                                    <input class="form-check-input" type="checkbox" id="trial" name="trial" {{old('trial', false) ? 'checked' : ''}}>
 
-                                    <label class="form-check-label" for="no_trial">
-                                        Je ne souhaite PAS reçevoir les prochains numéros gratuitement pednant 2 semaines.
+                                    <label class="form-check-label" for="trial">
+                                        Je souhaite demander l'activation d'une période d'essai pour reçevoir gratuitement les prochains numéros de PSQ.
                                     </label>
                                 </div>
 
diff --git a/resources/views/emails/template.blade.php b/resources/views/emails/template.blade.php
new file mode 100644 (file)
index 0000000..11f1524
--- /dev/null
@@ -0,0 +1,4 @@
+@component('mail::message')
+{!! $content !!}
+@endcomponent
+
index 3dd58a61ff3960e01e459d1ef08b2bd1cc989ec8..f64b4a256b93b9ad6269f6fd080dceae3e0f5a74 100644 (file)
@@ -29,7 +29,7 @@
                 </div>
         @endif
 
-    <h1>L'actualité à la une de notre quotidien</h1>
+    <h1>L'actualité du médicament à la une de notre quotidien</h1>
     <div class="row justify-content-center pt-3">
         <div class="col-md-4">
             <ul class="leaders">
index 66e046d92f59468fa86f46cbda651418b5f5dff4..809f4326315ae5d1eb7b37fc9ab318661a3f1b6a 100644 (file)
@@ -133,3 +133,7 @@ Route::domain('{client_domains}')->group(function() {
     });
 });
 
+
+if(config('app.env') === 'local') {
+    Route::get('debug', 'DebugController@test');
+}