change user checkIsNormal()

This commit is contained in:
xiaomlove
2025-05-05 22:07:14 +07:00
parent c5c20c02d6
commit 9a3daabf18
4 changed files with 12 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
<?php <?php
namespace App\Auth; namespace App\Auth;
use App\Models\User;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Auth\GuardHelpers; use Illuminate\Auth\GuardHelpers;
use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Contracts\Auth\Authenticatable;
@@ -46,14 +47,16 @@ class NexusWebGuard implements StatefulGuard
} }
$credentials = $this->request->cookie(); $credentials = $this->request->cookie();
if ($this->validate($credentials)) { if ($this->validate($credentials)) {
/**
* @var User $user
*/
$user = $this->provider->retrieveByCredentials($credentials); $user = $this->provider->retrieveByCredentials($credentials);
if (empty($user)) { if (empty($user)) {
return null; return null;
} }
if ($this->provider->validateCredentials($user, $credentials)) { if ($this->provider->validateCredentials($user, $credentials)) {
if ($user->checkIsNormal()) { $user->checkIsNormal();
return $this->user = $user; return $this->user = $user;
}
} }
} }
} }

View File

@@ -100,7 +100,7 @@ class PluginStoreResource extends Resource
} }
return nexus_trans("plugin.actions.install"); return nexus_trans("plugin.actions.install");
}) })
->modalHeading(fn (PluginStore $record) => sprintf("%s: %s", nexus_trans("plugin.actions.install_or_update") ,$record->title)) ->modalHeading(fn (PluginStore $record) => sprintf("%s: %s", nexus_trans("plugin.actions.install_or_update"), data_get($record, self::getColumnLabelKey("title"))))
->modalContent(function (PluginStore $record) { ->modalContent(function (PluginStore $record) {
$infolist = new Infolist(); $infolist = new Infolist();
$infolist->record = $record; $infolist->record = $record;

View File

@@ -2,6 +2,7 @@
namespace App\Models; namespace App\Models;
use App\Exceptions\NexusException;
use App\Http\Middleware\Locale; use App\Http\Middleware\Locale;
use App\Repositories\ExamRepository; use App\Repositories\ExamRepository;
use Carbon\Carbon; use Carbon\Carbon;
@@ -277,12 +278,11 @@ class User extends Authenticatable implements FilamentUser, HasName
public function checkIsNormal(array $fields = ['status', 'enabled']): bool public function checkIsNormal(array $fields = ['status', 'enabled']): bool
{ {
if (in_array('status', $fields) && $this->getAttribute('status') != self::STATUS_CONFIRMED) { if (in_array('status', $fields) && $this->getAttribute('status') != self::STATUS_CONFIRMED) {
throw new \InvalidArgumentException(sprintf('User: %s is not confirmed.', $this->id)); throw new NexusException(nexus_trans("user.user_is_not_confirmed", ['user_id' => $this->id, 'username' => $this->username]));
} }
if (in_array('enabled', $fields) && $this->getAttribute('enabled') != self::ENABLED_YES) { if (in_array('enabled', $fields) && $this->getAttribute('enabled') != self::ENABLED_YES) {
throw new \InvalidArgumentException(sprintf('User: %s is not enabled.', $this->id)); throw new NexusException(nexus_trans("user.user_is_disabled", ['user_id' => $this->id, 'username' => $this->username]));
} }
return true; return true;
} }

View File

@@ -109,4 +109,6 @@ return [
'msg_invited_user_has_registered' => "你邀请的用户已注册", 'msg_invited_user_has_registered' => "你邀请的用户已注册",
'msg_user_you_invited' => "你邀请的用户 ", 'msg_user_you_invited' => "你邀请的用户 ",
'msg_has_registered' => " 刚刚已注册。", 'msg_has_registered' => " 刚刚已注册。",
'user_is_disabled' => '用户::username(ID: :user_id) 已被封禁',
'user_is_not_confirmed' => '用户::username(ID: :user_id) 未确认',
]; ];