mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 13:04:23 +00:00
Got the basic login system working :D
This commit is contained in:
parent
eaa925e5dd
commit
eb6c131163
2 changed files with 30 additions and 18 deletions
|
@ -2,9 +2,15 @@
|
||||||
// Great, there are now no errors ig
|
// Great, there are now no errors ig
|
||||||
const emit = defineEmits(["windowopener", "error", "loadValue"]);
|
const emit = defineEmits(["windowopener", "error", "loadValue"]);
|
||||||
import sha512 from "crypto-js/sha512";
|
import sha512 from "crypto-js/sha512";
|
||||||
|
import Input from "~/components/ui/input/Input.vue";
|
||||||
const userAccount = ref("");
|
const userAccount = ref("");
|
||||||
const userPassword = ref("");
|
const userPassword = ref("");
|
||||||
|
const error = ref(false);
|
||||||
|
const errormsg = ref("");
|
||||||
|
const success = ref(false);
|
||||||
const submitUserPassword = async () => {
|
const submitUserPassword = async () => {
|
||||||
|
error.value = false;
|
||||||
|
errormsg.value = "";
|
||||||
// Encrypt password during transit
|
// Encrypt password during transit
|
||||||
const password = sha512(userPassword.value).toString();
|
const password = sha512(userPassword.value).toString();
|
||||||
|
|
||||||
|
@ -21,46 +27,52 @@ const submitUserPassword = async () => {
|
||||||
});
|
});
|
||||||
const res = await sendData.json();
|
const res = await sendData.json();
|
||||||
|
|
||||||
if (res.status === "ok") {
|
if (!res.error) {
|
||||||
// Store the token in local storage
|
error.value = false;
|
||||||
localStorage.setItem("token", res.token);
|
localStorage.setItem("token", res.token);
|
||||||
// Redirect to the home page
|
|
||||||
window.location.href = "/";
|
|
||||||
success.value = true;
|
success.value = true;
|
||||||
|
console.log(res);
|
||||||
|
userAccount.value = "";
|
||||||
} else {
|
} else {
|
||||||
alert("Login failed");
|
error.value = true;
|
||||||
error.value = true;
|
errormsg.value = res.error
|
||||||
}
|
}
|
||||||
// Clear the input fields
|
|
||||||
userAccount.value = "";
|
|
||||||
userPassword.value = "";
|
userPassword.value = "";
|
||||||
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col items-center justify-center h-full">
|
<div class="">
|
||||||
<form
|
<form
|
||||||
class="flex flex-col items-center justify-center h-full"
|
class="flex flex-col items-center justify-center h-full"
|
||||||
@submit.prevent="submitUserPassword"
|
@submit.prevent="submitUserPassword"
|
||||||
v-if="!success"
|
v-if="!success"
|
||||||
>
|
>
|
||||||
<div class="text-xl mb-4 text-bold">Login / Register</div>
|
<span class="text-2xl text-bold mb-0">Login / Register</span>
|
||||||
|
<span class="mb-4 text-sm mt-0">We will create a account for you if you don't have one.</span>
|
||||||
<input
|
<div class="">
|
||||||
|
<Input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Username"
|
placeholder="Username"
|
||||||
class="mb-2 p-2 border rounded"
|
class="mb-2 p-2 border rounded"
|
||||||
v-model="userAccount"
|
v-model="userAccount"
|
||||||
|
required
|
||||||
/>
|
/>
|
||||||
<input
|
<Input
|
||||||
type="password"
|
type="password"
|
||||||
placeholder="Password"
|
placeholder="Password"
|
||||||
class="p-2 border rounded mb-2"
|
class="p-2 border rounded mb-2"
|
||||||
v-model="userPassword"
|
v-model="userPassword"
|
||||||
|
required
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
<span v-if="error" class="text-red-600 text-xs m-2">Error: {{ errormsg }}</span>
|
||||||
<button class="bg-black text-white p-2 rounded transition duration-200">
|
<button class="bg-black text-white p-2 rounded transition duration-200">
|
||||||
Log In
|
Log In
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
<div v-else></div>
|
<div v-else>
|
||||||
|
Hi! ${user}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
|
@ -32,7 +32,7 @@ import { TextPlugin } from "gsap/TextPlugin";
|
||||||
gsap.registerPlugin(TextPlugin);
|
gsap.registerPlugin(TextPlugin);
|
||||||
|
|
||||||
// Import Windows
|
// Import Windows
|
||||||
import LoginWindow from "~/components/app/windows/login.vue";
|
import UserWindow from "~/components/app/windows/user.vue";
|
||||||
import HotNewsWindow from "~/components/app/windows/hotnews.vue";
|
import HotNewsWindow from "~/components/app/windows/hotnews.vue";
|
||||||
import SourcesWindow from "~/components/app/windows/sources.vue";
|
import SourcesWindow from "~/components/app/windows/sources.vue";
|
||||||
import AboutWindow from "~/components/app/windows/about.vue";
|
import AboutWindow from "~/components/app/windows/about.vue";
|
||||||
|
@ -92,7 +92,7 @@ const menuItems = [
|
||||||
{ name: t("app.about"), windowName: "about" },
|
{ name: t("app.about"), windowName: "about" },
|
||||||
{ name: t("app.terminal"), windowName: "tty" },
|
{ name: t("app.terminal"), windowName: "tty" },
|
||||||
{ name: t("app.settings"), windowName: "settings" },
|
{ name: t("app.settings"), windowName: "settings" },
|
||||||
{ name: t("app.login"), windowName: "login" },
|
{ name: t("app.login"), windowName: "user" },
|
||||||
{ name: t("app.leave"), windowName: "leave" },
|
{ name: t("app.leave"), windowName: "leave" },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -106,10 +106,10 @@ const associAppWindow = [
|
||||||
height: "500px",
|
height: "500px",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "login",
|
name: "user",
|
||||||
id: "2",
|
id: "2",
|
||||||
title: t("app.login"),
|
title: t("app.login"),
|
||||||
component: LoginWindow,
|
component: UserWindow,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "sources",
|
name: "sources",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue