Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Michael 2025-04-18 11:12:10 +02:00
commit 15d72be4ee
9 changed files with 71 additions and 52 deletions

View file

@ -5,6 +5,7 @@ namespace App\Actions\Fortify;
use App\Models\User; use App\Models\User;
use Exception; use Exception;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Throwable;
class LoginUser class LoginUser
{ {
@ -14,25 +15,31 @@ class LoginUser
* @param $userInfo * @param $userInfo
* username and password. * username and password.
* *
* @return User|null The authenticated user if successful, otherwise null.
*/ */
public static function login($userInfo): ?User public static function login($userInfo)
{ {
$user = User::where('login', $userInfo['username'])->first(); try {
if ($user) { $user = User::where('login', $userInfo['username'])->first();
$user['role'] = ($user->getRoleNames())->first(); if ($user) {
$password = $user->getAuthPassword(); $password = User::where('pass',md5($userInfo['password']))->orWhere('pass',Hash::make($userInfo['password']))->first();
// Check if the stored password is an MD5 hash if ($password) {
if (strlen($password) === 32 && ctype_xdigit($password)) { $user['role'] = ($user->getRoleNames())->first();
if (md5($userInfo['password']) === $password) { $password = $user->getAuthPassword();
return $user; // Check if the stored password is an MD5 hash
if (strlen($password) === 32 && ctype_xdigit($password)) {
if (md5($userInfo['password']) === $password) {
return $user;
}
} else {
if (Hash::check($userInfo['password'], $password)) {
return $user;
}
}
} }
} }
// Otherwise, use Laravel's Hash to check the password } catch (Throwable $e) {
if (Hash::check($userInfo['password'], $password)) { report($e);
return $user; return $e;
}
} }
throw new Exception('User not found', 401);
} }
} }

View file

@ -17,7 +17,7 @@ class Preferences
throw new Exception("User id can't be null for a user preference {$key}."); 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) { if ($isUserValue) {
$pref = $pref->where('subjid', $userId); $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 { try {
$userId = Auth::id(); $userId = Auth::id();
@ -45,7 +45,7 @@ class Preferences
throw new Exception("User id can't be null for a user preference {$key}."); 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) { if ($isUserValue) {
$pref = $pref->where('subjid', $userId); $pref = $pref->where('subjid', $userId);
} }
@ -61,12 +61,13 @@ class Preferences
} catch (Exception $e) { } catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable'); header('HTTP/1.0 503 Service Unavailable');
Log::info('Database error: ' . $e->getMessage()); return false;
die(); // Log::info('Database error: ' . $e->getMessage());
// die();
} }
} }
public function getDefaultTimeZone() { public static function getDefaultTimeZone() {
return config('app.timezone'); return config('app.timezone');
} }

View file

@ -10,6 +10,7 @@ const { items, listData, headers, selected, loading, search, getItems, editItem,
const itemEdited = ref({ const itemEdited = ref({
id: null id: null
}) })
const bulk = ref(false) const bulk = ref(false)
const dialog = reactive({ const dialog = reactive({
open: false, open: false,
@ -38,14 +39,16 @@ const edit = (item) => {
const save = (item) => { const save = (item) => {
if (item.name === '') { if (item.name === '') {
//Check required fields //Check required fields
console.log('error') console.log('error!')
} }
console.log(item)
if (item.id > 0) { if (item.id > 0) {
const saved = editItem(item) const saved = editItem(item)
console.log(saved)
} else { } else {
delete item.id delete item.id
createItem(item) const saved = createItem(item)
console.log(saved)
} }
} }

View file

@ -1,14 +1,15 @@
<script setup lang="ts"> <script setup lang="ts">
import {useAuthStore} from "@/stores/auth.store.ts"; import {useAuthStore} from "@/stores/auth.store.ts";
import {computed, ref} from "vue"; import {computed, ref} from "vue";
import {DateTime} from "luxon";
const auth = useAuthStore(); const auth = useAuthStore();
const timezone = auth.userData.timezone; 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(() => { 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) }, 1000)
</script> </script>

View file

@ -11,7 +11,7 @@ const userName = auth.userData.login;
const logout = () => { const logout = () => {
auth.logout(); auth.logout();
router.push('/'); router.push('/login');
} }
</script> </script>

View file

@ -1,5 +1,6 @@
import {reactive, ref} from "vue"; import {reactive, ref} from "vue";
import axios from "axios"; import axios from "axios";
import {timeFormatter} from "@/helpers/TimeFormatter.ts";
export function playlist_page() { export function playlist_page() {
const items = ref([]) const items = ref([])
@ -39,7 +40,11 @@ export function playlist_page() {
listData.page = response.data.current_page; listData.page = response.data.current_page;
listData.total_items = response.data.total; listData.total_items = response.data.total;
items.value = response.data.data items.value = response.data.data.map(el => {
console.log(el.length)
el.length = timeFormatter(el.length);
return el;
});
loading.value = false; loading.value = false;
}).catch((error) => { }).catch((error) => {

View file

@ -20,7 +20,6 @@ export function timeFormatter(time: String): string {
} }
export function formatFromSeconds(seconds: number): string { export function formatFromSeconds(seconds: number): string {
console.log(seconds)
if (seconds.includes(':')) { if (seconds.includes(':')) {
let timeArray = seconds.split(':'); let timeArray = seconds.split(':');
seconds = (parseInt(timeArray[0])*3600)+(parseInt(timeArray[1])*60)+parseFloat(timeArray[2]); seconds = (parseInt(timeArray[0])*3600)+(parseInt(timeArray[1])*60)+parseFloat(timeArray[2]);
@ -28,12 +27,10 @@ export function formatFromSeconds(seconds: number): string {
let stringTime = ''; let stringTime = '';
let minutes = seconds / 60; let minutes = seconds / 60;
let hours = minutes / 60; let hours = minutes / 60;
console.log(seconds, minutes, hours)
if (parseInt(hours) > 0) { if (parseInt(hours) > 0) {
stringTime += (hours < 10) ? '0' : ''; stringTime += (hours < 10) ? '0' : '';
stringTime += parseInt(hours) + ':'; stringTime += parseInt(hours) + ':';
seconds = seconds - (parseInt(hours) * 3600); seconds = seconds - (parseInt(hours) * 3600);
console.log(stringTime)
} }
if (parseInt(hours) > 0 || parseInt(minutes) > 0) { if (parseInt(hours) > 0 || parseInt(minutes) > 0) {
minutes = minutes - (parseInt(hours) * 60); minutes = minutes - (parseInt(hours) * 60);
@ -41,10 +38,8 @@ export function formatFromSeconds(seconds: number): string {
stringTime += parseInt(minutes) + ':'; stringTime += parseInt(minutes) + ':';
seconds = seconds - (parseInt(minutes) * 60); seconds = seconds - (parseInt(minutes) * 60);
seconds = seconds.toFixed(2); seconds = seconds.toFixed(2);
console.log(stringTime)
} }
stringTime += (seconds < 10) ? '0' : ''; stringTime += (seconds < 10) ? '0' : '';
stringTime += seconds; stringTime += seconds;
console.log(stringTime)
return stringTime; return stringTime;
} }

View file

@ -8,6 +8,7 @@ const data = reactive({
'username': null, 'username': null,
'password': null, 'password': null,
'loading': false, 'loading': false,
'errors': {}
}); });
const router = useRouter(); const router = useRouter();
@ -22,7 +23,7 @@ const onSubmit = () => {
password: data.password, password: data.password,
}).then(async (response) => { }).then(async (response) => {
if (response.status === 200) { if (response.status === 200) {
console.log(response.data); console.log(response);
const timezone = await setTimezone(response.data); const timezone = await setTimezone(response.data);
const auth = useAuthStore(); const auth = useAuthStore();
const userStore = { const userStore = {
@ -32,30 +33,22 @@ const onSubmit = () => {
} }
auth.setUserData(userStore); 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('/'); router.push('/');
} else {
console.log(response)
} }
}).catch((error) => { }).catch((error) => {
console.log('Error: ' + error); console.log(error);
data.errors = error.response.data.errors
data.loading = false;
console.log(data)
}); });
} }
const setTimezone = (user): Promise<string> => { const setTimezone = (user): Promise<string> => {
console.log(user); return axios.get("timezone").then((res) => {
return axios.get("http://127.0.0.1:9876/api/v2/preferences", { return res.data;
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;
}).catch(error => { }).catch(error => {
console.log("Error: "+error); console.log("Error: "+error);
return null; return null;
@ -85,6 +78,8 @@ const required = (v) => {
label="Username" label="Username"
name="username" name="username"
autocomplete="username" autocomplete="username"
:error-messages="data.errors?.username"
hide-details="auto"
></v-text-field> ></v-text-field>
<v-text-field <v-text-field
v-model="data.password" v-model="data.password"
@ -93,6 +88,8 @@ const required = (v) => {
name="password" name="password"
type="password" type="password"
autocomplete="current-password" autocomplete="current-password"
:error-messages="data.errors?.username"
hide-details="auto"
></v-text-field> ></v-text-field>
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>

View file

@ -1,5 +1,6 @@
<?php <?php
use App\Helpers\Preferences;
use App\Http\Controllers\Auth\LoginController; use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\FileController; use App\Http\Controllers\FileController;
use App\Http\Controllers\Show\ShowController; use App\Http\Controllers\Show\ShowController;
@ -47,9 +48,18 @@ Route::resources([
Route::get('/file/check_upload_status/{id}', [FileController::class, 'checkUploadStatus']); Route::get('/file/check_upload_status/{id}', [FileController::class, 'checkUploadStatus']);
/** /**
* Test Routes * SmartBlocks additional tracks route
*/ */
Route::post('/smartblock/{id}/tracks', [SmartBlockController::class, 'getTrackList']); 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('/test', [FileController::class, 'test']);
Route::get('/testSchedule', [ShowInstancesController::class, 'testSchedule']); Route::get('/testSchedule', [ShowInstancesController::class, 'testSchedule']);
/** /**