Skip to content

Commit

Permalink
feat:ldap登录
Browse files Browse the repository at this point in the history
  • Loading branch information
QwQ-wuwuwu committed Jul 10, 2024
1 parent fc1ae56 commit f08c88a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
13 changes: 12 additions & 1 deletion src/frontend/src/controllers/API/pro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,16 @@ export function getUserGroupsProApi() {
// GET sso URL
export function getSSOurlApi() {
// return Promise.resolve(url)
return axios.get(`/api/oauth2/list`).then(res => res.wx);
return axios.get(`/api/oauth2/list`)
}

export async function getKeyApi() {
return await axios.get('/api/getkey')
}

export async function ldapLoginApi(username:string, password:string) {
return await axios.post('/api/oauth2/ldap', {
username,
password
})
}
13 changes: 11 additions & 2 deletions src/frontend/src/pages/LoginPage/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import { useNavigate } from 'react-router-dom';
import { getCaptchaApi, loginApi, registerApi } from "../../controllers/API/user";
import { captureAndAlertRequestErrorHoc } from "../../controllers/request";
import LoginBridge from './loginBridge';
import { PWD_RULE, handleEncrypt } from './utils';
import { PWD_RULE, handleEncrypt, handleLdapEncrypt } from './utils';
import { locationContext } from '@/contexts/locationContext';
import { ldapLoginApi } from '@/controllers/API/pro';

export const LoginPage = () => {
// const { setErrorData, setSuccessData } = useContext(alertContext);
const { t, i18n } = useTranslation();
Expand Down Expand Up @@ -41,6 +43,7 @@ export const LoginPage = () => {
getCaptchaApi().then(setCaptchaData)
};

const ldapRef = useRef(false)
const handleLogin = async () => {
const error = []
const [mail, pwd] = [mailRef.current.value, pwdRef.current.value]
Expand All @@ -58,6 +61,12 @@ export const LoginPage = () => {
// });

const encryptPwd = await handleEncrypt(pwd)
if(ldapRef.current) {
const encryptLdapPwd = await handleLdapEncrypt(pwd)
captureAndAlertRequestErrorHoc(ldapLoginApi(mail, encryptLdapPwd).then(res => console.log(res)))
fetchCaptchaData()
return
}
captureAndAlertRequestErrorHoc(loginApi(mail, encryptPwd, captchaData.captcha_key, captchaRef.current?.value).then((res: any) => {
// setUser(res.data)
localStorage.setItem('ws_token', res.access_token)
Expand Down Expand Up @@ -196,7 +205,7 @@ export const LoginPage = () => {
disabled={isLoading} onClick={handleRegister} >{t('login.registerButton')}</Button>
</>
}
{appConfig.hasSSO && <LoginBridge />}
{appConfig.hasSSO && <LoginBridge onHasLdap={(bool) => ldapRef.current = bool} />}
</div>
<div className=" absolute right-[16px] bottom-[16px] flex">
<span className="mr-4 text-sm text-gray-400 relative top-2">v{json.version}</span>
Expand Down
7 changes: 5 additions & 2 deletions src/frontend/src/pages/LoginPage/loginBridge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import { useEffect, useRef } from "react";
import { ReactComponent as Wxpro } from "./icons/wxpro.svg";
import { useTranslation } from "react-i18next";

export default function LoginBridge() {
export default function LoginBridge({onHasLdap}) {

const { t } = useTranslation()

const urlRef = useRef<string>('')
useEffect(() => {
getSSOurlApi().then(url => urlRef.current = url)
getSSOurlApi().then((urls:any) => {
urlRef.current = urls.wx
urls.ldap && onHasLdap(true)
})
}, [])

const clickQwLogin = () => {
Expand Down
8 changes: 8 additions & 0 deletions src/frontend/src/pages/LoginPage/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getPublicKeyApi } from "@/controllers/API/user";
import { getKeyApi } from "@/controllers/API/pro";
import { JSEncrypt } from 'jsencrypt';

export const handleEncrypt = async (pwd: string): Promise<string> => {
Expand All @@ -8,4 +9,11 @@ export const handleEncrypt = async (pwd: string): Promise<string> => {
return encrypt.encrypt(pwd) as string;
};

export const handleLdapEncrypt = async (pwd: string): Promise<string> => {
const public_key:any = await getKeyApi();
const encrypt = new JSEncrypt();
encrypt.setPublicKey(public_key);
return encrypt.encrypt(pwd) as string;
};

export const PWD_RULE = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).{8,}$/
14 changes: 5 additions & 9 deletions src/frontend/src/pages/SkillPage/l2Edit.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import FlowSetting from "@/components/Pro/security/FlowSetting";
import { useToast } from "@/components/bs-ui/toast/use-toast";
import { locationContext } from "@/contexts/locationContext";
import { ArrowLeft, ChevronUp } from "lucide-react";
import { useContext, useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate, useParams } from "react-router-dom";
import L2ParameterComponent from "../../CustomNodes/GenericNode/components/parameterComponent/l2Index";
import ShadTooltip from "../../components/ShadTooltipComponent";
import { Button } from "../../components/bs-ui/button";
import { Input } from "../../components/bs-ui/input";
import { Input, Textarea } from "../../components/bs-ui/input";
import { Label } from "../../components/bs-ui/label";
import { Textarea } from "../../components/bs-ui/input";
import { alertContext } from "../../contexts/alertContext";
import { TabsContext } from "../../contexts/tabsContext";
import { userContext } from "../../contexts/userContext";
import { createCustomFlowApi, getFlowApi } from "../../controllers/API/flow";
import { captureAndAlertRequestErrorHoc } from "../../controllers/request";
import { useHasForm } from "../../util/hook";
import FormSet from "./components/FormSet";
import { captureAndAlertRequestErrorHoc } from "../../controllers/request";
import { useToast } from "@/components/bs-ui/toast/use-toast";
import { SettingIcon } from "@/components/bs-icons/setting";
import { Switch } from "@/components/bs-ui/switch";
import FlowSetting from "@/components/Pro/security/FlowSetting";
import { locationContext } from "@/contexts/locationContext";

export default function l2Edit() {
const { t } = useTranslation()
Expand Down

0 comments on commit f08c88a

Please sign in to comment.