Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

fix: accept deprecated timezones during registration

Paulo Castellano84911dcb348d
diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php
index 746b07047..85284ffbf 100644
--- a/app/Http/Controllers/Auth/RegisteredUserController.php
+++ b/app/Http/Controllers/Auth/RegisteredUserController.php
@@ -6,6 +6,7 @@ namespace App\Http\Controllers\Auth;
use App\Enums\User\Setup;
use App\Http\Controllers\Controller;
+use App\Rules\Timezone;
use App\Models\Language;
use App\Models\User;
use App\Models\Workspace;
@@ -40,7 +41,7 @@ class RegisteredUserController extends Controller
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
'password' => ['required', Rules\Password::defaults()],
- 'timezone' => ['nullable', 'string', 'timezone'],
+ 'timezone' => ['nullable', 'string', new Timezone],
]);
// Check if registering via invite link (redirect contains /invites/)
diff --git a/app/Http/Requests/UpdateWorkspaceRequest.php b/app/Http/Requests/UpdateWorkspaceRequest.php
index fd7b2ff83..a96bf0fbf 100644
--- a/app/Http/Requests/UpdateWorkspaceRequest.php
+++ b/app/Http/Requests/UpdateWorkspaceRequest.php
@@ -2,6 +2,7 @@
namespace App\Http\Requests;
+use App\Rules\Timezone;
use Illuminate\Foundation\Http\FormRequest;
class UpdateWorkspaceRequest extends FormRequest
@@ -15,7 +16,7 @@ class UpdateWorkspaceRequest extends FormRequest
{
return [
'name' => ['required', 'string', 'max:255'],
- 'timezone' => ['required', 'string', 'timezone:all'],
+ 'timezone' => ['required', 'string', new Timezone],
];
}
diff --git a/app/Rules/Timezone.php b/app/Rules/Timezone.php
new file mode 100644
index 000000000..90301db05
--- /dev/null
+++ b/app/Rules/Timezone.php
@@ -0,0 +1,23 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Rules;
+
+use Closure;
+use Illuminate\Contracts\Validation\ValidationRule;
+
+class Timezone implements ValidationRule
+{
+ /**
+ * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
+ */
+ public function validate(string $attribute, mixed $value, Closure $fail): void
+ {
+ try {
+ new \DateTimeZone($value);
+ } catch (\Exception) {
+ $fail('The :attribute must be a valid timezone.');
+ }
+ }
+}
diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php
index 449799dae..3a5924e1b 100644
--- a/tests/Feature/Auth/RegistrationTest.php
+++ b/tests/Feature/Auth/RegistrationTest.php
@@ -61,6 +61,46 @@ test('new users do not have verified email by default', function () {
expect($user->email_verified_at)->toBeNull();
});
+test('new users can register with deprecated timezone Asia/Calcutta', function () {
+ $this->post(route('register.store'), [
+ 'name' => 'Test User',
+ 'email' => '[email protected]',
+ 'password' => 'Password123!',
+ 'timezone' => 'Asia/Calcutta',
+ ]);
+
+ $user = User::where('email', '[email protected]')->first();
+
+ expect($user)->not->toBeNull();
+ expect($user->workspaces->first()->timezone)->toBe('Asia/Calcutta');
+});
+
+test('new users can register with deprecated timezone US/Eastern', function () {
+ $this->post(route('register.store'), [
+ 'name' => 'Test User',
+ 'email' => '[email protected]',
+ 'password' => 'Password123!',
+ 'timezone' => 'US/Eastern',
+ ]);
+
+ $user = User::where('email', '[email protected]')->first();
+
+ expect($user)->not->toBeNull();
+ expect($user->workspaces->first()->timezone)->toBe('US/Eastern');
+});
+
+test('new users cannot register with invalid timezone', function () {
+ $response = $this->post(route('register.store'), [
+ 'name' => 'Test User',
+ 'email' => '[email protected]',
+ 'password' => 'Password123!',
+ 'timezone' => 'Invalid/Timezone',
+ ]);
+
+ $response->assertSessionHasErrors('timezone');
+ expect(User::where('email', '[email protected]')->exists())->toBeFalse();
+});
+
test('new users registering via invite have verified email automatically', function () {
$this->post(route('register.store'), [
'name' => 'Test User',
diff --git a/tests/Unit/Rules/TimezoneRuleTest.php b/tests/Unit/Rules/TimezoneRuleTest.php
new file mode 100644
index 000000000..2440bb390
--- /dev/null
+++ b/tests/Unit/Rules/TimezoneRuleTest.php
@@ -0,0 +1,46 @@
+<?php
+
+use App\Rules\Timezone;
+use Illuminate\Support\Facades\Validator;
+
+test('accepts valid timezone', function () {
+ $validator = Validator::make(['tz' => 'America/Sao_Paulo'], ['tz' => new Timezone]);
+
+ expect($validator->passes())->toBeTrue();
+});
+
+test('accepts UTC', function () {
+ $validator = Validator::make(['tz' => 'UTC'], ['tz' => new Timezone]);
+
+ expect($validator->passes())->toBeTrue();
+});
+
+test('accepts deprecated timezone Asia/Calcutta', function () {
+ $validator = Validator::make(['tz' => 'Asia/Calcutta'], ['tz' => new Timezone]);
+
+ expect($validator->passes())->toBeTrue();
+});
+
+test('accepts deprecated timezone US/Eastern', function () {
+ $validator = Validator::make(['tz' => 'US/Eastern'], ['tz' => new Timezone]);
+
+ expect($validator->passes())->toBeTrue();
+});
+
+test('rejects invalid timezone', function () {
+ $validator = Validator::make(['tz' => 'Invalid/Timezone'], ['tz' => new Timezone]);
+
+ expect($validator->passes())->toBeFalse();
+});
+
+test('rejects random string', function () {
+ $validator = Validator::make(['tz' => 'blabla'], ['tz' => new Timezone]);
+
+ expect($validator->passes())->toBeFalse();
+});
+
+test('accepts Europe/London', function () {
+ $validator = Validator::make(['tz' => 'Europe/London'], ['tz' => new Timezone]);
+
+ expect($validator->passes())->toBeTrue();
+});