mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 21:14:23 +00:00
Make it NOT laggy and done some basic login stuff.
This commit is contained in:
parent
fd2ba525f9
commit
b8e5981947
5 changed files with 132 additions and 126 deletions
|
@ -1,50 +1,64 @@
|
|||
<script setup lamng="ts">
|
||||
import sha512 from "crypto-js/sha512";
|
||||
const userAccount = ref("");
|
||||
const userPassword = ref("");
|
||||
const crypto = Crypto;
|
||||
const submitUserPassword = async () => {
|
||||
// Encrypt password during transit
|
||||
const sha512Passwordify = crypto.createHash("sha512");
|
||||
sha512Passwordify.update(userPassword.value);
|
||||
const sha512Password = sha512Passwordify.digest("hex");
|
||||
|
||||
// Log user & password
|
||||
console.log(userAccount.value);
|
||||
console.log(sha512Password);
|
||||
const password = sha512(userPassword.value).toString();
|
||||
|
||||
// Send data.
|
||||
const sendData = fetch("/api/user/login", {
|
||||
const sendData = await fetch("/api/user/login", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username: userAccount.value,
|
||||
password: sha512Password,
|
||||
pcssword: password,
|
||||
}),
|
||||
})
|
||||
const res = await sendData.json();
|
||||
|
||||
if (res.status === "ok") {
|
||||
// Store the token in local storage
|
||||
localStorage.setItem("token", res.token);
|
||||
// Redirect to the home page
|
||||
window.location.href = "/";
|
||||
success.value = true;
|
||||
} else {
|
||||
alert("Login failed");
|
||||
error.value = true;
|
||||
}
|
||||
// Clear the input fields
|
||||
userAccount.value = "";
|
||||
userPassword.value = "";
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex flex-col items-center justify-center h-full">
|
||||
<div
|
||||
<form
|
||||
class="flex flex-col items-center justify-center h-full"
|
||||
@submit.prevent="submitUserPassword"
|
||||
v-if="!success"
|
||||
>
|
||||
<div class="text-xl mb-4 text-bold">Login / Register</div>
|
||||
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Username"
|
||||
placeholder="Your Email"
|
||||
class="mb-2 p-2 border rounded"
|
||||
v-model="userAccount"
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
class="p-2 border rounded mb-2"
|
||||
v-model="userPassword"
|
||||
/>
|
||||
<button class="bg-black text-white p-2 rounded transition duration-200" @click="submitUserPassword">
|
||||
<button class="bg-black text-white p-2 rounded transition duration-200">
|
||||
Log In
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<div v-else></div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue