add offers count, & minor fixes code standards

This commit is contained in:
Ludovic CANDELLIER
2021-11-01 16:26:31 +01:00
parent e97f54f126
commit 18f1f8a13a
66 changed files with 526 additions and 574 deletions

View File

@@ -1,74 +0,0 @@
<?php
namespace App\Repositories\Core\User\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class NewUser extends Notification
{
use Queueable;
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
*
* @return string[]
*/
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)
{
$currentUser = \Auth::user();
return (new MailMessage())
->markdown('notifications.email')
->greeting(__('notifications.greeting', ['firstname' => $notifiable->first_name]))
->subject(__('notifications.newuser.subject', ['name' => config('app.name')]))
->line(
__(
'notifications.newuser.intro', [
'name' => $currentUser->first_name.' '.$currentUser->last_name,
]
)
)
->action(
__('notifications.newuser.button'),
route('users.firstlogin', $notifiable->remember_token)
)
->salutation(
__(
'notifications.salutation', [
'name' => $currentUser->first_name.' '.$currentUser->last_name,
]
)
)
->line(__('notifications.newuser.outro'));
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
*
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}

View File

@@ -9,12 +9,19 @@ class PasswordSecurities
{
public static function create($user_id, $delay = 90)
{
return PasswordSecurity::create(
[
return PasswordSecurity::create([
'user_id' => $user_id,
'password_expiry_days' => $delay,
'password_updated_at' => Carbon::now(),
]
);
]);
}
public static function getUserName($id) {
return self::getUser($id)->username;
}
public static function getUser($id) {
return PasswordSecurity::with('user')->find($id)->user;
}
}

View File

@@ -1,31 +0,0 @@
<?php
namespace App\Repositories\Core\User\Notifications;
use Illuminate\Notifications\Messages\MailMessage;
class ResetPassword extends \Illuminate\Auth\Notifications\ResetPassword
{
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
*
* @return \Illuminate\Notifications\Messages\MailMessage
*/
/*
public function toMail($notifiable)
{
return (new MailMessage())
->markdown('notifications.email')
->greeting(__('notifications.greeting', ['firstname' => $notifiable->first_name]))
->subject(__('notifications.resetpassword.subject'))
->line(__('notifications.resetpassword.intro'))
->action(
__('notifications.resetpassword.button'),
route('password.reset', $this->token)
)
->line(__('notifications.resetpassword.outro'));
}
*/
}

View File

@@ -2,11 +2,6 @@
namespace App\Repositories\Core\Auth;
use Hyn\Tenancy\Environment;
use Hyn\Tenancy\Database\Connection;
use App\Models\Admin\Website;
use Hyn\Tenancy\Contracts\Repositories\WebsiteRepository;
use App\Models\Core\Auth\UserClient;
use App\Models\Core\Auth\User;
@@ -48,7 +43,7 @@ class UserClients
{
$history = "";
foreach ($clients as $key => $client_id) {
$client = Clients::select_by_id($client_id);
$client = Clients::get($client_id);
if ($client) {
self::associate_client($user_id, $client_id);
$history .= $client['name'] . "| ";

View File

@@ -15,7 +15,9 @@ use App\Models\Core\Auth\RoleUser;
use App\Repositories\Clients;
use App\Repositories\Partners;
use App\Repositories\Core\Upload;
use LangleyFoxall\LaravelNISTPasswordRules\PasswordRules;
class Users
{
use LaratrustUserTrait;
@@ -35,16 +37,18 @@ class Users
$data = $user->toArray();
$data['name'] = $user->name;
$data['avatar'] = self::getAvatar($id);
$data['last_login'] = $user->previousLoginAt();
// $data['last_login'] = $user->previousLoginAt();
// $data['roles'] = self::getRoles();
// $data['permissions'] = self::getPermissions();
$data['roles'] = $user->roles->pluck('id')->toArray();
$data['permissions'] = $user->allPermissions()->pluck('id')->toArray();
$data['clients'] = $user->clients->pluck('id')->toArray();
return $data;
}
public static function store($data)
{
$id = isset($data['id']) ? $data['id'] : false;
if (!empty($data['password'])) {
@@ -60,19 +64,20 @@ class Users
$data['active'] = true;
$user = $id ? self::update($data, $id) : self::create($data);
$user->roles()->sync(array_keys($data['roles'] ?? []));
if (isset($data['roles'])) {
$user->roles()->sync(array_keys($data['roles']));
}
UserClients::associate($user->id, $data['clients'] ?? false );
// $user->sendNewUserNotification($data['remember_token'], Auth::user());
return $user;
}
public static function create($data)
public static function create($data, $copy_password = false)
{
$data['password'] = $data['password'] ? Hash::make($data['password']) : Hash::make(Str::random(8));
return User::create($data);
$data['password'] = $copy_password ? $data['password'] : ($data['password'] ? Hash::make($data['password']) : Hash::make(Str::random(8)));
$user = User::create($data);
PasswordSecurities::create($user->id);
return $user;
}
public static function update($data, $id = false)
@@ -95,12 +100,17 @@ class Users
return $user ? $user->id : false;
}
public static function getName()
public static function getName($id = false)
{
$user = self::getUser();
$user = $id ? self::get($id) : self::getUser();
return $user->first_name . ' ' . $user->last_name;
}
public static function getUsername($id = false)
{
return $id ? self::get($id)->username : self::getUser()->username;
}
public static function getUser()
{
return Auth::user();
@@ -113,7 +123,7 @@ class Users
public static function getOptions()
{
return User::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
return User::orderBy('name')->pluck('name', 'id')->toArray();
}
public static function delete($id)
@@ -124,7 +134,7 @@ class Users
public static function getListByRole($role)
{
return self::selectOptions()->orderBy('name', 'asc')->whereRoleIs($role)->get();
return self::selectOptions()->orderBy('name')->whereRoleIs($role)->get();
}
public static function hasRole($role, $user = false)
@@ -211,37 +221,36 @@ class Users
return User::count();
}
// récupère tous les utilisateurs pour un statut donné
public static function select_all_by_status_id($status_id)
{
return User::byStatus($status_id);
}
// récupère toutes les informations d'un utilisateur pour un id donné
public static function select_by_id($user_id)
{
return User::with('status')->find($user_id)->toArray();
}
// récupère toutes les informations d'un utilisateur pour un nom donné
public static function select_by_name($name)
{
return User::byName($name)->first()->toArray();
return self::getByName($name)->toArray();
}
public static function getByUsername($username)
{
return User::byUsername($username)->withTrashed()->first();
}
// récupère les utilisateurs actifs d'un statut, d'une équipe et d'une entité donnés
public static function select_by_status_and_team_and_entity($status_id, $team_id, $third_party_id)
{
return User::active()->byStatus($status_id)->byTeam($team_id)->byThirdParty($third_party_id)->get()->toArray();
}
// récupère toutes les informations nécessaires d'un utilisateur pour un id donné
public static function select_datas_by_id($user_id)
{
return User::with('status')->find($user_id)->toArray();
}
// met à jour le statut actif/inactif d'un utilisateur
public static function toggle_active($id, $active)
{
return self::get($id)->update(['active' => $active]);
@@ -251,26 +260,29 @@ class Users
{
$targetDir = 'uploads';
$file = $request->file('avatar_file');
$data = \App\Repositories\Core\Upload::getData($file);
$file_uploaded = \App\Repositories\Core\Upload::store($file, $targetDir);
$data = Upload::getData($file);
$file_uploaded = Upload::store($file, $targetDir);
$tab = pathinfo($file_uploaded);
$response['name'] = $tab['basename'];
return $response;
}
// met à jour l'avatar d'un utilisateur
public static function update_avatar($id, $avatar)
{
return User::find($id)->update(['avatar' => $avatar]);
}
// met à jour le mot de passe d'un utilisateur
public static function update_password($id, $password)
{
$password = Hash::make($password);
UserClients::changePasswordsByUser($id, $password);
$connection = app(Connection::class);
return User::on($connection->systemName())->find($id)->update(['password' => $password]);
return User::find($id)->update(['password' => $password]);
// $connection = app(Connection::class);
// return User::on($connection->systemName())->find($id)->update(['password' => $password]);
}
public static function validate($username, $field = 'current_password')
{
return PasswordRules::changePassword($username, $field);
}
}