From 68ecd706c46e9e50b5d62f1c05b1e67971f17eca Mon Sep 17 00:00:00 2001 From: yumusb <43062104+yumusb@users.noreply.github.com> Date: Fri, 26 Dec 2025 19:34:47 +0800 Subject: [PATCH] feat: Add `passwordEnabled` configuration to conditionally display the username/password login form. --- internal/service/account_service.go | 10 ++- web/src/api/auth.ts | 1 + web/src/pages/Login/index.tsx | 111 ++++++++++++++-------------- 3 files changed, 64 insertions(+), 58 deletions(-) diff --git a/internal/service/account_service.go b/internal/service/account_service.go index 5c32e1f..0500ffc 100644 --- a/internal/service/account_service.go +++ b/internal/service/account_service.go @@ -167,15 +167,17 @@ func (s *AccountService) ValidateToken(tokenString string) (*JWTClaims, error) { // AuthConfig 认证配置 type AuthConfig struct { - OIDCEnabled bool `json:"oidcEnabled"` - GitHubEnabled bool `json:"githubEnabled"` + OIDCEnabled bool `json:"oidcEnabled"` + GitHubEnabled bool `json:"githubEnabled"` + PasswordEnabled bool `json:"passwordEnabled"` } // GetAuthConfig 获取认证配置 func (s *AccountService) GetAuthConfig() *AuthConfig { return &AuthConfig{ - OIDCEnabled: s.oidcService.IsEnabled(), - GitHubEnabled: s.githubService.IsEnabled(), + OIDCEnabled: s.oidcService.IsEnabled(), + GitHubEnabled: s.githubService.IsEnabled(), + PasswordEnabled: s.userService.IsEnabled(), } } diff --git a/web/src/api/auth.ts b/web/src/api/auth.ts index 8d13392..f355905 100644 --- a/web/src/api/auth.ts +++ b/web/src/api/auth.ts @@ -5,6 +5,7 @@ import type { LoginRequest, LoginResponse } from '../types'; export interface AuthConfig { oidcEnabled: boolean; githubEnabled: boolean; + passwordEnabled: boolean; } // OIDC 认证 URL diff --git a/web/src/pages/Login/index.tsx b/web/src/pages/Login/index.tsx index a215646..a73bf1d 100644 --- a/web/src/pages/Login/index.tsx +++ b/web/src/pages/Login/index.tsx @@ -1,18 +1,19 @@ -import {useEffect, useState} from 'react'; -import {useNavigate} from 'react-router-dom'; -import {App, Button, Form, Input} from 'antd'; -import {GithubOutlined, GlobalOutlined, LockOutlined, UserOutlined} from '@ant-design/icons'; -import {getAuthConfig, getGitHubAuthURL, getOIDCAuthURL, login} from '@/api/auth.ts'; -import type {LoginRequest} from '@/types'; +import { useEffect, useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import { App, Button, Form, Input } from 'antd'; +import { GithubOutlined, GlobalOutlined, LockOutlined, UserOutlined } from '@ant-design/icons'; +import { getAuthConfig, getGitHubAuthURL, getOIDCAuthURL, login } from '@/api/auth.ts'; +import type { LoginRequest } from '@/types'; const Login = () => { const [loading, setLoading] = useState(false); const [oidcEnabled, setOidcEnabled] = useState(false); const [githubEnabled, setGithubEnabled] = useState(false); + const [passwordEnabled, setPasswordEnabled] = useState(true); const [oidcLoading, setOidcLoading] = useState(false); const [githubLoading, setGithubLoading] = useState(false); const navigate = useNavigate(); - const {message: messageApi} = App.useApp(); + const { message: messageApi } = App.useApp(); useEffect(() => { fetchAuthConfig(); @@ -23,6 +24,7 @@ const Login = () => { const response = await getAuthConfig(); setOidcEnabled(response.data.oidcEnabled); setGithubEnabled(response.data.githubEnabled); + setPasswordEnabled(response.data.passwordEnabled); } catch (error) { console.error('获取认证配置失败:', error); } @@ -32,7 +34,7 @@ const Login = () => { setLoading(true); try { const response = await login(values); - const {token, user} = response.data; + const { token, user } = response.data; localStorage.setItem('token', token); localStorage.setItem('userInfo', JSON.stringify(user)); messageApi.success('欢迎回来'); @@ -83,60 +85,61 @@ const Login = () => {

-
- - } - placeholder="用户名" - className="rounded-xl px-4 py-2.5 bg-slate-50 border-slate-200 hover:bg-white focus:bg-white transition-all" - /> - - - - } - placeholder="密码" - className="rounded-xl px-4 py-2.5 bg-slate-50 border-slate-200 hover:bg-white focus:bg-white transition-all" - /> - - - - - -
+ } + placeholder="用户名" + className="rounded-xl px-4 py-2.5 bg-slate-50 border-slate-200 hover:bg-white focus:bg-white transition-all" + /> + + + + } + placeholder="密码" + className="rounded-xl px-4 py-2.5 bg-slate-50 border-slate-200 hover:bg-white focus:bg-white transition-all" + /> + + + + + + + )} {/* 5. 第三方登录区域 */} {(oidcEnabled || githubEnabled) && (
- +
- 或者 + {passwordEnabled ? '或者' : '使用第三方登录'}
@@ -146,7 +149,7 @@ const Login = () => {