From a8d1c1fdf94683309a952fea0dd41685ff83c89f Mon Sep 17 00:00:00 2001 From: Patrick Alvin Alcala Date: Tue, 30 Sep 2025 09:38:30 +0800 Subject: [PATCH] Fixed login --- src/pages/LoginPage/Login.tsx | 61 ++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/src/pages/LoginPage/Login.tsx b/src/pages/LoginPage/Login.tsx index 2598a44..7f19f1f 100644 --- a/src/pages/LoginPage/Login.tsx +++ b/src/pages/LoginPage/Login.tsx @@ -1,5 +1,5 @@ import './Login.sass' -import { Logo, Link, Page, Row, Padding, Box, Radio, Combobox, Input, Button } from '../../components' +import { Logo, Link, Page, Row, Padding, Box, Radio, Combobox, Input, Button, Modal, Column } from '../../components' import { IoChevronBack } from 'solid-icons/io' import { createSignal, Show, createEffect } from 'solid-js' import { ofetch } from 'ofetch' @@ -9,22 +9,31 @@ import { useNavigate } from '@solidjs/router' export default () => { const API = import.meta.env.VITE_BACKEND const APPROVERNAME = import.meta.env.VITE_HEAD + const navigate = useNavigate() const assessors = JSON.parse(sessionStorage.getItem('registered')!) const roles = ['Assessor', 'Approver'] const [role, setRole] = createSignal('Assessor') const [name, setName] = createSignal('') const [password, setPassword] = createSignal('') - - const navigate = useNavigate() + const [loggedin, setLoggedin] = createSignal(0) + const [errorMessage, setErrorMessage] = createSignal('') const login = async () => { const employeeid = await ofetch(API + 'get-employeeid/' + name(), { parseResponse: JSON.parse }) const dbpassword = await ofetch(API + 'get-password/' + employeeid.result, { parseResponse: JSON.parse }) const hashPassword = await securePassword() + if (dbpassword.result === '0') { + setErrorMessage('Not yet registered. Please proceed to Registration.') + } else { + setErrorMessage('Invalid Password, Try again.') + } + if (dbpassword.result === hashPassword) { - navigate('/notification') + setLoggedin(2) + } else { + setLoggedin(1) } } @@ -36,6 +45,10 @@ export default () => { return thirdHashing.toString() } + const gotoMain = () => { + navigate('/main') + } + createEffect(() => { if (role() === 'Approver') setName(APPROVERNAME) else if (role() !== 'Approver' && name() === APPROVERNAME) setName('') @@ -112,6 +125,46 @@ export default () => { + +
+ + + + + +

Login Successful

+
+
+ + + Click anywhere to close + +
+
+
+
+ +
setLoggedin(0)}> + + + + + +

Login Failed

+
+
+ + +

{errorMessage()}

+
+ + + Click anywhere to close + +
+
+
+
) }