From 8a4bfdf006ec642b280646b0d2100f9bda1156f5 Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Sun, 7 Jan 2024 16:14:55 +0000 Subject: [PATCH] Improve error handling Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- phpstan-baseline.neon | 155 ------ src/Auth/AuthServiceProvider.php | 2 +- src/Auth/Manager.php | 494 ------------------ src/Auth/Models/User.php | 3 +- .../Conditions/CustomerAttribute.php | 4 +- src/Classes/PermissionManager.php | 2 +- src/Http/Controllers/Customers.php | 9 +- src/Http/Controllers/Users.php | 18 +- src/Jobs/AllocateAssignable.php | 3 +- src/MainMenuWidgets/UserPanel.php | 8 +- src/Models/Concerns/SendsInvite.php | 3 +- src/Models/Customer.php | 4 +- src/Models/UserPreference.php | 4 +- 13 files changed, 30 insertions(+), 679 deletions(-) delete mode 100644 src/Auth/Manager.php diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d016f9c..c50ba0a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -100,46 +100,6 @@ parameters: count: 1 path: src/Auth/CustomerGuard.php - - - message: "#^Access to an undefined property Igniter\\\\User\\\\Auth\\\\Models\\\\User\\:\\:\\$is_activated\\.$#" - count: 1 - path: src/Auth/Manager.php - - - - message: "#^Access to an undefined property Illuminate\\\\Contracts\\\\Auth\\\\Authenticatable\\:\\:\\$is_activated\\.$#" - count: 1 - path: src/Auth/Manager.php - - - - message: "#^Call to an undefined method Illuminate\\\\Contracts\\\\Auth\\\\Authenticatable\\:\\:afterLogin\\(\\)\\.$#" - count: 1 - path: src/Auth/Manager.php - - - - message: "#^Call to an undefined method Illuminate\\\\Contracts\\\\Auth\\\\Authenticatable\\:\\:beforeLogin\\(\\)\\.$#" - count: 1 - path: src/Auth/Manager.php - - - - message: "#^Call to an undefined method Illuminate\\\\Contracts\\\\Auth\\\\Authenticatable\\:\\:checkRememberToken\\(\\)\\.$#" - count: 1 - path: src/Auth/Manager.php - - - - message: "#^Call to an undefined method Illuminate\\\\Contracts\\\\Auth\\\\Authenticatable\\:\\:fireEvent\\(\\)\\.$#" - count: 1 - path: src/Auth/Manager.php - - - - message: "#^Call to an undefined method Illuminate\\\\Contracts\\\\Auth\\\\Authenticatable\\:\\:getKey\\(\\)\\.$#" - count: 1 - path: src/Auth/Manager.php - - - - message: "#^Call to an undefined method Illuminate\\\\Contracts\\\\Auth\\\\Authenticatable\\:\\:updateRememberToken\\(\\)\\.$#" - count: 1 - path: src/Auth/Manager.php - - message: "#^Access to an undefined property Igniter\\\\User\\\\Auth\\\\Models\\\\User\\:\\:\\$activated_at\\.$#" count: 1 @@ -270,111 +230,6 @@ parameters: count: 1 path: src/Classes/UserState.php - - - message: "#^Call to an undefined static method Igniter\\\\Cart\\\\Facades\\\\Cart\\:\\:count\\(\\)\\.$#" - count: 1 - path: src/Components/Account.php - - - - message: "#^Call to an undefined static method Igniter\\\\Cart\\\\Facades\\\\Cart\\:\\:total\\(\\)\\.$#" - count: 1 - path: src/Components/Account.php - - - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Facades\\\\Auth\\:\\:check\\(\\)\\.$#" - count: 1 - path: src/Components/Account.php - - - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Facades\\\\Auth\\:\\:getUser\\(\\)\\.$#" - count: 1 - path: src/Components/Account.php - - - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Facades\\\\Auth\\:\\:login\\(\\)\\.$#" - count: 1 - path: src/Components/Account.php - - - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Facades\\\\Auth\\:\\:logout\\(\\)\\.$#" - count: 1 - path: src/Components/Account.php - - - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Facades\\\\Auth\\:\\:validateCredentials\\(\\)\\.$#" - count: 1 - path: src/Components/Account.php - - - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Models\\\\Customer\\:\\:whereActivationCode\\(\\)\\.$#" - count: 1 - path: src/Components/Account.php - - - - message: "#^Call to an undefined static method Illuminate\\\\Support\\\\Facades\\\\Mail\\:\\:queueTemplate\\(\\)\\.$#" - count: 3 - path: src/Components/Account.php - - - - message: "#^Call to an undefined method Igniter\\\\User\\\\Components\\\\AddressBook\\:\\:pageCycle\\(\\)\\.$#" - count: 2 - path: src/Components/AddressBook.php - - - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Facades\\\\Auth\\:\\:customer\\(\\)\\.$#" - count: 5 - path: src/Components/AddressBook.php - - - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Models\\\\Address\\:\\:find\\(\\)\\.$#" - count: 3 - path: src/Components/AddressBook.php - - - - message: "#^Call to an undefined method Igniter\\\\User\\\\Components\\\\ResetPassword\\:\\:currentPageUrl\\(\\)\\.$#" - count: 1 - path: src/Components/ResetPassword.php - - - - message: "#^Call to an undefined static method Igniter\\\\Main\\\\Template\\\\Page\\:\\:lists\\(\\)\\.$#" - count: 2 - path: src/Components/ResetPassword.php - - - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Models\\\\Customer\\:\\:whereEmail\\(\\)\\.$#" - count: 1 - path: src/Components/ResetPassword.php - - - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Models\\\\Customer\\:\\:whereResetCode\\(\\)\\.$#" - count: 1 - path: src/Components/ResetPassword.php - - - - message: "#^Call to an undefined static method Illuminate\\\\Support\\\\Facades\\\\Mail\\:\\:queueTemplate\\(\\)\\.$#" - count: 1 - path: src/Components/ResetPassword.php - - - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Facades\\\\Auth\\:\\:check\\(\\)\\.$#" - count: 2 - path: src/Components/Session.php - - - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Facades\\\\Auth\\:\\:getUser\\(\\)\\.$#" - count: 2 - path: src/Components/Session.php - - - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Facades\\\\Auth\\:\\:logout\\(\\)\\.$#" - count: 1 - path: src/Components/Session.php - - - - message: "#^Call to an undefined static method Illuminate\\\\Support\\\\Facades\\\\Event\\:\\:fire\\(\\)\\.$#" - count: 1 - path: src/Components/Session.php - - message: "#^Access to an undefined property Igniter\\\\User\\\\Console\\\\Commands\\\\ClearUserStateCommand\\:\\:\\$defaultStateConfig\\.$#" count: 1 @@ -515,11 +370,6 @@ parameters: count: 1 path: src/Http/Controllers/Customers.php - - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Facades\\\\AdminAuth\\:\\:user\\(\\)\\.$#" - count: 1 - path: src/Http/Controllers/Customers.php - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Facades\\\\Auth\\:\\:impersonate\\(\\)\\.$#" count: 1 @@ -600,11 +450,6 @@ parameters: count: 1 path: src/Http/Controllers/Users.php - - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Facades\\\\AdminAuth\\:\\:user\\(\\)\\.$#" - count: 1 - path: src/Http/Controllers/Users.php - - message: "#^Call to an undefined static method Igniter\\\\User\\\\Facades\\\\AdminAuth\\:\\:check\\(\\)\\.$#" count: 1 diff --git a/src/Auth/AuthServiceProvider.php b/src/Auth/AuthServiceProvider.php index 7f07b45..98861e2 100644 --- a/src/Auth/AuthServiceProvider.php +++ b/src/Auth/AuthServiceProvider.php @@ -68,7 +68,7 @@ protected function configureGateCallback() { Gate::after(function ($user, $ability) { if (Igniter::isAdminUser($user)) { - return $user->hasPermission($ability) === true ? true : null; + return $user->hasAnyPermission($ability) === true ? true : null; } }); } diff --git a/src/Auth/Manager.php b/src/Auth/Manager.php deleted file mode 100644 index b006ac3..0000000 --- a/src/Auth/Manager.php +++ /dev/null @@ -1,494 +0,0 @@ -user)) { - // Load the user using session identifier - if ($sessionData = Session::get($this->sessionKey)) { - $userData = $sessionData; - } - // If no user is found in session, - // load the user using cookie token - elseif ($cookieData = Cookie::get($this->sessionKey)) { - $this->viaRemember = true; - $userData = @json_decode($cookieData, true); - } else { - return false; - } - - if (!is_array($userData) || count($userData) !== 2) { - return false; - } - - [$userId, $rememberToken] = $userData; - - if (!$user = $this->getById($userId)) { - return false; - } - - if (!$user->checkRememberToken($rememberToken)) { - return false; - } - - $this->user = $user; - } - - if (!($user = $this->getUser())) { - return false; - } - - if ($this->requireApproval && $user && !$user->is_activated) { - $this->user = null; - - return false; - } - - return true; - } - - /** - * Determine if the current user is a guest. - */ - public function guest() - { - return !$this->check(); - } - - /** - * Get the currently authenticated user. - * - * @return \Igniter\User\Auth\Models\User - */ - public function user() - { - if (is_null($this->user)) { - $this->check(); - } - - return $this->user; - } - - /** - * Get the ID for the currently authenticated user. - * @return int|null - */ - public function id() - { - return $this->user()->getAuthIdentifier(); - } - - /** - * Get the currently authenticated user model. - * @return \Igniter\User\Auth\Models\User - */ - public function getUser() - { - return $this->user(); - } - - /** - * Set the current user model - */ - public function setUser($user) - { - $this->user = $user; - } - - /** - * Validate a user using the given credentials. - * - * @param bool $remember - * @param bool $login - * - * @return \Igniter\User\Auth\Models\User|bool - * @throws \Exception - */ - public function authenticate(array $credentials = [], $remember = false, $login = true) - { - $user = $this->getByCredentials($credentials); - - // Validate the user against the given credentials, - // if valid log the user into the application - if (is_null($user) || !$this->validateCredentials($user, $credentials)) { - return false; - } - - $user->clearResetPasswordCode(); - - if ($login) { - $this->login($user, $remember); - } - - return $this->user; - } - - /** - * Log a user into the application without sessions or cookies. - * - * @param array $credentials - * @return bool - */ - public function once($credentials = []) - { - $this->useSession = false; - - $user = $this->authenticate($credentials); - - $this->useSession = true; - - return (bool)$user; - } - - /** - * Log the given user ID into the application without sessions or cookies. - * - * @param mixed $id - * @return \Illuminate\Contracts\Auth\Authenticatable|false - */ - public function onceUsingId($id) - { - if (!is_null($user = $this->getById($id))) { - $this->setUser($user); - - return $user; - } - - return false; - } - - /** - * Log a user into the application. - * - * @param bool $remember - * - * @throws \Exception - */ - public function login(Authenticatable $user, $remember = false) - { - $user->beforeLogin(); - - // Approval is required, user not approved - if ($this->requireApproval && !$user->is_activated) { - throw new Exception(sprintf( - 'Cannot login user "%s" until activated.', $user->getAuthIdentifier() - )); - } - - $this->setUser($user); - - if ($this->useSession) { - $toPersist = $this->getPersistData($user); - Session::put($this->sessionKey, $toPersist); - - // If the user should be permanently "remembered" by the application. - if ($remember) { - Cookie::queue(Cookie::forever($this->sessionKey, json_encode($toPersist))); - } - } - - $user->afterLogin(); - } - - /** - * Log the given user ID into the application. - * - * @param bool $remember - * - * @return mixed - * @throws \Exception - */ - public function loginUsingId($id, $remember = false) - { - if (!is_null($user = $this->getById($id))) { - $this->login($user, $remember); - - return $user; - } - - return false; - } - - /** - * Log the user out of the application. - * @return void - **/ - public function logout() - { - if (is_null($this->user) && !$this->check()) { - return; - } - - if ($this->isImpersonator()) { - $this->user = $this->getImpersonator(); - $this->stopImpersonate(); - - return; - } - - if ($this->user) { - $this->user->updateRememberToken(null); - } - - $this->user = null; - - Session::forget($this->sessionKey); - - // delete the remember me cookies if they exist - Cookie::queue(Cookie::forget($this->sessionKey)); - } - - /** - * Determine if the user was authenticated via "remember me" cookie. - * - * @return bool - */ - public function viaRemember() - { - return $this->viaRemember; - } - - // - // User - // - - /** - * @return \Illuminate\Contracts\Auth\Authenticatable|\Igniter\User\Auth\Models\User - */ - public function getById($identifier) - { - $query = $this->createModelQuery(); - - return $query->find($identifier); - } - - /** - * @return mixed - * @throws \Exception - */ - public function getByToken($identifier, $token) - { - $model = $this->createModel(); - $query = $this->createModelQuery(); - - return $query - ->where($model->getAuthIdentifierName(), $identifier) - ->where($model->getRememberTokenName(), $token) - ->first(); - } - - /** - * @return null|\Igniter\User\Auth\Models\User - */ - public function getByCredentials(array $credentials) - { - if (empty($credentials)) { - return null; - } - - $query = $this->createModelQuery(); - - foreach ($credentials as $key => $value) { - if (!str_contains($key, 'password')) { - $query->where($key, $value); - } - } - - return $query->first(); - } - - public function validateCredentials(User $user, $credentials) - { - $plain = $credentials['password']; - - // Backward compatibility to turn SHA1 passwords to BCrypt - if ($user->hasShaPassword($plain)) { - $user->updateHashPassword($plain); - } - - return Hash::check($plain, $user->getAuthPassword()); - } - - /** - * Create a new instance of the model - * if it does not already exist. - * @return mixed - * @throws \Exception - */ - public function createModel() - { - if (!isset($this->model)) { - throw new Exception(sprintf('Required property [model] missing in %s', get_called_class())); - } - - $modelClass = $this->model; - if (!class_exists($modelClass)) { - throw new Exception(sprintf('Missing model [%s] in %s', $modelClass, get_called_class())); - } - - return new $modelClass(); - } - - /** - * Prepares a query derived from the user model. - */ - protected function createModelQuery() - { - $model = $this->createModel(); - $query = $model->newQuery(); - $this->extendUserQuery($query); - - return $query; - } - - /** - * Extend the query used for finding the user. - * - * @param \Igniter\Flame\Database\Builder $query - * - * @return void - */ - public function extendUserQuery($query) - { - } - - /** - * Gets the name of the user model - * @return string - */ - public function getModel() - { - return $this->model; - } - - /** - * Sets the name of the user model - * - * @return $this - */ - public function setModel($model) - { - $this->model = $model; - - return $this; - } - - /** - * Create a new "remember me" token for the user - * - * @param \Illuminate\Contracts\Auth\Authenticatable|\Igniter\User\Auth\Models\User $user - * @return array - */ - protected function getPersistData($user) - { - $user->updateRememberToken(Str::random(42)); - - return [$user->getKey(), $user->getRememberToken()]; - } - - // - // Impersonation - // - - /** - * Impersonates the given user and sets properties - * in the session but not the cookie. - * - * @param \Igniter\User\Auth\Models\User $user - * - * @throws \Exception - */ - public function impersonate($user) - { - $oldSession = Session::get($this->sessionKey); - $oldUser = !empty($oldSession[0]) ? $this->getById($oldSession[0]) : false; - - $user->fireEvent('model.auth.beforeImpersonate', [$oldUser]); - $this->login($user, false); - - if (!$this->isImpersonator()) { - Session::put($this->sessionKey.'_impersonate', $oldSession); - } - } - - public function stopImpersonate() - { - $currentSession = Session::get($this->sessionKey); - $currentUser = !empty($currentSession[0]) ? $this->getById($currentSession[0]) : false; - - $oldSession = Session::pull($this->sessionKey.'_impersonate'); - $oldUser = !empty($oldSession[0]) ? $this->getById($oldSession[0]) : false; - - if ($currentUser) { - $currentUser->fireEvent('model.auth.afterImpersonate', [$oldUser]); - } - - if ($oldSession) { - Session::put($this->sessionKey, $oldSession); - } - } - - public function isImpersonator() - { - return Session::has($this->sessionKey.'_impersonate'); - } - - public function getImpersonator() - { - $impersonateArray = Session::get($this->sessionKey.'_impersonate'); - - // Check supplied session/cookie is an array (user id, persist code) - if (!is_array($impersonateArray) || count($impersonateArray) !== 2) { - return false; - } - - $id = $impersonateArray[0]; - - return $this->createModel()->find($id); - } -} diff --git a/src/Auth/Models/User.php b/src/Auth/Models/User.php index 01c9d5f..ce0d73a 100644 --- a/src/Auth/Models/User.php +++ b/src/Auth/Models/User.php @@ -5,6 +5,7 @@ use Carbon\Carbon; use Exception; use Igniter\Flame\Database\Model; +use Igniter\Flame\Exception\SystemException; use Igniter\User\Models\Notification; use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Notifications\Notifiable; @@ -253,7 +254,7 @@ public function getActivationCode() public function completeActivation($activationCode) { if ($this->is_activated) { - throw new Exception('User is already active!'); + throw new SystemException('User is already active!'); } if ($activationCode == $this->activation_code) { diff --git a/src/AutomationRules/Conditions/CustomerAttribute.php b/src/AutomationRules/Conditions/CustomerAttribute.php index 544d61d..ca46fd6 100644 --- a/src/AutomationRules/Conditions/CustomerAttribute.php +++ b/src/AutomationRules/Conditions/CustomerAttribute.php @@ -2,8 +2,8 @@ namespace Igniter\User\AutomationRules\Conditions; +use Igniter\Automation\AutomationException; use Igniter\Automation\Classes\BaseModelAttributesCondition; -use Igniter\Flame\Exception\ApplicationException; class CustomerAttribute extends BaseModelAttributesCondition { @@ -45,7 +45,7 @@ public function defineModelAttributes() public function isTrue(&$params) { if (!$customer = array_get($params, 'customer')) { - throw new ApplicationException('Error evaluating the customer attribute condition: the customer object is not found in the condition parameters.'); + throw new AutomationException('Error evaluating the customer attribute condition: the customer object is not found in the condition parameters.'); } return $this->evalIsTrue($customer); diff --git a/src/Classes/PermissionManager.php b/src/Classes/PermissionManager.php index d97b197..3443048 100644 --- a/src/Classes/PermissionManager.php +++ b/src/Classes/PermissionManager.php @@ -80,8 +80,8 @@ public function listGroupedPermissions() public function checkPermission($permissions, $checkPermissions, $checkAll) { - $matched = false; foreach ($checkPermissions as $permission) { + $matched = false; if ($this->checkPermissionStartsWith($permission, $permissions) || $this->checkPermissionEndsWith($permission, $permissions) || $this->checkPermissionMatches($permission, $permissions) diff --git a/src/Http/Controllers/Customers.php b/src/Http/Controllers/Customers.php index 8ec675c..cce2040 100644 --- a/src/Http/Controllers/Customers.php +++ b/src/Http/Controllers/Customers.php @@ -4,8 +4,7 @@ use Igniter\Admin\Facades\AdminMenu; use Igniter\Admin\Facades\Template; -use Igniter\Flame\Exception\ApplicationException; -use Igniter\User\Facades\AdminAuth; +use Igniter\Flame\Exception\FlashException; use Igniter\User\Facades\Auth; use function flash; @@ -71,9 +70,9 @@ public function __construct() public function onImpersonate($context, $recordId = null) { - if (!AdminAuth::user()->hasPermission('Admin.ImpersonateCustomers')) { - throw new ApplicationException(lang('igniter.user::default.customers.alert_login_restricted')); - } + throw_unless($this->authorize('Admin.ImpersonateCustomers'), + FlashException::error(lang('igniter.user::default.customers.alert_login_restricted')) + ); $id = post('recordId', $recordId); if ($customer = $this->formFindModelObject((int)$id)) { diff --git a/src/Http/Controllers/Users.php b/src/Http/Controllers/Users.php index 50e0ad8..d2c30ce 100644 --- a/src/Http/Controllers/Users.php +++ b/src/Http/Controllers/Users.php @@ -100,27 +100,27 @@ public function account_onSave() public function index_onDelete() { - if (!$this->getUser()->hasPermission('Admin.DeleteStaffs')) { - throw new FlashException(lang('igniter::admin.alert_user_restricted')); - } + throw_unless($this->authorize('Admin.DeleteStaffs'), + FlashException::error(lang('igniter::admin.alert_user_restricted')) + ); return $this->asExtension(\Igniter\Admin\Http\Actions\ListController::class)->index_onDelete(); } public function edit_onDelete($context, $recordId) { - if (!$this->getUser()->hasPermission('Admin.DeleteStaffs')) { - throw new FlashException(lang('igniter::admin.alert_user_restricted')); - } + throw_unless($this->authorize('Admin.DeleteStaffs'), + FlashException::error(lang('igniter::admin.alert_user_restricted')) + ); return $this->asExtension(\Igniter\Admin\Http\Actions\FormController::class)->edit_onDelete($context, $recordId); } public function onImpersonate($context, $recordId = null) { - if (!AdminAuth::user()->hasPermission('Admin.Impersonate')) { - throw new FlashException(lang('igniter.user::default.staff.alert_login_restricted')); - } + throw_unless($this->authorize('Admin.Impersonate'), + FlashException::error(lang('igniter.user::default.staff.alert_login_restricted')) + ); $id = post('recordId', $recordId); if ($user = $this->formFindModelObject((int)$id)) { diff --git a/src/Jobs/AllocateAssignable.php b/src/Jobs/AllocateAssignable.php index 4d9116d..4b7ad10 100644 --- a/src/Jobs/AllocateAssignable.php +++ b/src/Jobs/AllocateAssignable.php @@ -3,6 +3,7 @@ namespace Igniter\User\Jobs; use Exception; +use Igniter\Flame\Exception\SystemException; use Igniter\User\Console\Commands\AllocatorCommand; use Igniter\User\Models\AssignableLog; use Igniter\User\Models\Concerns\Assignable; @@ -52,7 +53,7 @@ public function handle() AllocatorCommand::addSlot($this->assignableLog->getKey()); if (!$assignee = $this->assignableLog->assignee_group->findAvailableAssignee()) { - throw new Exception(lang('igniter.user::default.user_groups.alert_no_available_assignee')); + throw new SystemException(lang('igniter.user::default.user_groups.alert_no_available_assignee')); } $this->assignableLog->assignable->assignTo($assignee); diff --git a/src/MainMenuWidgets/UserPanel.php b/src/MainMenuWidgets/UserPanel.php index 3e23d7c..1886ee5 100644 --- a/src/MainMenuWidgets/UserPanel.php +++ b/src/MainMenuWidgets/UserPanel.php @@ -3,7 +3,7 @@ namespace Igniter\User\MainMenuWidgets; use Igniter\Admin\Traits\ValidatesForm; -use Igniter\Flame\Exception\ApplicationException; +use Igniter\Flame\Exception\FlashException; use Igniter\Flame\Html\HtmlFacade; use Igniter\User\Classes\UserState; use Igniter\User\Models\User; @@ -70,9 +70,9 @@ public function onSetStatus() 'clear_after' => 'required_if:status,'.UserState::CUSTOM_STATUS.'|integer', ]); - if ($validated['status'] < 1 && !strlen($validated['message'])) { - throw new ApplicationException(lang('igniter::admin.side_menu.alert_invalid_status')); - } + throw_if($validated['status'] < 1 && !strlen($validated['message']), + FlashException::error(lang('igniter::admin.side_menu.alert_invalid_status')) + ); $this->userState->updateState($validated['status'], $validated['message'] ?? '', $validated['clear_after']); diff --git a/src/Models/Concerns/SendsInvite.php b/src/Models/Concerns/SendsInvite.php index 960aa3a..8807ecc 100644 --- a/src/Models/Concerns/SendsInvite.php +++ b/src/Models/Concerns/SendsInvite.php @@ -3,7 +3,6 @@ namespace Igniter\User\Models\Concerns; use Igniter\Flame\Database\Model; -use Igniter\Flame\Exception\SystemException; trait SendsInvite { @@ -23,7 +22,7 @@ public static function bootSendsInvite() protected function sendInviteGetTemplateCode(): string { - throw new SystemException(sprintf( + throw new \LogicException(sprintf( 'The model [%s] must implement a sendInviteGetTemplateCode() method.', get_class($this) )); diff --git a/src/Models/Customer.php b/src/Models/Customer.php index 7177246..fd65844 100644 --- a/src/Models/Customer.php +++ b/src/Models/Customer.php @@ -3,10 +3,10 @@ namespace Igniter\User\Models; use Carbon\Carbon; -use Exception; use Igniter\Cart\Models\Order; use Igniter\Flame\Database\Factories\HasFactory; use Igniter\Flame\Database\Traits\Purgeable; +use Igniter\Flame\Exception\SystemException; use Igniter\Reservation\Models\Reservation; use Igniter\System\Models\Concerns\Switchable; use Igniter\System\Traits\SendsMailTemplate; @@ -101,7 +101,7 @@ public function beforeLogin() return; } - throw new Exception(sprintf( + throw new SystemException(sprintf( lang('igniter.user::default.customers.alert_customer_not_active'), $this->email )); } diff --git a/src/Models/UserPreference.php b/src/Models/UserPreference.php index 8012197..b813dc8 100644 --- a/src/Models/UserPreference.php +++ b/src/Models/UserPreference.php @@ -2,8 +2,8 @@ namespace Igniter\User\Models; -use Exception; use Igniter\Flame\Database\Model; +use Igniter\Flame\Exception\SystemException; use Igniter\User\Facades\AdminAuth; class UserPreference extends Model @@ -42,7 +42,7 @@ public function resolveUser() { $user = AdminAuth::getUser(); if (!$user) { - throw new Exception(lang('igniter::admin.alert_user_not_logged')); + throw new SystemException(lang('igniter::admin.alert_user_not_logged')); } return $user;