mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
improve admin user profile + image hosting
This commit is contained in:
@@ -92,4 +92,8 @@ class NexusWebUserProvider implements UserProvider
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rehashPasswordIfRequired(Authenticatable $user, #[\SensitiveParameter] array $credentials, bool $force = false)
|
||||
{
|
||||
// TODO: Implement rehashPasswordIfRequired() method.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,9 @@ class Test extends Command
|
||||
public function handle()
|
||||
{
|
||||
$str = "1.abc.de";
|
||||
$res = explode(".", $str, 2);
|
||||
$ext = "png";
|
||||
$str = "202404/20240403215909f58f38ddd968a0e8a4bdd30690a9e92e.png";
|
||||
$res = substr($str, 0,-1*strlen($ext)-1);
|
||||
dd($res);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,27 +7,21 @@ use App\Filament\Resources\System\SettingResource;
|
||||
use App\Models\HitAndRun;
|
||||
use App\Models\SearchBox;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Tag;
|
||||
use App\Models\User;
|
||||
use App\Repositories\MeiliSearchRepository;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms\ComponentContainer;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Resources\Pages\Concerns\InteractsWithRecord;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Filament\Resources\Pages\Page;
|
||||
use Filament\Forms;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class EditSetting extends Page implements Forms\Contracts\HasForms
|
||||
{
|
||||
use InteractsWithForms, OptionsTrait;
|
||||
use Forms\Concerns\InteractsWithForms, OptionsTrait;
|
||||
|
||||
protected static string $resource = SettingResource::class;
|
||||
|
||||
protected static string $view = 'filament.resources.system.setting-resource.pages.edit-hit-and-run';
|
||||
|
||||
public ?array $data = [];
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return __('label.setting.nav_text');
|
||||
@@ -39,12 +33,21 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
|
||||
$this->fillForm();
|
||||
}
|
||||
|
||||
public function form(Forms\Form $form): Forms\Form
|
||||
{
|
||||
return $form
|
||||
->schema($this->getFormSchema())
|
||||
->statePath('data');
|
||||
}
|
||||
|
||||
private function fillForm()
|
||||
{
|
||||
$settings = Setting::get();
|
||||
$settings = Setting::getFromDb();
|
||||
$this->form->fill($settings);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function getFormSchema(): array
|
||||
{
|
||||
return [
|
||||
@@ -81,7 +84,7 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
|
||||
Setting::query()->upsert($data, ['name'], ['value']);
|
||||
do_action("nexus_setting_update");
|
||||
clear_setting_cache();
|
||||
Filament::notify('success', __('filament::resources/pages/edit-record.messages.saved'), true);
|
||||
send_admin_success_notification();
|
||||
}
|
||||
|
||||
private function getTabs(): array
|
||||
@@ -125,6 +128,13 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
|
||||
->columns(2)
|
||||
;
|
||||
|
||||
$id = "image_hosting";
|
||||
$tabs[] = Forms\Components\Tabs\Tab::make(__("label.setting.$id.tab_header"))
|
||||
->id($id)
|
||||
->schema($this->getTabImageHostingSchema($id))
|
||||
->columns(2)
|
||||
;
|
||||
|
||||
$tabs[] = Forms\Components\Tabs\Tab::make(__('label.setting.system.tab_header'))
|
||||
->id('system')
|
||||
->schema([
|
||||
@@ -184,7 +194,7 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
|
||||
return apply_filter("hit_and_run_setting_schema", $default);
|
||||
}
|
||||
|
||||
private function getTabMeilisearchSchema($id)
|
||||
private function getTabMeilisearchSchema($id): array
|
||||
{
|
||||
$schema = [];
|
||||
|
||||
@@ -215,4 +225,59 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
|
||||
return $schema;
|
||||
}
|
||||
|
||||
private function getTabImageHostingSchema($id): array
|
||||
{
|
||||
$schema = [];
|
||||
$name = "$id.driver";
|
||||
$schema[] = Forms\Components\Radio::make($name)
|
||||
->options(['local' => 'local', 'chevereto' => 'chevereto', 'lsky' => 'lsky'])
|
||||
->inline(true)
|
||||
->label(__("label.setting.$name"))
|
||||
->helperText(__("label.setting.{$name}_help"))
|
||||
->columnSpanFull()
|
||||
;
|
||||
|
||||
//chevereto
|
||||
$driverName = "chevereto";
|
||||
$driverId = sprintf("%s_%s", $id, $driverName);
|
||||
$driverSchemas = [];
|
||||
$field = "upload_api_endpoint";
|
||||
$driverSchemas[] = Forms\Components\TextInput::make("$driverId.$field")
|
||||
->label(__("label.setting.$id.$field"))
|
||||
;
|
||||
$field = "upload_token";
|
||||
$driverSchemas[] = Forms\Components\TextInput::make("$driverId.$field")
|
||||
->label(__("label.setting.$id.$field"))
|
||||
;
|
||||
$field = "base_url";
|
||||
$driverSchemas[] = Forms\Components\TextInput::make("$driverId.$field")
|
||||
->label(__("label.setting.$id.$field"))
|
||||
;
|
||||
|
||||
$driverSection = Forms\Components\Section::make($driverName)->schema($driverSchemas);
|
||||
$schema[] = $driverSection;
|
||||
|
||||
//lsky
|
||||
$driverName = "lsky";
|
||||
$driverId = sprintf("%s_%s", $id, $driverName);
|
||||
$driverSchemas = [];
|
||||
$field = "upload_api_endpoint";
|
||||
$driverSchemas[] = Forms\Components\TextInput::make("$driverId.$field")
|
||||
->label(__("label.setting.$id.$field"))
|
||||
;
|
||||
$field = "upload_token";
|
||||
$driverSchemas[] = Forms\Components\TextInput::make("$driverId.$field")
|
||||
->label(__("label.setting.$id.$field"))
|
||||
;
|
||||
$field = "base_url";
|
||||
$driverSchemas[] = Forms\Components\TextInput::make("$driverId.$field")
|
||||
->label(__("label.setting.$id.$field"))
|
||||
;
|
||||
$driverSection = Forms\Components\Section::make($driverName)->schema($driverSchemas);
|
||||
$schema[] = $driverSection;
|
||||
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ class ExamUserResource extends Resource
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
])
|
||||
->prependBulkActions([
|
||||
->groupedBulkActions([
|
||||
Tables\Actions\BulkAction::make('Avoid')->action(function (Collection $records) {
|
||||
$idArr = $records->pluck('id')->toArray();
|
||||
$rep = new ExamRepository();
|
||||
|
||||
@@ -75,7 +75,7 @@ class HitAndRunResource extends Resource
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
])
|
||||
->prependBulkActions([
|
||||
->groupedBulkActions([
|
||||
Tables\Actions\BulkAction::make('Pardon')->action(function (Collection $records) {
|
||||
$idArr = $records->pluck('id')->toArray();
|
||||
$rep = new HitAndRunRepository();
|
||||
|
||||
@@ -7,12 +7,16 @@ use App\Filament\Resources\User\UserResource\Pages;
|
||||
use App\Filament\Resources\User\UserResource\RelationManagers;
|
||||
use App\Models\User;
|
||||
use App\Repositories\UserRepository;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Grid;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Tables;
|
||||
use Filament\Infolists;
|
||||
use Filament\Infolists\Infolist;
|
||||
use Filament\Infolists\Components;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
@@ -32,6 +36,16 @@ class UserResource extends Resource
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
private static $rep;
|
||||
|
||||
private static function getRep(): UserRepository
|
||||
{
|
||||
if (!self::$rep) {
|
||||
self::$rep = new UserRepository();
|
||||
}
|
||||
return self::$rep;
|
||||
}
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.sidebar.users_list');
|
||||
@@ -102,6 +116,198 @@ class UserResource extends Resource
|
||||
->bulkActions(self::getBulkActions());
|
||||
}
|
||||
|
||||
public static function infolist(Infolist $infolist): Infolist
|
||||
{
|
||||
return $infolist
|
||||
->schema([
|
||||
Components\Grid::make(2)->schema([
|
||||
Components\Group::make([
|
||||
Infolists\Components\TextEntry::make('id')->label("UID"),
|
||||
Infolists\Components\TextEntry::make('username')
|
||||
->label(__("label.user.username"))
|
||||
->formatStateUsing(fn ($record) => get_username($record->id, false, true, true, true))
|
||||
->html()
|
||||
,
|
||||
Infolists\Components\TextEntry::make('email')
|
||||
->label(__("label.email"))
|
||||
,
|
||||
Infolists\Components\TextEntry::make('passkey'),
|
||||
Infolists\Components\TextEntry::make('added')->label(__("label.added")),
|
||||
Infolists\Components\TextEntry::make('last_access')->label(__("label.last_access")),
|
||||
Infolists\Components\TextEntry::make('inviter.username')->label(__("label.user.invite_by")),
|
||||
Infolists\Components\TextEntry::make('parked')->label(__("label.user.parked")),
|
||||
Infolists\Components\TextEntry::make('offer_allowed_count')->label(__("label.user.offer_allowed_count")),
|
||||
Infolists\Components\TextEntry::make('seed_points')->label(__("label.user.seed_points")),
|
||||
Infolists\Components\TextEntry::make('uploadedText')->label(__("label.uploaded")),
|
||||
Infolists\Components\TextEntry::make('downloadedText')->label(__("label.downloaded")),
|
||||
Infolists\Components\TextEntry::make('seedbonus')->label(__("label.user.seedbonus")),
|
||||
])->columns(2),
|
||||
Components\Group::make([
|
||||
Infolists\Components\TextEntry::make('status')
|
||||
->label(__('label.user.status'))
|
||||
->badge()
|
||||
->colors(['success' => User::STATUS_CONFIRMED, 'warning' => User::STATUS_PENDING])
|
||||
->hintAction(self::buildActionConfirm())
|
||||
,
|
||||
|
||||
Infolists\Components\TextEntry::make('classText')
|
||||
->label(__("label.user.class"))
|
||||
->hintAction(self::buildActionChangeClass())
|
||||
,
|
||||
|
||||
Infolists\Components\TextEntry::make('enabled')
|
||||
->label(__("label.user.enabled"))
|
||||
->badge()
|
||||
->colors(['success' => 'yes', 'warning' => 'no'])
|
||||
->hintAction(self::buildActionEnableDisable())
|
||||
,
|
||||
Infolists\Components\TextEntry::make('downloadpos')
|
||||
->label(__("label.user.downloadpos"))
|
||||
->badge()
|
||||
->colors(['success' => 'yes', 'warning' => 'no'])
|
||||
->hintAction(self::buildActionChangeDownloadPos())
|
||||
,
|
||||
Infolists\Components\TextEntry::make('twoFactorAuthenticationStatus')
|
||||
->label(__("label.user.two_step_authentication"))
|
||||
->badge()
|
||||
->colors(['success' => 'yes', 'warning' => 'no'])
|
||||
->hintAction(self::buildActionCancelTwoStepAuthentication())
|
||||
,
|
||||
])
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
private static function buildActionChangeClass(): Infolists\Components\Actions\Action
|
||||
{
|
||||
return Infolists\Components\Actions\Action::make("changeClass")
|
||||
->label(__('label.change'))
|
||||
->button()
|
||||
->visible(fn (User $record): bool => (Auth::user()->class > $record->class))
|
||||
->form([
|
||||
Forms\Components\Select::make('class')
|
||||
->options(User::listClass(User::CLASS_PEASANT, Auth::user()->class - 1))
|
||||
->default(fn (User $record) => $record->class)
|
||||
->label(__('user.labels.class'))
|
||||
->required()
|
||||
->reactive()
|
||||
,
|
||||
Forms\Components\Radio::make('vip_added')
|
||||
->options(self::getYesNoOptions('yes', 'no'))
|
||||
->default(fn (User $record) => $record->vip_added)
|
||||
->label(__('user.labels.vip_added'))
|
||||
->helperText(__('user.labels.vip_added_help'))
|
||||
->hidden(fn (\Filament\Forms\Get $get) => $get('class') != User::CLASS_VIP)
|
||||
,
|
||||
Forms\Components\DateTimePicker::make('vip_until')
|
||||
->default(fn (User $record) => $record->vip_until)
|
||||
->label(__('user.labels.vip_until'))
|
||||
->helperText(__('user.labels.vip_until_help'))
|
||||
->hidden(fn (\Filament\Forms\Get $get) => $get('class') != User::CLASS_VIP)
|
||||
,
|
||||
Forms\Components\TextInput::make('reason')
|
||||
->label(__('admin.resources.user.actions.enable_disable_reason'))
|
||||
->placeholder(__('admin.resources.user.actions.enable_disable_reason_placeholder'))
|
||||
,
|
||||
])
|
||||
->action(function (User $record, array $data) {
|
||||
$userRep = self::getRep();
|
||||
try {
|
||||
$userRep->changeClass(Auth::user(), $record, $data['class'], $data['reason'], $data);
|
||||
send_admin_success_notification();
|
||||
} catch (\Exception $exception) {
|
||||
send_admin_fail_notification($exception->getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static function buildActionConfirm(): Infolists\Components\Actions\Action
|
||||
{
|
||||
return Infolists\Components\Actions\Action::make(__('admin.resources.user.actions.confirm_btn'))
|
||||
->modalHeading(__('admin.resources.user.actions.confirm_btn'))
|
||||
->requiresConfirmation()
|
||||
->visible(fn (User $record): bool => (Auth::user()->class > $record->class))
|
||||
->button()
|
||||
->color('success')
|
||||
->visible(fn ($record) => $record->status == User::STATUS_PENDING)
|
||||
->action(function (User $record) {
|
||||
if (Auth::user()->class <= $record->class) {
|
||||
send_admin_fail_notification("No Permission!");
|
||||
return;
|
||||
}
|
||||
$record->status = User::STATUS_CONFIRMED;
|
||||
$record->info= null;
|
||||
$record->save();
|
||||
send_admin_success_notification();
|
||||
});
|
||||
}
|
||||
|
||||
private static function buildActionEnableDisable(): Infolists\Components\Actions\Action
|
||||
{
|
||||
return Infolists\Components\Actions\Action::make("changeClass")
|
||||
->label(fn (User $record) => $record->enabled == 'yes' ? __('admin.resources.user.actions.disable_modal_btn') : __('admin.resources.user.actions.enable_modal_btn'))
|
||||
->modalHeading(fn (User $record) => $record->enabled == 'yes' ? __('admin.resources.user.actions.disable_modal_title') : __('admin.resources.user.actions.enable_modal_title'))
|
||||
->button()
|
||||
->visible(fn (User $record): bool => (Auth::user()->class > $record->class))
|
||||
->form([
|
||||
Forms\Components\TextInput::make('reason')->label(__('admin.resources.user.actions.enable_disable_reason'))->placeholder(__('admin.resources.user.actions.enable_disable_reason_placeholder')),
|
||||
Forms\Components\Hidden::make('action')->default(fn (User $record) => $record->enabled == 'yes' ? 'disable' : 'enable'),
|
||||
Forms\Components\Hidden::make('uid')->default(fn (User $record) => $record->id),
|
||||
])
|
||||
->action(function (User $record, array $data) {
|
||||
$userRep = self::getRep();
|
||||
try {
|
||||
if ($data['action'] == 'enable') {
|
||||
$userRep->enableUser(Auth::user(), $data['uid'], $data['reason']);
|
||||
} elseif ($data['action'] == 'disable') {
|
||||
$userRep->disableUser(Auth::user(), $data['uid'], $data['reason']);
|
||||
}
|
||||
send_admin_success_notification();
|
||||
} catch (\Exception $exception) {
|
||||
send_admin_fail_notification($exception->getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static function buildActionChangeDownloadPos(): Infolists\Components\Actions\Action
|
||||
{
|
||||
return Infolists\Components\Actions\Action::make("changeDownloadPos")
|
||||
->label(fn (User $record) => $record->downloadpos == 'yes' ? __('admin.resources.user.actions.disable_download_privileges_btn') : __('admin.resources.user.actions.enable_download_privileges_btn'))
|
||||
->button()
|
||||
->requiresConfirmation()
|
||||
->visible(fn (User $record): bool => (Auth::user()->class > $record->class))
|
||||
->action(function (User $record) {
|
||||
$userRep = self::getRep();
|
||||
try {
|
||||
$userRep->updateDownloadPrivileges(Auth::user(), $record->id, $record->downloadpos == 'yes' ? 'no' : 'yes');
|
||||
send_admin_success_notification();
|
||||
} catch (\Exception $exception) {
|
||||
send_admin_fail_notification($exception->getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private static function buildActionCancelTwoStepAuthentication(): Infolists\Components\Actions\Action
|
||||
{
|
||||
return Infolists\Components\Actions\Action::make("twoStepAuthentication")
|
||||
->label(__('admin.resources.user.actions.disable_two_step_authentication'))
|
||||
->button()
|
||||
->visible(fn (User $record) => $record->two_step_secret != "")
|
||||
->modalHeading(__('admin.resources.user.actions.disable_two_step_authentication'))
|
||||
->requiresConfirmation()
|
||||
->action(function (user $record) {
|
||||
$userRep = self::getRep();
|
||||
try {
|
||||
$userRep->removeTwoStepAuthentication(Auth::user(), $record->id);
|
||||
send_admin_success_notification();
|
||||
} catch (\Exception $exception) {
|
||||
send_admin_fail_notification($exception->getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
@@ -123,13 +329,13 @@ class UserResource extends Resource
|
||||
public static function getBulkActions(): array
|
||||
{
|
||||
$actions = [];
|
||||
if (Auth::user()->class >= User::CLASS_SYSOP) {
|
||||
if (filament()->auth()->user()->class >= User::CLASS_SYSOP) {
|
||||
$actions[] = Tables\Actions\BulkAction::make('confirm')
|
||||
->label(__('admin.resources.user.actions.confirm_bulk'))
|
||||
->requiresConfirmation()
|
||||
->deselectRecordsAfterCompletion()
|
||||
->action(function (Collection $records) {
|
||||
$rep = new UserRepository();
|
||||
$rep = self::getRep();
|
||||
$rep->confirmUser($records->pluck('id')->toArray());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,10 +13,11 @@ use App\Repositories\ExamRepository;
|
||||
use App\Repositories\MedalRepository;
|
||||
use App\Repositories\UserRepository;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\Concerns\HasRelationManagers;
|
||||
use Filament\Resources\Pages\Concerns\InteractsWithRecord;
|
||||
use Filament\Resources\Pages\Page;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Actions;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -32,13 +33,7 @@ class UserProfile extends ViewRecord
|
||||
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected static string $view = 'filament.resources.user.user-resource.pages.user-profile';
|
||||
|
||||
const EVENT_RECORD_UPDATED = 'recordUpdated';
|
||||
|
||||
protected $listeners = [
|
||||
self::EVENT_RECORD_UPDATED => 'updateRecord'
|
||||
];
|
||||
// protected static string $view = 'filament.resources.user.user-resource.pages.user-profile';
|
||||
|
||||
private function getRep(): UserRepository
|
||||
{
|
||||
@@ -48,11 +43,6 @@ class UserProfile extends ViewRecord
|
||||
return self::$rep;
|
||||
}
|
||||
|
||||
public function updateRecord($id)
|
||||
{
|
||||
$this->record = $this->resolveRecord($id);
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
$actions = [];
|
||||
@@ -61,18 +51,18 @@ class UserProfile extends ViewRecord
|
||||
$actions[] = $this->buildGrantMedalAction();
|
||||
$actions[] = $this->buildAssignExamAction();
|
||||
$actions[] = $this->buildChangeBonusEtcAction();
|
||||
if ($this->record->two_step_secret) {
|
||||
$actions[] = $this->buildDisableTwoStepAuthenticationAction();
|
||||
}
|
||||
if ($this->record->status == User::STATUS_PENDING) {
|
||||
$actions[] = $this->buildConfirmAction();
|
||||
}
|
||||
// if ($this->record->two_step_secret) {
|
||||
// $actions[] = $this->buildDisableTwoStepAuthenticationAction();
|
||||
// }
|
||||
// if ($this->record->status == User::STATUS_PENDING) {
|
||||
// $actions[] = $this->buildConfirmAction();
|
||||
// }
|
||||
$actions[] = $this->buildResetPasswordAction();
|
||||
$actions[] = $this->buildEnableDisableAction();
|
||||
$actions[] = $this->buildEnableDisableDownloadPrivilegesAction();
|
||||
if (user_can('user-change-class')) {
|
||||
$actions[] = $this->buildChangeClassAction();
|
||||
}
|
||||
// $actions[] = $this->buildEnableDisableAction();
|
||||
// $actions[] = $this->buildEnableDisableDownloadPrivilegesAction();
|
||||
// if (user_can('user-change-class')) {
|
||||
// $actions[] = $this->buildChangeClassAction();
|
||||
// }
|
||||
if (user_can('user-delete')) {
|
||||
$actions[] = $this->buildDeleteAction();
|
||||
}
|
||||
@@ -101,10 +91,9 @@ class UserProfile extends ViewRecord
|
||||
} elseif ($data['action'] == 'disable') {
|
||||
$userRep->disableUser(Auth::user(), $data['uid'], $data['reason']);
|
||||
}
|
||||
$this->notify('success', 'Success!');
|
||||
$this->emitSelf(self::EVENT_RECORD_UPDATED, $data['uid']);
|
||||
$this->sendSuccessNotification();
|
||||
} catch (\Exception $exception) {
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
$this->sendFailNotification($exception->getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -118,10 +107,9 @@ class UserProfile extends ViewRecord
|
||||
$userRep = $this->getRep();
|
||||
try {
|
||||
$userRep->removeTwoStepAuthentication(Auth::user(), $this->record->id);
|
||||
$this->notify('success', 'Success!');
|
||||
$this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id);
|
||||
$this->sendSuccessNotification();
|
||||
} catch (\Exception $exception) {
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
$this->sendFailNotification($exception->getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -175,10 +163,9 @@ class UserProfile extends ViewRecord
|
||||
} else {
|
||||
$userRep->incrementDecrement(Auth::user(), $this->record->id, $data['action'], $data['field'], $data['value'], $data['reason']);
|
||||
}
|
||||
$this->notify('success', 'Success!');
|
||||
$this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id);
|
||||
$this->sendSuccessNotification();
|
||||
} catch (\Exception $exception) {
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
$this->sendFailNotification($exception->getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -198,10 +185,9 @@ class UserProfile extends ViewRecord
|
||||
$userRep = $this->getRep();
|
||||
try {
|
||||
$userRep->resetPassword($this->record->id, $data['password'], $data['password_confirmation']);
|
||||
$this->notify('success', 'Success!');
|
||||
$this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id);
|
||||
$this->sendSuccessNotification();
|
||||
} catch (\Exception $exception) {
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
$this->sendFailNotification($exception->getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -223,10 +209,9 @@ class UserProfile extends ViewRecord
|
||||
$examRep = new ExamRepository();
|
||||
try {
|
||||
$examRep->assignToUser($this->record->id, $data['exam_id'], $data['begin'], $data['end']);
|
||||
$this->notify('success', 'Success!');
|
||||
$this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id);
|
||||
$this->sendSuccessNotification();
|
||||
} catch (\Exception $exception) {
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
$this->sendFailNotification($exception->getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -251,10 +236,9 @@ class UserProfile extends ViewRecord
|
||||
$medalRep = new MedalRepository();
|
||||
try {
|
||||
$medalRep->grantToUser($this->record->id, $data['medal_id'], $data['duration']);
|
||||
$this->notify('success', 'Success!');
|
||||
$this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id);
|
||||
$this->sendSuccessNotification();
|
||||
} catch (\Exception $exception) {
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
$this->sendFailNotification($exception->getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -272,8 +256,7 @@ class UserProfile extends ViewRecord
|
||||
$this->record->status = User::STATUS_CONFIRMED;
|
||||
$this->record->info= null;
|
||||
$this->record->save();
|
||||
$this->notify('success', 'Success!');
|
||||
$this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id);
|
||||
$this->sendSuccessNotification();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -287,10 +270,9 @@ class UserProfile extends ViewRecord
|
||||
$userRep = $this->getRep();
|
||||
try {
|
||||
$userRep->updateDownloadPrivileges(Auth::user(), $this->record->id, $this->record->downloadpos == 'yes' ? 'no' : 'yes');
|
||||
$this->notify('success', 'Success!');
|
||||
$this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id);
|
||||
$this->sendSuccessNotification();
|
||||
} catch (\Exception $exception) {
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
$this->sendFailNotification($exception->getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -311,15 +293,14 @@ class UserProfile extends ViewRecord
|
||||
$rep = $this->getRep();
|
||||
try {
|
||||
$rep->addMeta($this->record, $data, $data);
|
||||
$this->notify('success', 'Success!');
|
||||
$this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id);
|
||||
$this->sendSuccessNotification();
|
||||
} catch (\Exception $exception) {
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
$this->sendFailNotification($exception->getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function buildDeleteAction(): Actions\Action
|
||||
private function buildDeleteAction(): Actions\DeleteAction
|
||||
{
|
||||
return Actions\DeleteAction::make()->using(function () {
|
||||
$this->getRep()->destroy($this->record->id);
|
||||
@@ -345,7 +326,7 @@ class UserProfile extends ViewRecord
|
||||
$props = [];
|
||||
foreach ($metaList as $metaKey => $metas) {
|
||||
$meta = $metas->first();
|
||||
$text = sprintf('[%s]', $meta->metaKeyText, );
|
||||
$text = sprintf('[%s]', $meta->metaKeyText);
|
||||
if ($meta->meta_key == UserMeta::META_KEY_PERSONALIZED_USERNAME) {
|
||||
$text .= sprintf('(%s)', $meta->getDeadlineText());
|
||||
}
|
||||
@@ -397,11 +378,28 @@ class UserProfile extends ViewRecord
|
||||
$userRep = $this->getRep();
|
||||
try {
|
||||
$userRep->changeClass(Auth::user(), $this->record, $data['class'], $data['reason'], $data);
|
||||
$this->notify('success', 'Success!');
|
||||
$this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id);
|
||||
$this->sendSuccessNotification();
|
||||
} catch (\Exception $exception) {
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
$this->sendFailNotification($exception->getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function sendSuccessNotification(string $msg = ""): void
|
||||
{
|
||||
Notification::make()
|
||||
->success()
|
||||
->title($msg ?: "Success!")
|
||||
->send()
|
||||
;
|
||||
}
|
||||
|
||||
private function sendFailNotification(string $msg = ""): void
|
||||
{
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title($msg ?: "Fail!")
|
||||
->send()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,13 @@ use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
|
||||
/**
|
||||
* @OA\Info(
|
||||
* title="NexusPHP API",
|
||||
* version="1.0"
|
||||
* )
|
||||
*/
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
@@ -66,27 +66,27 @@ class Claim extends NexusModel
|
||||
return Setting::get('torrent.claim_enabled', 'no') == 'yes';
|
||||
}
|
||||
|
||||
public static function getConfigTorrentTTL()
|
||||
public static function getConfigTorrentTTL(): int
|
||||
{
|
||||
return Setting::get('torrent.claim_torrent_ttl', self::TORRENT_TTL);
|
||||
}
|
||||
|
||||
public static function getConfigUserUpLimit()
|
||||
public static function getConfigUserUpLimit(): int
|
||||
{
|
||||
return Setting::get('torrent.claim_torrent_user_counts_up_limit', self::USER_UP_LIMIT);
|
||||
}
|
||||
|
||||
public static function getConfigTorrentUpLimit()
|
||||
public static function getConfigTorrentUpLimit(): int
|
||||
{
|
||||
return Setting::get('torrent.claim_user_torrent_counts_up_limit', self::TORRENT_UP_LIMIT);
|
||||
}
|
||||
|
||||
public static function getConfigRemoveDeductBonus()
|
||||
public static function getConfigRemoveDeductBonus(): int
|
||||
{
|
||||
return Setting::get('torrent.claim_remove_deduct_user_bonus', self::REMOVE_DEDUCT);
|
||||
}
|
||||
|
||||
public static function getConfigGiveUpDeductBonus()
|
||||
public static function getConfigGiveUpDeductBonus(): int
|
||||
{
|
||||
return Setting::get('torrent.claim_give_up_deduct_user_bonus', self::GIVE_UP_DEDUCT);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ class HitAndRun extends NexusModel
|
||||
return '---';
|
||||
}
|
||||
$inspectTime = HitAndRun::getConfig('inspect_time', $searchBoxId);
|
||||
$diffInSeconds = Carbon::now()->diffInSeconds($this->created_at->addHours($inspectTime));
|
||||
$diffInSeconds = Carbon::now()->diffInSeconds($this->created_at->addHours(intval($inspectTime)));
|
||||
return mkprettytime($diffInSeconds);
|
||||
}
|
||||
|
||||
|
||||
@@ -333,6 +333,11 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
);
|
||||
}
|
||||
|
||||
protected function getTwoFactorAuthenticationStatusAttribute(): string
|
||||
{
|
||||
return $this->two_step_secret != "" ? "yes" : "no";
|
||||
}
|
||||
|
||||
public static function getMinSeedPoints($class)
|
||||
{
|
||||
$setting = Setting::get("account.{$class}_min_seed_points");
|
||||
|
||||
@@ -17,7 +17,11 @@ use Illuminate\Cookie\Middleware\EncryptCookies;
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
||||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||||
use Illuminate\Session\Middleware\StartSession;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
use Filament\Tables\Enums\FiltersLayout;
|
||||
use Filament\Tables\Table;
|
||||
use Livewire\Livewire;
|
||||
|
||||
class AppPanelProvider extends PanelProvider
|
||||
{
|
||||
@@ -26,6 +30,11 @@ class AppPanelProvider extends PanelProvider
|
||||
return $panel
|
||||
->default()
|
||||
->id('app')
|
||||
->homeUrl("/")
|
||||
->sidebarWidth("15rem")
|
||||
->topbar(true)
|
||||
->sidebarCollapsibleOnDesktop(true)
|
||||
->authGuard("nexus-web")
|
||||
->path('nexusphp')
|
||||
->login()
|
||||
->colors([
|
||||
@@ -34,26 +43,48 @@ class AppPanelProvider extends PanelProvider
|
||||
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
|
||||
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
|
||||
->pages([
|
||||
Pages\Dashboard::class,
|
||||
// Pages\Dashboard::class,
|
||||
\App\Filament\Pages\Dashboard::class,
|
||||
])
|
||||
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
|
||||
->widgets([
|
||||
Widgets\AccountWidget::class,
|
||||
Widgets\FilamentInfoWidget::class,
|
||||
// Widgets\AccountWidget::class,
|
||||
// Widgets\FilamentInfoWidget::class,
|
||||
])
|
||||
->middleware([
|
||||
EncryptCookies::class,
|
||||
// EncryptCookies::class,
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
AddQueuedCookiesToResponse::class,
|
||||
StartSession::class,
|
||||
AuthenticateSession::class,
|
||||
// AuthenticateSession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
VerifyCsrfToken::class,
|
||||
SubstituteBindings::class,
|
||||
DisableBladeIconComponents::class,
|
||||
DispatchServingFilamentEvent::class,
|
||||
\App\Http\Middleware\Locale::class,
|
||||
])
|
||||
->authMiddleware([
|
||||
Authenticate::class,
|
||||
\App\Http\Middleware\Filament::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
Table::configureUsing(function (Table $table): void {
|
||||
$table
|
||||
->filtersLayout(FiltersLayout::AboveContent)
|
||||
->paginationPageOptions([10, 25, 50, 100])
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
public function register(): void
|
||||
{
|
||||
parent::register(); // TODO: Change the autogenerated stub
|
||||
Livewire::setUpdateRoute(function ($handle) {
|
||||
return Route::post('/livewire/update', $handle)->middleware('filament');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
class GoogleDriveAdapter extends \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter
|
||||
{
|
||||
public function getService()
|
||||
{
|
||||
return $this->service;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user