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