Skip to content

Commit

Permalink
fix: mini-graphic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
domysh committed Jun 9, 2024
1 parent 5906e79 commit eb2446b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ client/build/
client/dist/**
client/dist/
Pipfile
Pipfile.lock
Pipfile.lock
test/xploit_test/.flag_queue.json
99 changes: 57 additions & 42 deletions frontend/src/components/LoginProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { postFormRequest } from "@/utils/net";
import { statusQuery } from "@/utils/queries";
import { useGlobalStore, useTokenStore } from "@/utils/stores";
import { Box, Button, Group, PasswordInput, Space } from "@mantine/core"
import { Box, Button, Container, Group, PasswordInput, Space } from "@mantine/core"
import { useForm } from '@mantine/form';
import { notifications } from '@mantine/notifications'
import { useEffect } from "react";
Expand All @@ -28,6 +28,19 @@ export const LoginProvider = ({ children }: { children:any }) => {
form.reset()
},[token])

if (status.isError){
return <Box className="center-flex-col" style={{
width: "100%",
height: "100%",
}}>
<Container className="center-flex-col">
<WelcomeTitle description="An error occured while fetching status!" />
Check if the backend is running and reachable.
<Space h="xl" />
<Button onClick={() => status.refetch()} size="xl" color="orange">Retry</Button>
</Container>
</Box>
}

if (status.data?.status == "setup"){
return <SetupScreen />
Expand All @@ -41,51 +54,53 @@ export const LoginProvider = ({ children }: { children:any }) => {
width: "100%",
height: "100%",
}}>
<WelcomeTitle description="A password is required to access to the platform!" />
<Space h="md" />
<form
style={{
width: "80%"
}}
onSubmit={form.onSubmit((values) => {
setLoading(true)
postFormRequest("login", {body: {username: "web-user", ...values}})
.then( (res) => {
if(res.access_token){
setToken(res.access_token)
status.refetch()
}else{
<Container>
<WelcomeTitle description="A password is required to access the platform!" />
<Space h="xl" />
<form
style={{
width: "100%"
}}
onSubmit={form.onSubmit((values) => {
setLoading(true)
postFormRequest("login", {body: {username: "web-user", ...values}})
.then( (res) => {
if(res.access_token){
setToken(res.access_token)
status.refetch()
}else{
notifications.show({
title: "Unexpected Error",
message: res.detail??res??"Unknown error",
color: "red",
autoClose: 5000
})
}
})
.catch( (err) => {
notifications.show({
title: "Unexpected Error",
message: res.detail??res??"Unknown error",
title: "Something went wrong!",
message: err.message??"Unknown error",
color: "red",
autoClose: 5000
})
}
})
.catch( (err) => {
notifications.show({
title: "Something went wrong!",
message: err.message??"Unknown error",
color: "red",
autoClose: 5000
})
})
.finally(()=>{
setLoading(false)
})
})}>
<PasswordInput
withAsterisk
label="Password"
placeholder="Access Password"
required
{...form.getInputProps("password")}
/>
<Space h="md" />
<Group justify="flex-end" mt="md">
<Button type="submit" loading={loadingStatus}>Login</Button>
</Group>
</form>
.finally(()=>{
setLoading(false)
})
})}>
<PasswordInput
withAsterisk
label="Password"
placeholder="Access Password"
required
{...form.getInputProps("password")}
/>
<Space h="md" />
<Group justify="center" mt="md">
<Button type="submit" loading={loadingStatus} size="lg">Login</Button>
</Group>
</form>
</Container>
</Box>
}
2 changes: 1 addition & 1 deletion tests/xploit_test/.flag_queue.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"server_id":"62a1412f-3e92-4c20-8039-47c2eb8d52ec","queue":[]}
{"server_id":"279e503e-dcf4-4103-98da-d2e0619ebcc9","queue":[]}
2 changes: 1 addition & 1 deletion tests/xploit_test/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name = "xploit_test"
interpreter = "python3"
run = "main.py"
language = "python"
service = "2244667d-0645-4930-8e9a-c6c5ea799258"
service = "9454014c-0be6-4f9e-9963-2c3ffb8aba8a"

0 comments on commit eb2446b

Please sign in to comment.