Skip to content

Commit

Permalink
#327 show login messages from server, remove old logo from login
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Jan 9, 2024
1 parent 24d4804 commit ba15c97
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
15 changes: 13 additions & 2 deletions frontend-v2/src/features/login/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,20 @@ const Login: React.FC<LoginProps> = ({ onLogin, isLoading, errorMessage }) => {
<form onSubmit={handleSubmit(onSubmit)}>
<Stack spacing={2} sx={{ marginTop: 10 }}>
<Box display="flex" justifyContent="center" alignItems="center">
<PkpdAppIcon style={{ width: 250 }} />
<Typography
variant="h3"
component="div"
sx={{
color: "#1976d2",
fontWeight: "bold",
paddingLeft: "1rem",
fontFamily: "Comfortaa",
}}
>
pkpd explorer
</Typography>
</Box>
<Typography variant="h5">Login</Typography>
<Typography variant="h6">Login</Typography>
<TextField
label="Username"
name="username"
Expand Down
20 changes: 18 additions & 2 deletions frontend-v2/src/features/login/loginSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,27 @@ export const fetchSession = createAsyncThunk<
return sessionResponse;
});

class ServerError extends Error {
constructor(message: string) {
super(message)
this.name = "ServerError";
}
}
function isResponseOk(response: Response) {
if (response.status >= 200 && response.status <= 299) {
return response.json();
} else {
throw Error(response.statusText);
return response.json()
.then((data) => {
throw new ServerError(data.detail);
})
.catch((err) => {
if (err instanceof ServerError) {
throw err;
} else {
throw Error(response.statusText);
}
});
}
}

Expand Down Expand Up @@ -80,7 +96,7 @@ export const login = createAsyncThunk<
return { isAuthenticated: true, user: data.user };
})
.catch((err) => {
return rejectWithValue({ error: err.message });
return rejectWithValue({ error: err.message});
});
return response;
},
Expand Down
2 changes: 1 addition & 1 deletion pkpdapp/pkpdapp/api/views/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def login_view(request):

user = authenticate(username=username, password=password)
if user is None:
return JsonResponse({'detail': 'Invalid credentials.'}, status=400)
return JsonResponse({'detail': 'Invalid credentials. Either you have supplied an incorrect username/password combination, or you do not have sufficient access'}, status=400)

login(request, user)

Expand Down

0 comments on commit ba15c97

Please sign in to comment.