diff --git a/app/Console/Commands/CreateAdmin.php b/app/Console/Commands/CreateAdmin.php new file mode 100644 index 0000000..5b6d448 --- /dev/null +++ b/app/Console/Commands/CreateAdmin.php @@ -0,0 +1,102 @@ +ask('Type the wanted user email', 'equipe.web@ldc.fr'); + $validator = Validator::make(['email' => $tmp], [ + 'email' => 'required|unique:users,email|email:rfc,dns' + ]); + $validator->validate(); + $email = $tmp; + } catch (ValidationException $e) { + $this->error(sprintf( + 'Please provide a valid email %s', + \implode(',', collect($e->errors())->flatten()->all()) + )); + continue; + } + } + $firstname = null; + while (is_null($firstname)) { + try { + $tmp = $this->ask('Type the wanted user firstname', 'Admin'); + $validator = Validator::make(['firstname' => $tmp], [ + 'firstname' => 'required|min:5,max:255' + ]); + $validator->validate(); + $firstname = $tmp; + } catch (ValidationException $e) { + $this->error(sprintf( + 'Please provide a valid firstname %s', + \implode(',', collect($e->errors())->flatten()->all()) + )); + continue; + } + } + + $lastname = null; + while (is_null($lastname)) { + try { + $tmp = $this->ask('Type the wanted user lastname', 'Saïtama'); + $validator = Validator::make(['lastname' => $tmp], [ + 'lastname' => 'required|min:5,max:255' + ]); + $validator->validate(); + $lastname = $tmp; + } catch (ValidationException $e) { + $this->error(sprintf( + 'Please provide a valid lastname %s', + \implode(',', collect($e->errors())->flatten()->all()) + )); + continue; + } + } + + $password = $this->secret('Type the wanted user password'); + + $admin = new User([ + 'lastname' => $lastname, + 'firstname' => $firstname, + 'email' => $email, + 'password' => $password + ]); + $admin->saveOrFail(); + + $this->info('User created.'); + return 0; + } +} diff --git a/app/Console/Commands/UserCreate.php b/app/Console/Commands/UserCreate.php deleted file mode 100644 index a198eda..0000000 --- a/app/Console/Commands/UserCreate.php +++ /dev/null @@ -1,50 +0,0 @@ -ask('What is the firstname?'); - $lastname = $this->ask('What is the lastname?'); - $email = $this->ask('What is the email?'); - $pwd = $this->secret('What is the password?'); - - $user = new User(); - $user->firstname = $firstname; - $user->lastname = $lastname; - $user->email = $email; - $user->password = Hash::make($pwd); - $user->save(); - - $this->info('User created.'); - return 0; - } -} diff --git a/app/Http/Controllers/Api/V2/StatsController.php b/app/Http/Controllers/Api/V2/StatsController.php index 174cbd8..e1fcc5f 100644 --- a/app/Http/Controllers/Api/V2/StatsController.php +++ b/app/Http/Controllers/Api/V2/StatsController.php @@ -71,7 +71,7 @@ class StatsController extends Controller ->get()->map(function ($custAnswer) { return [ 'answer_id' => $custAnswer->answer_id, - 'created_at' => $custAnswer->created_at->format('Y-m-d'), + 'created_at' => $custAnswer->created_at->isoFormat('YYYY-MM-DD'), ]; })->groupBy(['created_at', 'answer_id'])->map(function ($day) { return $day->map(function ($custAnswers) { @@ -80,7 +80,7 @@ class StatsController extends Controller }); do { - $currentDate = $start->format('Y-m-d'); + $currentDate = $start->isoFormat('YYYY-MM-DD'); /** @var \Illuminate\Support\Collection $answersByDays */ if (!$answersByDays->has($currentDate)) { $answersByDays->put( diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php index 05b4482..8300965 100644 --- a/app/Http/Controllers/CustomerController.php +++ b/app/Http/Controllers/CustomerController.php @@ -232,7 +232,7 @@ class CustomerController extends Controller 'Content-Disposition', sprintf( 'attachment; filename="Export pour newsletter %s %s.csv"', - Carbon::now()->format('d-m-Y_H-i'), + Carbon::now()->isoFormat('DD-MM-YYYY_HH-mm'), Str::slug($exportType) ) ); diff --git a/app/Http/Controllers/QuestionController.php b/app/Http/Controllers/QuestionController.php index 516ac58..abbcfe5 100644 --- a/app/Http/Controllers/QuestionController.php +++ b/app/Http/Controllers/QuestionController.php @@ -233,7 +233,7 @@ class QuestionController extends Controller 'Content-Disposition', sprintf( 'attachment; filename="Export pour newsletter %s %s.csv"', - Carbon::now()->format('d-m-Y_H-i'), + Carbon::now()->isoFormat('DD-MM-YYYY_HH-mm'), Str::slug($brand->name) ) ); @@ -248,6 +248,13 @@ class QuestionController extends Controller $w->insertOne([]); } + // * Push empty line if nothing to export + if (empty($results)) { + $w->insertOne([ + 'Aucune question pour cette marque' + ]); + } + /* We create a callable to output the CSV in chunk with Symfony StreamResponse you can flush the body content if necessary diff --git a/app/Http/Controllers/StatsController.php b/app/Http/Controllers/StatsController.php index aa19e6f..1b449b4 100644 --- a/app/Http/Controllers/StatsController.php +++ b/app/Http/Controllers/StatsController.php @@ -62,7 +62,7 @@ class StatsController extends Controller foreach ($stats as $stat) { $cols = [ - $stat->created_at->format('Y-m-d'), + $stat->created_at->isoFormat('YYYY-MM-DD'), $stat->brand->name ]; foreach ($columns as $colname) { @@ -161,7 +161,7 @@ class StatsController extends Controller ->get()->map(function ($custAnswer) { return [ 'answer_id' => $custAnswer->answer_id, - 'created_at' => $custAnswer->created_at->format('Y-m-d'), + 'created_at' => $custAnswer->created_at->isoFormat('YYYY-MM-DD'), ]; })->groupBy(['created_at', 'answer_id'])->map(function ($day) { return $day->map(function ($custAnswers) { @@ -170,7 +170,7 @@ class StatsController extends Controller }); do { - $currentDate = $start->format('Y-m-d'); + $currentDate = $start->isoFormat('YYYY-MM-DD'); /** @var \Illuminate\Support\Collection $answersByDays */ if (!$answersByDays->has($currentDate)) { $answersByDays->put( diff --git a/app/Http/Resources/Api/V2/BrandStatsResource.php b/app/Http/Resources/Api/V2/BrandStatsResource.php index 25fdf5a..582ff2e 100644 --- a/app/Http/Resources/Api/V2/BrandStatsResource.php +++ b/app/Http/Resources/Api/V2/BrandStatsResource.php @@ -19,7 +19,7 @@ class BrandStatsResource extends JsonResourceCollection return [ 'stats' => $this->collection->map(function (BrandStat $brandStat) { return [ - 'date' => $brandStat->created_at->format('Y-m-d'), + 'date' => $brandStat->created_at->isoFormat('YYYY-MM-DD'), 'active' => $brandStat->active, 'inactive' => $brandStat->inactive, 'old_accounts' => $brandStat->old_accounts, diff --git a/app/Models/User.php b/app/Models/User.php index 6232f42..244c32e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -5,6 +5,8 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; +use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Str; class User extends Authenticatable { @@ -17,7 +19,8 @@ class User extends Authenticatable * @var array */ protected $fillable = [ - 'name', + 'lastname', + 'firstname', 'email', 'password', ]; @@ -40,4 +43,26 @@ class User extends Authenticatable protected $casts = [ 'email_verified_at' => 'datetime', ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted() + { + // * EVENT CLOSURES. + static::creating(function (self $model) { + if (Hash::needsRehash($model->password)) { + $model->password = Hash::make($model->password); + } + $model->remember_token = Str::random(10); + }); + static::updating(function (self $model) { + if (Hash::needsRehash($model->password)) { + $model->password = Hash::make($model->password); + } + $model->remember_token = Str::random(10); + }); + } } diff --git a/database/migrations/2021_10_29_160416_repair_stats_jobs.php b/database/migrations/2021_10_29_160416_repair_stats_jobs.php index 11d9b00..a1a900b 100644 --- a/database/migrations/2021_10_29_160416_repair_stats_jobs.php +++ b/database/migrations/2021_10_29_160416_repair_stats_jobs.php @@ -31,7 +31,7 @@ class RepairStatsJobs extends Migration $ref->setAccessible(true); $service = $ref->getValue(unserialize($payload->data->command)); - $date = Carbon::parse($job->created_at)->format('Y-m-d'); + $date = Carbon::parse($job->created_at)->isoFormat('YYYY-MM-DD'); $serviceStat = ServiceStat::whereDate('date', $date) ->where('service_id', $service->id)->where('brand_id', $service->brand->id) diff --git a/resources/views/customers/show.blade.php b/resources/views/customers/show.blade.php index ae54f49..47a8467 100644 --- a/resources/views/customers/show.blade.php +++ b/resources/views/customers/show.blade.php @@ -63,7 +63,7 @@ {{ __('Date de naissance') }} - {{ \Carbon\Carbon::parse($customerInfos->birth_date)->format('d/m/Y') }} + {{ \Carbon\Carbon::parse($customerInfos->birth_date)->isoFormat('DD\/MM\/YYYY') }} {{ __('Téléphone') }} @@ -96,14 +96,14 @@ {{ __('Date de la dernière modification de l\'abonnement') }} @if($customerInfos->customer->optInHistory()->orderBy('created_at', 'DESC')->exists()) - {{ \Carbon\Carbon::parse($customerInfos->customer->optInHistory()->orderBy('created_at', 'DESC')->first()->created_at)->format('d/m/Y à H:i') }} + {{ \Carbon\Carbon::parse($customerInfos->customer->optInHistory()->orderBy('created_at', 'DESC')->first()->created_at)->isoFormat('DD\/MM\/YYYY à HH:mm') }} @else @endif {{ __('Dernière connexion') }} - {{ \Carbon\Carbon::parse($customerLogin->last_connection)->format('d/m/Y à H:i') }} + {{ \Carbon\Carbon::parse($customerLogin->last_connection)->isoFormat('DD\/MM\/YYYY à HH:mm') }} {{ __('Status du compte') }} @@ -115,11 +115,11 @@ {{ __('Date de création') }} - {{ \Carbon\Carbon::parse($customerInfos->created_at)->format('d/m/Y à H:i') }} + {{ \Carbon\Carbon::parse($customerInfos->created_at)->isoFormat('DD\/MM\/YYYY à HH:mm') }} {{ __('Date de modification') }} - {{ \Carbon\Carbon::parse($customerInfos->updated_at)->format('d/m/Y à H:i') }} + {{ \Carbon\Carbon::parse($customerInfos->updated_at)->isoFormat('DD\/MM\/YYYY à HH:mm') }} diff --git a/resources/views/mail/arcadiaOrders/default.blade.php b/resources/views/mail/arcadiaOrders/default.blade.php index 892c8d4..c14a9e9 100644 --- a/resources/views/mail/arcadiaOrders/default.blade.php +++ b/resources/views/mail/arcadiaOrders/default.blade.php @@ -2,7 +2,7 @@ {{ $request->order_num }} - {{ \Carbon::parse($request->order_date)->format('d/m/Y') }} + {{ Carbon::parse($request->order_date)->isoFormat('DD\/MM\/YYYY') }} {{ $request->operation }} @if($type->equals(\App\Enums\ArcadiaMailType::default())) @if($orderType->equals(\App\Enums\ArcadiaOrderType::cb())) diff --git a/resources/views/mail/arcadiaOrders/game.blade.php b/resources/views/mail/arcadiaOrders/game.blade.php index 7fb0e96..4505039 100644 --- a/resources/views/mail/arcadiaOrders/game.blade.php +++ b/resources/views/mail/arcadiaOrders/game.blade.php @@ -2,7 +2,7 @@ - {{ \Carbon::parse($request->order_date)->format('d/m/Y') }} + {{ Carbon::parse($request->order_date)->isoFormat('DD\/MM\/YYYY') }} {{ $request->operation }} diff --git a/resources/views/mail/service-renewed-plain.blade.php b/resources/views/mail/service-renewed-plain.blade.php index b3b0c69..2616bf1 100644 --- a/resources/views/mail/service-renewed-plain.blade.php +++ b/resources/views/mail/service-renewed-plain.blade.php @@ -3,6 +3,6 @@ Un service vient d'être régénéré sur {{ $appName }} {{ $service->name }} (marque : {{ $service->brand->name }}) -Régénéré le {{ $service->updated_at->format('D/m/Y H:i') }} +Régénéré le {{ $service->updated_at->isoFormat('dddd DD\/MM\/YYYY HH:MM') }} par {{ $by }} Celà va empêcher le service de fonctionner tant que les crédentials d'api n'auront pas été mis à jour sur le service concerné, veuillez faire au plus vite ! diff --git a/resources/views/mail/service-renewed.blade.php b/resources/views/mail/service-renewed.blade.php index 31a1180..17275e6 100644 --- a/resources/views/mail/service-renewed.blade.php +++ b/resources/views/mail/service-renewed.blade.php @@ -7,7 +7,7 @@

Un service vient d'être régénéré sur {{ $appName }}

{{ $service->name }} (marque : {{ $service->brand->name }})

-

Régénéré le {{ $service->updated_at->format('D d/m/Y H:i') }}
par {{ $by }}

+

Régénéré le {{ $service->updated_at->isoFormat('dddd DD\/MM\/YYYY HH:MM') }}
par {{ $by }}

Celà va empêcher le service de fonctionner tant que les crédentials d'api n'auront pas été mis à jour sur le service concerné, veuillez faire au plus vite !

diff --git a/resources/views/stats/view-stats-by-brands.blade.php b/resources/views/stats/view-stats-by-brands.blade.php index 2cf837f..2e0aabf 100644 --- a/resources/views/stats/view-stats-by-brands.blade.php +++ b/resources/views/stats/view-stats-by-brands.blade.php @@ -25,9 +25,9 @@ {{ __('Début') }} - + {{ __('Fin') }} - + + {{ __('Fin') }} - +