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 @@
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 !