feat: get initial password command
This commit is contained in:
@@ -6,7 +6,7 @@ import qs from 'query-string';
|
||||
|
||||
export const AUTH_API = '/auth';
|
||||
|
||||
export const AUTH_CONFIG_API = '/auth-config';
|
||||
export const AUTH_CONFIG_API = '/auth/config';
|
||||
|
||||
export const AUTH_OIDC_LOGIN_API = '/auth/oidc/login';
|
||||
export const AUTH_SAML_LOGIN_API = '/auth/saml/login';
|
||||
@@ -52,5 +52,10 @@ export const updatePassword = async (params: any) => {
|
||||
};
|
||||
|
||||
export const fetchAuthConfig = async () => {
|
||||
return request(AUTH_CONFIG_API);
|
||||
return request<{
|
||||
is_saml: boolean;
|
||||
is_oidc: boolean;
|
||||
first_time_setup: boolean;
|
||||
get_initial_password_command: string;
|
||||
}>(AUTH_CONFIG_API);
|
||||
};
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
import { useIntl } from '@umijs/max';
|
||||
import { Button, Checkbox, Divider, Form, FormInstance } from 'antd';
|
||||
import { createStyles } from 'antd-style';
|
||||
import { GET_INITIAL_PASSWORD } from '../../login/config';
|
||||
|
||||
const useStyles = createStyles(({ token, css }) => {
|
||||
return {
|
||||
@@ -37,17 +36,26 @@ const useStyles = createStyles(({ token, css }) => {
|
||||
interface LocalUserFormProps {
|
||||
handleLogin: (values: any) => void;
|
||||
form: FormInstance;
|
||||
loginOption: {
|
||||
saml: boolean;
|
||||
oidc: boolean;
|
||||
first_time_setup: boolean;
|
||||
get_initial_password_command: string;
|
||||
};
|
||||
}
|
||||
|
||||
const LocalUserForm: React.FC<LocalUserFormProps> = (props) => {
|
||||
const { handleLogin, form } = props;
|
||||
const { handleLogin, form, loginOption } = props;
|
||||
const intl = useIntl();
|
||||
const { styles } = useStyles();
|
||||
|
||||
const renderCommandInfo = () => {
|
||||
if (!loginOption?.first_time_setup) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<div className={styles.commandInfo}>
|
||||
<Divider />
|
||||
<Divider style={{ marginTop: 16, marginBottom: 12 }} />
|
||||
<div className="content">
|
||||
<InfoCircleOutlined className="icon" />
|
||||
<span className="info">
|
||||
@@ -56,8 +64,8 @@ const LocalUserForm: React.FC<LocalUserFormProps> = (props) => {
|
||||
</div>
|
||||
<HighlightCode
|
||||
theme="dark"
|
||||
code={GET_INITIAL_PASSWORD}
|
||||
copyValue={GET_INITIAL_PASSWORD}
|
||||
code={loginOption.get_initial_password_command}
|
||||
copyValue={loginOption.get_initial_password_command}
|
||||
lang="bash"
|
||||
></HighlightCode>
|
||||
</div>
|
||||
@@ -140,6 +148,7 @@ const LocalUserForm: React.FC<LocalUserFormProps> = (props) => {
|
||||
>
|
||||
{intl.formatMessage({ id: 'common.button.login' })}
|
||||
</Button>
|
||||
{renderCommandInfo()}
|
||||
</Form>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -251,7 +251,11 @@ const LoginForm = () => {
|
||||
{renderWelCome()}
|
||||
{renderLoginButtons()}
|
||||
{(!hasThirdPartyLogin || isPassword) && (
|
||||
<LocalUserForm handleLogin={handleLogin} form={form} />
|
||||
<LocalUserForm
|
||||
handleLogin={handleLogin}
|
||||
form={form}
|
||||
loginOption={SSOAuth.options}
|
||||
/>
|
||||
)}
|
||||
{hasThirdPartyLogin && isPassword && (
|
||||
<BackButton onClick={handleLoginWithThirdParty}>
|
||||
|
||||
@@ -10,6 +10,8 @@ import {
|
||||
type LoginOption = {
|
||||
saml: boolean;
|
||||
oidc: boolean;
|
||||
first_time_setup: boolean;
|
||||
get_initial_password_command: string;
|
||||
};
|
||||
|
||||
export function useSSOAuth({
|
||||
@@ -25,7 +27,9 @@ export function useSSOAuth({
|
||||
}) {
|
||||
const [loginOption, setLoginOption] = useState<LoginOption>({
|
||||
saml: false,
|
||||
oidc: false
|
||||
oidc: false,
|
||||
first_time_setup: false,
|
||||
get_initial_password_command: ''
|
||||
});
|
||||
|
||||
const intl = useIntl();
|
||||
@@ -44,16 +48,17 @@ export function useSSOAuth({
|
||||
|
||||
const init = async () => {
|
||||
try {
|
||||
const authConfig = await fetchAuthConfig();
|
||||
const { is_oidc, is_saml, ...rest } = await fetchAuthConfig();
|
||||
setLoginOption({
|
||||
oidc: !!authConfig.is_oidc,
|
||||
saml: !!authConfig.is_saml
|
||||
...rest,
|
||||
oidc: !!is_oidc,
|
||||
saml: !!is_saml
|
||||
});
|
||||
if (sso) {
|
||||
onLoading?.(true);
|
||||
if (authConfig.is_oidc) {
|
||||
if (is_oidc) {
|
||||
oidcLogin();
|
||||
} else if (authConfig.is_saml) {
|
||||
} else if (is_saml) {
|
||||
samlLogin();
|
||||
} else {
|
||||
onError?.(
|
||||
@@ -62,7 +67,12 @@ export function useSSOAuth({
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
setLoginOption({ oidc: false, saml: false });
|
||||
setLoginOption({
|
||||
oidc: false,
|
||||
saml: false,
|
||||
first_time_setup: false,
|
||||
get_initial_password_command: ''
|
||||
});
|
||||
onLoading?.(false);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user