+
-
{intl?.formatMessage({ id: 'users.login.title' })}
+
+ {intl?.formatMessage({ id: 'users.login.title' })}
+

{
);
- }, [intl]);
+ };
const gotoDefaultPage = async (userInfo: any) => {
checkDefaultPage(userInfo, true);
@@ -162,34 +176,56 @@ const LoginForm = () => {
onError: handleOnError
});
+ const handleLoginWithPassword = () => {
+ setIsPassword(true);
+ };
+
+ const handleLoginWithThirdParty = () => {
+ if (SSOAuth.options.oidc) {
+ SSOAuth.loginWithOIDC();
+ } else if (SSOAuth.options.saml) {
+ SSOAuth.loginWithSAML();
+ }
+ };
+
const hasThirdPartyLogin = useMemo(() => {
return SSOAuth.options.oidc || SSOAuth.options.saml;
}, [SSOAuth.options]);
- const renderThirdPartyLoginButtons = () => {
- if (!hasThirdPartyLogin) return null;
+ const renderLoginButtons = () => {
+ // do not render login buttons if using password login or no third-party login
+ if (!hasThirdPartyLogin || isPassword) return null;
+
return (
- <>
-
- {intl.formatMessage({ id: 'common.login.thirdparty' })}
-
-
- {SSOAuth.options.oidc && (
-
-
-
-
-
- )}
- {SSOAuth.options.saml && (
-
-
-
-
-
- )}
-
- >
+
+ {SSOAuth.options.oidc && (
+
+
+
+ {intl.formatMessage(
+ { id: 'common.external.login' },
+ { type: 'OIDC' }
+ )}
+
+
+ )}
+ {SSOAuth.options.saml && (
+
+
+
+ {intl.formatMessage(
+ { id: 'common.external.login' },
+ { type: 'SAML' }
+ )}
+
+
+ )}
+
+
);
};
@@ -212,84 +248,21 @@ const LoginForm = () => {
) : (
-
- }
- />
-
-
-
- }
- label={intl.formatMessage({ id: 'common.form.password' })}
- />
-
-
-
-
-
- {intl.formatMessage({ id: 'common.login.rember' })}
-
-
-
-
-
-
- {renderThirdPartyLoginButtons()}
-
+ <>
+ {renderWelCome()}
+ {renderLoginButtons()}
+ {(!hasThirdPartyLogin || isPassword) && (
+
+ )}
+ {hasThirdPartyLogin && isPassword && (
+
+ {intl.formatMessage(
+ { id: 'common.external.login' },
+ { type: SSOAuth.options.oidc ? 'OIDC' : 'SAML' }
+ )}
+
+ )}
+ >
)}
diff --git a/src/pages/login/hooks/use-local-auth.ts b/src/pages/login/hooks/use-local-auth.ts
index f6171308..acc90cd6 100644
--- a/src/pages/login/hooks/use-local-auth.ts
+++ b/src/pages/login/hooks/use-local-auth.ts
@@ -83,7 +83,7 @@ export const useLocalAuth = ({
}
onSuccess?.(userInfo);
- } catch (error) {
+ } catch (error: any) {
onError?.(error);
}
};
diff --git a/src/pages/login/hooks/use-sso-auth.ts b/src/pages/login/hooks/use-sso-auth.ts
index 1e32a7f9..14bc7b2e 100644
--- a/src/pages/login/hooks/use-sso-auth.ts
+++ b/src/pages/login/hooks/use-sso-auth.ts
@@ -45,27 +45,27 @@ export function useSSOAuth({
window.location.href = '/auth/saml/login';
};
- useEffect(() => {
- fetchAuthConfig('/auth_config')
- .then((authConfig) => {
- setLoginOption({
- oidc: !!authConfig.is_oidc,
- saml: !!authConfig.is_saml
- });
- })
- .catch(() => {
- setLoginOption({ oidc: false, saml: false });
+ const init = async () => {
+ try {
+ const authConfig = await fetchAuthConfig('/auth_config');
+ setLoginOption({
+ oidc: !!authConfig.is_oidc,
+ saml: !!authConfig.is_saml
});
-
- if (sso) {
- fetchUserInfo()
- .then((userInfo) => {
- onSuccess?.(userInfo);
- })
- .catch((error) => {
- onError?.(error);
- });
+ if (sso) {
+ if (authConfig.is_oidc) {
+ oidcLogin();
+ } else if (authConfig.is_saml) {
+ samlLogin();
+ }
+ }
+ } catch {
+ setLoginOption({ oidc: false, saml: false });
}
+ };
+
+ useEffect(() => {
+ init();
}, []);
return {
diff --git a/src/pages/profile/index.tsx b/src/pages/profile/index.tsx
index 5059818b..459534be 100644
--- a/src/pages/profile/index.tsx
+++ b/src/pages/profile/index.tsx
@@ -1,8 +1,10 @@
+import { userAtom } from '@/atoms/user';
import useTabActive from '@/hooks/use-tab-active';
import { PageContainer } from '@ant-design/pro-components';
import { useIntl } from '@umijs/max';
import { TabsProps } from 'antd';
-import React, { useCallback, useState } from 'react';
+import { useAtom } from 'jotai';
+import React, { useCallback, useMemo, useState } from 'react';
import styled from 'styled-components';
import Appearance from './components/appearance';
import ModifyPasswordn from './components/modify-password';
@@ -15,23 +17,35 @@ const Wrapper = styled.div`
const Profile: React.FC = () => {
const intl = useIntl();
+ const [userInfo, setUserInfo] = useAtom(userAtom);
const { setTabActive, getTabActive, tabsMap } = useTabActive();
const [activeKey, setActiveKey] = useState(
- getTabActive(tabsMap.userSettings) || 'modify-password'
+ userInfo?.source === 'Local' ? 'modify-password' : 'appearance'
);
- const items: TabsProps['items'] = [
- {
- key: 'modify-password',
- label: intl.formatMessage({ id: 'users.form.updatepassword' }),
- children: