mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 00:34:44 +02:00
Allow user to switch time zones (#332)
* Description not required * Overwrite to use user’s time zone * Allow users to change time zones * Update app/Filament/Resources/UserResource/Pages/EditProfile.php Co-authored-by: Boy132 <Boy132@users.noreply.github.com> * Pint fix --------- Co-authored-by: Charles <charles@pelican.dev> Co-authored-by: Boy132 <Boy132@users.noreply.github.com>
This commit is contained in:
parent
fc92a87993
commit
cf37994c3b
@ -13,6 +13,7 @@ use chillerlan\QRCode\Common\EccLevel;
|
|||||||
use chillerlan\QRCode\Common\Version;
|
use chillerlan\QRCode\Common\Version;
|
||||||
use chillerlan\QRCode\QRCode;
|
use chillerlan\QRCode\QRCode;
|
||||||
use chillerlan\QRCode\QROptions;
|
use chillerlan\QRCode\QROptions;
|
||||||
|
use DateTimeZone;
|
||||||
use Filament\Forms\Components\Actions\Action;
|
use Filament\Forms\Components\Actions\Action;
|
||||||
use Filament\Forms\Components\Grid;
|
use Filament\Forms\Components\Grid;
|
||||||
use Filament\Forms\Components\Placeholder;
|
use Filament\Forms\Components\Placeholder;
|
||||||
@ -85,6 +86,12 @@ class EditProfile extends \Filament\Pages\Auth\EditProfile
|
|||||||
->visible(fn (Get $get): bool => filled($get('password')))
|
->visible(fn (Get $get): bool => filled($get('password')))
|
||||||
->dehydrated(false),
|
->dehydrated(false),
|
||||||
|
|
||||||
|
Select::make('timezone')
|
||||||
|
->required()
|
||||||
|
->prefixIcon('tabler-clock-pin')
|
||||||
|
->options(fn () => collect(DateTimeZone::listIdentifiers())->mapWithKeys(fn ($tz) => [$tz => $tz]))
|
||||||
|
->searchable(),
|
||||||
|
|
||||||
Select::make('language')
|
Select::make('language')
|
||||||
->label(trans('strings.language'))
|
->label(trans('strings.language'))
|
||||||
->required()
|
->required()
|
||||||
@ -193,8 +200,10 @@ class EditProfile extends \Filament\Pages\Auth\EditProfile
|
|||||||
->schema([
|
->schema([
|
||||||
Grid::make('asdf')->columns(5)->schema([
|
Grid::make('asdf')->columns(5)->schema([
|
||||||
Section::make('Create API Key')->columnSpan(3)->schema([
|
Section::make('Create API Key')->columnSpan(3)->schema([
|
||||||
|
|
||||||
TextInput::make('description')
|
TextInput::make('description')
|
||||||
->live(),
|
->live(),
|
||||||
|
|
||||||
TagsInput::make('allowed_ips')
|
TagsInput::make('allowed_ips')
|
||||||
->live()
|
->live()
|
||||||
->splitKeys([',', ' ', 'Tab'])
|
->splitKeys([',', ' ', 'Tab'])
|
||||||
|
@ -2,7 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Carbon\CarbonInterface;
|
||||||
|
use DateTimeInterface;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Date;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Container\Container;
|
use Illuminate\Container\Container;
|
||||||
@ -12,6 +16,7 @@ use App\Exceptions\Model\DataValidationException;
|
|||||||
use Illuminate\Database\Eloquent\Model as IlluminateModel;
|
use Illuminate\Database\Eloquent\Model as IlluminateModel;
|
||||||
use Illuminate\Validation\Factory as ValidationFactory;
|
use Illuminate\Validation\Factory as ValidationFactory;
|
||||||
use Illuminate\Validation\Validator;
|
use Illuminate\Validation\Validator;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
abstract class Model extends IlluminateModel
|
abstract class Model extends IlluminateModel
|
||||||
{
|
{
|
||||||
@ -64,6 +69,36 @@ abstract class Model extends IlluminateModel
|
|||||||
return 'uuid';
|
return 'uuid';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function asDateTime($value)
|
||||||
|
{
|
||||||
|
$timezone = auth()->user()?->timezone ?? config('app.timezone', 'UTC');
|
||||||
|
|
||||||
|
if ($value instanceof CarbonInterface) {
|
||||||
|
return Date::instance($value->timezone($timezone));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value instanceof DateTimeInterface) {
|
||||||
|
return Date::parse($value->format('Y-m-d H:i:s.u'), $timezone);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_numeric($value)) {
|
||||||
|
return Date::createFromTimestamp($value, $timezone);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->isStandardDateFormat($value)) {
|
||||||
|
return Date::instance(Carbon::createFromFormat('Y-m-d', $value)->timezone($timezone)->startOfDay());
|
||||||
|
}
|
||||||
|
|
||||||
|
$format = $this->getDateFormat();
|
||||||
|
try {
|
||||||
|
$date = Date::createFromFormat($format, $value)->timezone($timezone);
|
||||||
|
} catch (InvalidArgumentException) {
|
||||||
|
$date = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $date ?: Date::parse($value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the validator instance used by this model.
|
* Returns the validator instance used by this model.
|
||||||
*/
|
*/
|
||||||
|
@ -123,6 +123,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|||||||
'name_last',
|
'name_last',
|
||||||
'password',
|
'password',
|
||||||
'language',
|
'language',
|
||||||
|
'timezone',
|
||||||
'use_totp',
|
'use_totp',
|
||||||
'totp_secret',
|
'totp_secret',
|
||||||
'totp_authenticated_at',
|
'totp_authenticated_at',
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->string('timezone')->default('UTC')->after('language');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('timezone');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user