Fixed login
This commit is contained in:
parent
439083a55b
commit
a8d1c1fdf9
1 changed files with 57 additions and 4 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import './Login.sass'
|
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 { IoChevronBack } from 'solid-icons/io'
|
||||||
import { createSignal, Show, createEffect } from 'solid-js'
|
import { createSignal, Show, createEffect } from 'solid-js'
|
||||||
import { ofetch } from 'ofetch'
|
import { ofetch } from 'ofetch'
|
||||||
|
|
@ -9,22 +9,31 @@ import { useNavigate } from '@solidjs/router'
|
||||||
export default () => {
|
export default () => {
|
||||||
const API = import.meta.env.VITE_BACKEND
|
const API = import.meta.env.VITE_BACKEND
|
||||||
const APPROVERNAME = import.meta.env.VITE_HEAD
|
const APPROVERNAME = import.meta.env.VITE_HEAD
|
||||||
|
const navigate = useNavigate()
|
||||||
const assessors = JSON.parse(sessionStorage.getItem('registered')!)
|
const assessors = JSON.parse(sessionStorage.getItem('registered')!)
|
||||||
const roles = ['Assessor', 'Approver']
|
const roles = ['Assessor', 'Approver']
|
||||||
|
|
||||||
const [role, setRole] = createSignal('Assessor')
|
const [role, setRole] = createSignal('Assessor')
|
||||||
const [name, setName] = createSignal('')
|
const [name, setName] = createSignal('')
|
||||||
const [password, setPassword] = createSignal('')
|
const [password, setPassword] = createSignal('')
|
||||||
|
const [loggedin, setLoggedin] = createSignal(0)
|
||||||
const navigate = useNavigate()
|
const [errorMessage, setErrorMessage] = createSignal('')
|
||||||
|
|
||||||
const login = async () => {
|
const login = async () => {
|
||||||
const employeeid = await ofetch(API + 'get-employeeid/' + name(), { parseResponse: JSON.parse })
|
const employeeid = await ofetch(API + 'get-employeeid/' + name(), { parseResponse: JSON.parse })
|
||||||
const dbpassword = await ofetch(API + 'get-password/' + employeeid.result, { parseResponse: JSON.parse })
|
const dbpassword = await ofetch(API + 'get-password/' + employeeid.result, { parseResponse: JSON.parse })
|
||||||
const hashPassword = await securePassword()
|
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) {
|
if (dbpassword.result === hashPassword) {
|
||||||
navigate('/notification')
|
setLoggedin(2)
|
||||||
|
} else {
|
||||||
|
setLoggedin(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -36,6 +45,10 @@ export default () => {
|
||||||
return thirdHashing.toString()
|
return thirdHashing.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gotoMain = () => {
|
||||||
|
navigate('/main')
|
||||||
|
}
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (role() === 'Approver') setName(APPROVERNAME)
|
if (role() === 'Approver') setName(APPROVERNAME)
|
||||||
else if (role() !== 'Approver' && name() === APPROVERNAME) setName('')
|
else if (role() !== 'Approver' && name() === APPROVERNAME) setName('')
|
||||||
|
|
@ -112,6 +125,46 @@ export default () => {
|
||||||
</Row>
|
</Row>
|
||||||
</Padding>
|
</Padding>
|
||||||
</Page>
|
</Page>
|
||||||
|
|
||||||
|
<div onClick={gotoMain}>
|
||||||
|
<Modal trigger={loggedin() === 2} background="#18412aff" color="#ffffffe4" opacity={0.6}>
|
||||||
|
<Padding top={1} bottom={1} left={4} right={4}>
|
||||||
|
<Column>
|
||||||
|
<Row>
|
||||||
|
<Box curved thickness={3} color="white" padding={1}>
|
||||||
|
<h2>Login Successful</h2>
|
||||||
|
</Box>
|
||||||
|
</Row>
|
||||||
|
|
||||||
|
<Row>
|
||||||
|
<span class="close-text">Click anywhere to close</span>
|
||||||
|
</Row>
|
||||||
|
</Column>
|
||||||
|
</Padding>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div onClick={() => setLoggedin(0)}>
|
||||||
|
<Modal trigger={loggedin() === 1} background="#562020ff" color="#ffffffe4" opacity={0.6}>
|
||||||
|
<Padding top={1} bottom={1} left={4} right={4}>
|
||||||
|
<Column>
|
||||||
|
<Row>
|
||||||
|
<Box curved thickness={3} color="white" padding={1}>
|
||||||
|
<h2>Login Failed</h2>
|
||||||
|
</Box>
|
||||||
|
</Row>
|
||||||
|
|
||||||
|
<Row>
|
||||||
|
<h3>{errorMessage()}</h3>
|
||||||
|
</Row>
|
||||||
|
|
||||||
|
<Row>
|
||||||
|
<span class="close-text">Click anywhere to close</span>
|
||||||
|
</Row>
|
||||||
|
</Column>
|
||||||
|
</Padding>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue