mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 15:51:01 +08:00
Slowly move the login stuff into the settings page.
This commit is contained in:
parent
e089b19326
commit
69017be083
@ -1,5 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { BadgeCheckIcon, OctagonAlertIcon } from "lucide-vue-next";
|
import { BadgeCheckIcon, OctagonAlertIcon } from "lucide-vue-next";
|
||||||
|
import sha512 from "crypto-js/sha512";
|
||||||
|
import Input from "~/components/ui/input/Input.vue";
|
||||||
import { Input } from "~/components/ui/input";
|
import { Input } from "~/components/ui/input";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@ -15,6 +17,7 @@ import { Button } from "@/components/ui/button";
|
|||||||
const { t, locale } = useI18n();
|
const { t, locale } = useI18n();
|
||||||
const user = ref("");
|
const user = ref("");
|
||||||
const enterFirstName = ref();
|
const enterFirstName = ref();
|
||||||
|
const isLoggedIn = ref(false);
|
||||||
const useremail = ref();
|
const useremail = ref();
|
||||||
const userData = ref({
|
const userData = ref({
|
||||||
userAccount: "",
|
userAccount: "",
|
||||||
@ -27,9 +30,14 @@ const enteruseremail = ref();
|
|||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const req = await fetch("/api/user/validateUserToken");
|
const req = await fetch("/api/user/validateUserToken");
|
||||||
const res = await req.json();
|
const res = await req.json();
|
||||||
|
if (res.current_spot === "LOGOUT") {
|
||||||
|
isLoggedIn.value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
user.value = res.firstName;
|
user.value = res.firstName;
|
||||||
userData.value = res;
|
userData.value = res;
|
||||||
useremail.value = res.email;
|
useremail.value = res.email;
|
||||||
|
isLoggedIn.value = true;
|
||||||
});
|
});
|
||||||
const setFirstName = async () => {
|
const setFirstName = async () => {
|
||||||
const staticFirstName = "";
|
const staticFirstName = "";
|
||||||
@ -37,7 +45,13 @@ const setFirstName = async () => {
|
|||||||
|
|
||||||
const emit = defineEmits(["windowopener"]);
|
const emit = defineEmits(["windowopener"]);
|
||||||
|
|
||||||
const logoutAction = () => {};
|
const logoutAction = async () => {
|
||||||
|
// I reget rolling my own auth :(
|
||||||
|
const req = await fetch("/api/user/logout");
|
||||||
|
const res = await req.json();
|
||||||
|
console.log(res);
|
||||||
|
showLogoutDialog.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
const groqApiKeyRegex = /^gsk_[a-zA-Z0-9]{52}$/;
|
const groqApiKeyRegex = /^gsk_[a-zA-Z0-9]{52}$/;
|
||||||
const customApiKey = ref();
|
const customApiKey = ref();
|
||||||
@ -67,9 +81,6 @@ const confirmDelete = async () => {
|
|||||||
showDeleteDialog.value = false;
|
showDeleteDialog.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const confirmLogout = async () => {
|
|
||||||
showLogoutDialog.value = false;
|
|
||||||
};
|
|
||||||
const deleteAccount = async () => {
|
const deleteAccount = async () => {
|
||||||
const req = await fetch("/api/user/action", {
|
const req = await fetch("/api/user/action", {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
@ -124,6 +135,43 @@ const submitChangeAction = async (action: string) => {
|
|||||||
console.error("Failed to submit change:", error);
|
console.error("Failed to submit change:", error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Login function
|
||||||
|
const userAccount = ref("");
|
||||||
|
const userPassword = ref("");
|
||||||
|
const error = ref(false);
|
||||||
|
const errormsg = ref("");
|
||||||
|
const success = ref(false);
|
||||||
|
const submitUserPassword = async () => {
|
||||||
|
error.value = false;
|
||||||
|
errormsg.value = "";
|
||||||
|
// Encrypt password during transit
|
||||||
|
const password = sha512(userPassword.value).toString();
|
||||||
|
|
||||||
|
// Send data.
|
||||||
|
const sendData = await fetch("/api/user/login", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
username: userAccount.value,
|
||||||
|
password: password,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
const res = await sendData.json();
|
||||||
|
|
||||||
|
if (!res.error) {
|
||||||
|
error.value = false;
|
||||||
|
success.value = true;
|
||||||
|
console.log(res);
|
||||||
|
userAccount.value = "";
|
||||||
|
} else {
|
||||||
|
error.value = true;
|
||||||
|
errormsg.value = res.error;
|
||||||
|
}
|
||||||
|
userPassword.value = "";
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="justify-center align-center text-center">
|
<div class="justify-center align-center text-center">
|
||||||
@ -230,7 +278,7 @@ const submitChangeAction = async (action: string) => {
|
|||||||
<Button @click="showLogoutDialog = false" variant="outline">
|
<Button @click="showLogoutDialog = false" variant="outline">
|
||||||
{{ t("popup.cancel") }}
|
{{ t("popup.cancel") }}
|
||||||
</Button>
|
</Button>
|
||||||
<Button @click="confirmLogout" variant="destructive">
|
<Button @click="logoutAction" variant="destructive">
|
||||||
{{ t("popup.confirm") }}
|
{{ t("popup.confirm") }}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
|
@ -6,6 +6,7 @@ export default defineEventHandler(async (event) => {
|
|||||||
return {
|
return {
|
||||||
error: "INVALID_TOKEN",
|
error: "INVALID_TOKEN",
|
||||||
requested_action: "USE_DEFAULT_STATE",
|
requested_action: "USE_DEFAULT_STATE",
|
||||||
|
current_spot: "LOGOUT",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const checkIsUUIDRegex =
|
const checkIsUUIDRegex =
|
||||||
@ -14,6 +15,7 @@ export default defineEventHandler(async (event) => {
|
|||||||
return {
|
return {
|
||||||
error: "NOT_A_UUID",
|
error: "NOT_A_UUID",
|
||||||
requested_action: "LOGOUT_USER",
|
requested_action: "LOGOUT_USER",
|
||||||
|
current_spot: "LOGOUT",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const fetchViaSQL = await sql`
|
const fetchViaSQL = await sql`
|
||||||
@ -24,6 +26,7 @@ export default defineEventHandler(async (event) => {
|
|||||||
return {
|
return {
|
||||||
error: "INVALID_TOKEN",
|
error: "INVALID_TOKEN",
|
||||||
requested_action: "LOGOUT_USER",
|
requested_action: "LOGOUT_USER",
|
||||||
|
current_spot: "LOGOUT",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,12 +38,14 @@ export default defineEventHandler(async (event) => {
|
|||||||
return {
|
return {
|
||||||
error: "TOKEN_EXPIRED",
|
error: "TOKEN_EXPIRED",
|
||||||
requested_action: "LOGOUT_USER",
|
requested_action: "LOGOUT_USER",
|
||||||
|
current_spot: "LOGOUT",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
userAccount: fetchViaSQL[0].username,
|
userAccount: fetchViaSQL[0].username,
|
||||||
firstName: fetchViaSQL[0].firstName,
|
firstName: fetchViaSQL[0].firstName,
|
||||||
requested_action: "CONTINUE",
|
requested_action: "CONTINUE",
|
||||||
|
current_spot: "KEEP_LOGIN",
|
||||||
email: fetchViaSQL[0].email,
|
email: fetchViaSQL[0].email,
|
||||||
avatarURL: fetchViaSQL[0].avatarurl,
|
avatarURL: fetchViaSQL[0].avatarurl,
|
||||||
firstName: fetchViaSQL[0].firstName,
|
firstName: fetchViaSQL[0].firstName,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user