|
@@ -1,14 +1,13 @@
|
|
|
<?php
|
|
|
require_once "dependencies.php";
|
|
|
|
|
|
-// Simplify the assignment of $page
|
|
|
-$page = 'login';
|
|
|
-if (isset($_SESSION['moodle_db'])) {
|
|
|
+if (isset($_SESSION['moodle_db'], $_SESSION['user'])) {
|
|
|
$page = 'menu';
|
|
|
} else if (isset($_SESSION['user'])) {
|
|
|
$page = 'host';
|
|
|
+} else {
|
|
|
+ $page = 'login';
|
|
|
}
|
|
|
-$moodle_db = isset($_SESSION['moodle_db']) ? makeConnection($_SESSION['moodle_db']) : null;
|
|
|
?>
|
|
|
<!DOCTYPE html>
|
|
|
<html lang="en">
|
|
@@ -24,10 +23,17 @@ $moodle_db = isset($_SESSION['moodle_db']) ? makeConnection($_SESSION['moodle_db
|
|
|
const store = PetiteVue.reactive({
|
|
|
error: null,
|
|
|
loading: false,
|
|
|
+ token: sessionStorage.getItem('token'),
|
|
|
|
|
|
async fetch(url, options = {}, custom_error = null) {
|
|
|
store.loading = true
|
|
|
- const response = await fetch(url, options)
|
|
|
+ const response = await fetch(url, {
|
|
|
+ ...options,
|
|
|
+ headers: {
|
|
|
+ ...options.headers,
|
|
|
+ 'Authorization': `Bearer ${store.token}`
|
|
|
+ }
|
|
|
+ })
|
|
|
store.loading = false
|
|
|
|
|
|
if (!response.ok) {
|
|
@@ -43,7 +49,7 @@ $moodle_db = isset($_SESSION['moodle_db']) ? makeConnection($_SESSION['moodle_db
|
|
|
class: 'primary'
|
|
|
}]
|
|
|
}
|
|
|
- return
|
|
|
+ return []
|
|
|
}
|
|
|
|
|
|
return response.json()
|
|
@@ -60,13 +66,13 @@ $moodle_db = isset($_SESSION['moodle_db']) ? makeConnection($_SESSION['moodle_db
|
|
|
<?php if (isset($_SESSION['user']) || isset($_SESSION['moodle_db'])) : ?>
|
|
|
<div class="grid">
|
|
|
<?php if (isset($_SESSION['user'])) : ?>
|
|
|
- <form action="/action/desconectar.php" method="post">
|
|
|
+ <form action="/action/desconectar.php">
|
|
|
<input type="hidden" name="action" value="sign-out">
|
|
|
- <button type="submit">Cerrar sesión <i class="fas fa-sign-out-alt"></i></button>
|
|
|
+ <button type="submit" @click="sessionStorage.removeItem('token')">Cerrar sesión <i class="fas fa-sign-out-alt"></i></button>
|
|
|
</form>
|
|
|
<?php endif; ?>
|
|
|
<?php if (isset($_SESSION['moodle_db'])) : ?>
|
|
|
- <form action="/action/desconectar.php" method="post">
|
|
|
+ <form action="/action/desconectar.php">
|
|
|
<input type="hidden" name="action" value="desconectar">
|
|
|
<button type="submit">Desconectar <i class="fas fa-times-circle"></i></button>
|
|
|
</form>
|
|
@@ -76,9 +82,6 @@ $moodle_db = isset($_SESSION['moodle_db']) ? makeConnection($_SESSION['moodle_db
|
|
|
</div>
|
|
|
</div>
|
|
|
</nav>
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
<div class="container" v-scope>
|
|
|
<dialog :open="store.loading">
|
|
|
<div class="grid">
|
|
@@ -89,18 +92,18 @@ $moodle_db = isset($_SESSION['moodle_db']) ? makeConnection($_SESSION['moodle_db
|
|
|
<dialog :open="store.error !== null" v-if="store.error">
|
|
|
<article>
|
|
|
<header>
|
|
|
- <a href="#close" aria-label="Close" class="close" @click="store.error = null" v-if="store.error.avoidable"></a>
|
|
|
+ <a href="#close" aria-label="Close" class="close" @click="store.error = null" v-if="store.error?.avoidable"></a>
|
|
|
<strong>
|
|
|
- {{ store.error.title }}
|
|
|
+ {{ store.error?.title }}
|
|
|
</strong>
|
|
|
</header>
|
|
|
<p>
|
|
|
- {{ store.error.message }}
|
|
|
+ {{ store.error?.message }}
|
|
|
|
|
|
</p>
|
|
|
<br>
|
|
|
<div class="grid">
|
|
|
- <button v-for="action in store.error.actions" @click="action.handler" :class="action.class">
|
|
|
+ <button v-for="action in store.error?.actions ?? []" @click="action.handler" :class="action.class">
|
|
|
{{ action.label }}
|
|
|
</button>
|
|
|
</div>
|