fix(fe login/header): fixed getting the right timezone at login
This commit is contained in:
parent
0498f2fe08
commit
1c3ed7f590
4 changed files with 24 additions and 25 deletions
|
@ -17,7 +17,7 @@ class Preferences
|
|||
throw new Exception("User id can't be null for a user preference {$key}.");
|
||||
}
|
||||
|
||||
$pref = Preference::where('key', $key);
|
||||
$pref = Preference::where('keystr', $key);
|
||||
if ($isUserValue) {
|
||||
$pref = $pref->where('subjid', $userId);
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class Preferences
|
|||
}
|
||||
}
|
||||
|
||||
private function getValue($key, $isUserValue = false, $forceDefault = false) {
|
||||
private static function getValue($key, $isUserValue = false, $forceDefault = false) {
|
||||
try {
|
||||
$userId = Auth::id();
|
||||
|
||||
|
@ -45,7 +45,7 @@ class Preferences
|
|||
throw new Exception("User id can't be null for a user preference {$key}.");
|
||||
}
|
||||
|
||||
$pref = Preference::where('key', $key);
|
||||
$pref = Preference::where('keystr', $key);
|
||||
if ($isUserValue) {
|
||||
$pref = $pref->where('subjid', $userId);
|
||||
}
|
||||
|
@ -61,12 +61,13 @@ class Preferences
|
|||
|
||||
} catch (Exception $e) {
|
||||
header('HTTP/1.0 503 Service Unavailable');
|
||||
Log::info('Database error: ' . $e->getMessage());
|
||||
die();
|
||||
return false;
|
||||
// Log::info('Database error: ' . $e->getMessage());
|
||||
// die();
|
||||
}
|
||||
}
|
||||
|
||||
public function getDefaultTimeZone() {
|
||||
public static function getDefaultTimeZone() {
|
||||
return config('app.timezone');
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
<script setup lang="ts">
|
||||
import {useAuthStore} from "@/stores/auth.store.ts";
|
||||
import {computed, ref} from "vue";
|
||||
import {DateTime} from "luxon";
|
||||
|
||||
const auth = useAuthStore();
|
||||
const timezone = auth.userData.timezone;
|
||||
|
||||
const time = ref(new Date().toLocaleString("it-IT", {timeZone: timezone}));
|
||||
const time = ref(DateTime.now().setZone(timezone).setLocale('it').toLocaleString(DateTime.DATETIME_FULL_WITH_SECONDS));
|
||||
|
||||
setInterval(() => {
|
||||
time.value = new Date().toLocaleString("it-IT", {timeZone: timezone});
|
||||
time.value = DateTime.now().setZone(timezone).setLocale('it').toLocaleString(DateTime.DATETIME_FULL_WITH_SECONDS)
|
||||
}, 1000)
|
||||
</script>
|
||||
|
||||
|
|
|
@ -32,11 +32,6 @@ const onSubmit = () => {
|
|||
}
|
||||
auth.setUserData(userStore);
|
||||
|
||||
//To check data uncomment the timezone const, the timezone line in user object
|
||||
// and the console.log below. Then comment router.push('/')
|
||||
|
||||
// console.log(auth.userData)
|
||||
|
||||
router.push('/');
|
||||
}
|
||||
}).catch((error) => {
|
||||
|
@ -45,17 +40,8 @@ const onSubmit = () => {
|
|||
}
|
||||
|
||||
const setTimezone = (user): Promise<string> => {
|
||||
console.log(user);
|
||||
return axios.get("http://127.0.0.1:9876/api/v2/preferences", {
|
||||
auth: {
|
||||
username: user.login,
|
||||
password: data.password
|
||||
}
|
||||
}).then((res) => {
|
||||
const appConfig = res.data;
|
||||
console.log(res);
|
||||
const timezoneSetting = appConfig.find(setting => setting.key == 'user_timezone');
|
||||
return timezoneSetting?.value ? timezoneSetting.value : import.meta.env.VITE_APP_TIMEZONE;
|
||||
return axios.get("timezone").then((res) => {
|
||||
return res.data;
|
||||
}).catch(error => {
|
||||
console.log("Error: "+error);
|
||||
return null;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use App\Helpers\Preferences;
|
||||
use App\Http\Controllers\Auth\LoginController;
|
||||
use App\Http\Controllers\FileController;
|
||||
use App\Http\Controllers\Show\ShowController;
|
||||
|
@ -43,15 +44,25 @@ Route::resources([
|
|||
|
||||
Route::delete('/show', [ShowController::class, 'destroy']);
|
||||
Route::delete('/showInstances', [ShowInstancesController::class, 'destroy']);
|
||||
|
||||
/**
|
||||
* Custom file route
|
||||
*/
|
||||
Route::get('/file/check_upload_status/{id}', [FileController::class, 'checkUploadStatus']);
|
||||
|
||||
/**
|
||||
* Test Routes
|
||||
* SmartBlocks additional tracks route
|
||||
*/
|
||||
Route::post('/smartblock/{id}/tracks', [SmartBlockController::class, 'getTrackList']);
|
||||
|
||||
/**
|
||||
* Preferences custom routes
|
||||
*/
|
||||
Route::get('/timezone', [Preferences::class, 'getTimezone']);
|
||||
|
||||
/**
|
||||
* Test Routes
|
||||
*/
|
||||
Route::get('/test', [FileController::class, 'test']);
|
||||
Route::get('/testSchedule/{id}', [ShowController::class, 'testSchedule']);
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue