From f9cf79c81fe92272b517ae9a6be1adedaa4355e2 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Thu, 01 Sep 2022 02:23:54 +0100 Subject: [PATCH] Hide login form if password-based authentication is disabled --- chartered-frontend/src/pages/Login.tsx | 108 ++++++++++++++++++++++++++++++++++++++++++++------------------------------------ chartered-web/src/endpoints/web_api/auth/openid.rs | 3 +++ 2 files changed, 60 insertions(+), 51 deletions(-) diff --git a/chartered-frontend/src/pages/Login.tsx b/chartered-frontend/src/pages/Login.tsx index b02030a..3c1e2ae 100644 --- a/chartered-frontend/src/pages/Login.tsx +++ a/chartered-frontend/src/pages/Login.tsx @@ -20,6 +20,7 @@ import { PersonPlus } from "react-bootstrap-icons"; interface OAuthProviders { + password: boolean; providers: string[]; } @@ -110,60 +111,62 @@ /> -
-
- setUsername(e.target.value)} - /> + {oauthProviders?.password ?? true ? <> + +
+ setUsername(e.target.value)} + /> - -
- -
- setPassword(e.target.value)} - /> + +
+ +
+ setPassword(e.target.value)} + /> - -
- - - - - - Register - + +
+ + + + + + Register + + : <>} {oauthProviders?.providers.length > 0 ? ( <> -
or
+ {oauthProviders?.password ?
or
: <>} {oauthProviders.providers.map((v, i) => ( ))} @@ -214,6 +218,7 @@ icon, background, onClick, + noPadding, }: { type: "button" | "submit"; variant: string; @@ -223,11 +228,12 @@ icon?: IconDefinition; background?: string; onClick: MouseEventHandler; + noPadding?: boolean; }) { if (showSpinner) { return (
Logging in... @@ -241,7 +247,7 @@ type={type} disabled={disabled} onClick={onClick} - className={`btn btn-lg mt-2 btn-${variant} w-100`} + className={`btn btn-lg ${noPadding ? '' : 'mt-2'} btn-${variant} w-100`} style={{ background, borderColor: background }} > {icon ? : <>} diff --git a/chartered-web/src/endpoints/web_api/auth/openid.rs b/chartered-web/src/endpoints/web_api/auth/openid.rs index 07fdb74..4f87eb3 100644 --- a/chartered-web/src/endpoints/web_api/auth/openid.rs +++ a/chartered-web/src/endpoints/web_api/auth/openid.rs @@ -21,9 +21,11 @@ /// Lists all the available and enabled providers that the user can authenticate with. #[allow(clippy::unused_async)] pub async fn list_providers( + extract::Extension(config): extract::Extension>, extract::Extension(oidc_clients): extract::Extension>, ) -> Json { Json(ListProvidersResponse { + password: config.auth.password.enabled, providers: oidc_clients .keys() .into_iter() @@ -226,6 +228,7 @@ #[derive(Serialize)] pub struct ListProvidersResponse { + password: bool, providers: Vec, } -- rgit 0.1.3