Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
15d72be4ee
9 changed files with 71 additions and 52 deletions
|
@ -5,6 +5,7 @@ namespace App\Actions\Fortify;
|
|||
use App\Models\User;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Throwable;
|
||||
|
||||
class LoginUser
|
||||
{
|
||||
|
@ -14,25 +15,31 @@ class LoginUser
|
|||
* @param $userInfo
|
||||
* 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();
|
||||
if ($user) {
|
||||
$user['role'] = ($user->getRoleNames())->first();
|
||||
$password = $user->getAuthPassword();
|
||||
// Check if the stored password is an MD5 hash
|
||||
if (strlen($password) === 32 && ctype_xdigit($password)) {
|
||||
if (md5($userInfo['password']) === $password) {
|
||||
return $user;
|
||||
try {
|
||||
$user = User::where('login', $userInfo['username'])->first();
|
||||
if ($user) {
|
||||
$password = User::where('pass',md5($userInfo['password']))->orWhere('pass',Hash::make($userInfo['password']))->first();
|
||||
if ($password) {
|
||||
$user['role'] = ($user->getRoleNames())->first();
|
||||
$password = $user->getAuthPassword();
|
||||
// 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
|
||||
if (Hash::check($userInfo['password'], $password)) {
|
||||
return $user;
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
return $e;
|
||||
}
|
||||
throw new Exception('User not found', 401);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ const { items, listData, headers, selected, loading, search, getItems, editItem,
|
|||
const itemEdited = ref({
|
||||
id: null
|
||||
})
|
||||
|
||||
const bulk = ref(false)
|
||||
const dialog = reactive({
|
||||
open: false,
|
||||
|
@ -38,14 +39,16 @@ const edit = (item) => {
|
|||
const save = (item) => {
|
||||
if (item.name === '') {
|
||||
//Check required fields
|
||||
console.log('error')
|
||||
console.log('error!')
|
||||
}
|
||||
console.log(item)
|
||||
|
||||
if (item.id > 0) {
|
||||
const saved = editItem(item)
|
||||
console.log(saved)
|
||||
} else {
|
||||
delete item.id
|
||||
createItem(item)
|
||||
const saved = createItem(item)
|
||||
console.log(saved)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ const userName = auth.userData.login;
|
|||
|
||||
const logout = () => {
|
||||
auth.logout();
|
||||
router.push('/');
|
||||
router.push('/login');
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {reactive, ref} from "vue";
|
||||
import axios from "axios";
|
||||
import {timeFormatter} from "@/helpers/TimeFormatter.ts";
|
||||
|
||||
export function playlist_page() {
|
||||
const items = ref([])
|
||||
|
@ -39,7 +40,11 @@ export function playlist_page() {
|
|||
listData.page = response.data.current_page;
|
||||
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;
|
||||
|
||||
}).catch((error) => {
|
||||
|
|
|
@ -20,7 +20,6 @@ export function timeFormatter(time: String): string {
|
|||
}
|
||||
|
||||
export function formatFromSeconds(seconds: number): string {
|
||||
console.log(seconds)
|
||||
if (seconds.includes(':')) {
|
||||
let timeArray = seconds.split(':');
|
||||
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 minutes = seconds / 60;
|
||||
let hours = minutes / 60;
|
||||
console.log(seconds, minutes, hours)
|
||||
if (parseInt(hours) > 0) {
|
||||
stringTime += (hours < 10) ? '0' : '';
|
||||
stringTime += parseInt(hours) + ':';
|
||||
seconds = seconds - (parseInt(hours) * 3600);
|
||||
console.log(stringTime)
|
||||
}
|
||||
if (parseInt(hours) > 0 || parseInt(minutes) > 0) {
|
||||
minutes = minutes - (parseInt(hours) * 60);
|
||||
|
@ -41,10 +38,8 @@ export function formatFromSeconds(seconds: number): string {
|
|||
stringTime += parseInt(minutes) + ':';
|
||||
seconds = seconds - (parseInt(minutes) * 60);
|
||||
seconds = seconds.toFixed(2);
|
||||
console.log(stringTime)
|
||||
}
|
||||
stringTime += (seconds < 10) ? '0' : '';
|
||||
stringTime += seconds;
|
||||
console.log(stringTime)
|
||||
return stringTime;
|
||||
}
|
|
@ -8,6 +8,7 @@ const data = reactive({
|
|||
'username': null,
|
||||
'password': null,
|
||||
'loading': false,
|
||||
'errors': {}
|
||||
});
|
||||
|
||||
const router = useRouter();
|
||||
|
@ -22,7 +23,7 @@ const onSubmit = () => {
|
|||
password: data.password,
|
||||
}).then(async (response) => {
|
||||
if (response.status === 200) {
|
||||
console.log(response.data);
|
||||
console.log(response);
|
||||
const timezone = await setTimezone(response.data);
|
||||
const auth = useAuthStore();
|
||||
const userStore = {
|
||||
|
@ -32,30 +33,22 @@ 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('/');
|
||||
} else {
|
||||
console.log(response)
|
||||
}
|
||||
}).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> => {
|
||||
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;
|
||||
|
@ -85,6 +78,8 @@ const required = (v) => {
|
|||
label="Username"
|
||||
name="username"
|
||||
autocomplete="username"
|
||||
:error-messages="data.errors?.username"
|
||||
hide-details="auto"
|
||||
></v-text-field>
|
||||
<v-text-field
|
||||
v-model="data.password"
|
||||
|
@ -93,6 +88,8 @@ const required = (v) => {
|
|||
name="password"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
:error-messages="data.errors?.username"
|
||||
hide-details="auto"
|
||||
></v-text-field>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
|
|
|
@ -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;
|
||||
|
@ -47,9 +48,18 @@ Route::resources([
|
|||
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', [ShowInstancesController::class, 'testSchedule']);
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue