diff --git a/frontend/src/components/Mappa/Mappa.vue b/frontend/src/components/Mappa/Mappa.vue index 9f600b1..adfa17d 100644 --- a/frontend/src/components/Mappa/Mappa.vue +++ b/frontend/src/components/Mappa/Mappa.vue @@ -41,7 +41,6 @@ onMounted(() => { return emergency.coordinates.lat !== null && emergency.coordinates.lon !== null; }) - console.log(filteredEmergencies) }); @@ -70,7 +69,7 @@ onMounted(() => { - @@ -95,8 +94,12 @@ onMounted(() => { .btn-segnalazione { position: absolute; - bottom: 27px; - right: 10px; z-index: 500; + border: 2px #808080 solid; + + width: 200px; + height: 50px; + bottom: 35px; + right: 15px; } diff --git a/frontend/src/views/user/ViewAccedi.vue b/frontend/src/views/user/ViewAccedi.vue index ede918f..5800c63 100644 --- a/frontend/src/views/user/ViewAccedi.vue +++ b/frontend/src/views/user/ViewAccedi.vue @@ -79,6 +79,11 @@ onMounted(() => { createToast("info", "Accedi!", "Per visualizzare la pagina, devi prima effettuare l'accesso"); } + // Toast di reindirizzamento dopo cambio password + if (route.query.passwordChange === 'true') { + createToast("info", "Accedi!", "Dopo il cambio della password devi rieffettuare l'accesso"); + } + google.accounts.id.initialize({ client_id: import.meta.env.VITE_GOOGLE_CLIENT_ID, callback: handleCredentialResponse diff --git a/frontend/src/views/user/ViewProfilo.vue b/frontend/src/views/user/ViewProfilo.vue index 4710848..a81536a 100644 --- a/frontend/src/views/user/ViewProfilo.vue +++ b/frontend/src/views/user/ViewProfilo.vue @@ -12,8 +12,9 @@ import { reports, getMyReports } from '@/data/reports' const route = useRoute() const router = useRouter() -const password = ref() -const confirmPassword = ref() +const oldPassword = ref("") +const newPassword = ref("") +const confirmNewPassword = ref("") const showPassword = ref(false) const showToast = ref(false) @@ -63,6 +64,51 @@ function formatRole(role) { return (role === "citizen") ? "Cittadino" : "Operatore"; } +// Funzione per cambiare la password dell'utente +async function changePassword() { + if (newPassword.value.length < 8) { + createToast("warning", "Attenzione!", "Inserisci una password di almeno 8 caratteri"); + return; + } + + if (newPassword.value === "" || confirmNewPassword.value === "") { + createToast("warning", "Attenzione!", "I campi non possono essere vuoti"); + return; + } + + if (newPassword.value !== confirmNewPassword.value) { + createToast("warning", "Attenzione!", "Le password non corrispondono"); + return; + } + + try { + const apiPassword = import.meta.env.VITE_API_BASE_URL + "/users/" + + const resp = await fetch(apiPassword + loggedUser.id + "/password", { + method: 'PUT', + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${loggedUser.token}`, + }, + body: JSON.stringify({ + oldPassword: oldPassword.value, + newPassword: newPassword.value + }), + }); + + // Se il cambio password va a buon fine, effettuo il logout e reindirizzo alla pagina di login + if (resp.ok) { + clearLoggedUser(); + router.push({ path: '/accedi', query: { passwordChange: 'true' } }); + } else { + const errorData = await resp.json(); + createToast("error", "Errore!", errorData.message); + } + } catch (error) { + createToast("error", "Errore!", error.message); + } +} + function togglePasswordView() { const passwordInput = document.getElementById("passwordInput"); @@ -148,10 +194,15 @@ function createToast(type, title, msg) {

Cambia password:

-
-