diff --git a/src/api/login.ts b/src/api/login.ts index 8b41e40..6806d92 100644 --- a/src/api/login.ts +++ b/src/api/login.ts @@ -10,3 +10,11 @@ export function login(email: string, password: string) { export function logout() { return client.post("/api/v1/auth/logout", {}); } + +export function loginLdap(email: string, password: string) { + return client.post("/api/v1/auth/login/ldap", { + username: email, + password: password, + }); +} + diff --git a/src/pages/init/index.tsx b/src/pages/init/index.tsx index 7ea6f5c..e6e54a7 100644 --- a/src/pages/init/index.tsx +++ b/src/pages/init/index.tsx @@ -24,6 +24,7 @@ export const InitPage = (props: Props) => { if (props.configData) { let config: SystemConfigStoreInterface = { //系统配置 + "ldap-enabled": props.configData["ldap-enabled"], systemApiUrl: props.configData["system-api-url"], systemH5Url: props.configData["system-h5-url"], systemLogo: props.configData["system-logo"], diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index 8a13546..b7fbec9 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -1,8 +1,8 @@ import { Input, Button, message } from "antd"; -import React, { useState, useEffect } from "react"; +import React, { useState } from "react"; import styles from "./index.module.scss"; import banner from "../../assets/images/login/banner.png"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { useNavigate } from "react-router-dom"; import { loginAction } from "../../store/user/loginUserSlice"; import { login, user } from "../../api/index"; @@ -15,10 +15,11 @@ const LoginPage: React.FC = () => { const [loading, setLoading] = useState(false); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); + const systemConfig = useSelector((state: any) => state.systemConfig.value); const loginSubmit = (e: any) => { if (!email) { - message.error("请输入学员邮箱账号"); + message.error("请输入邮箱或uid"); return; } if (!password) { @@ -42,16 +43,29 @@ const LoginPage: React.FC = () => { return; } setLoading(true); - login - .login(email, password) - .then((res: any) => { - const token = res.data.token; - setToken(token); - getUser(); - }) - .catch((e) => { - setLoading(false); - }); + if (systemConfig["ldap-enabled"] === "1") { + login + .loginLdap(email, password) + .then((res: any) => { + const token = res.data.token; + setToken(token); + getUser(); + }) + .catch((e) => { + setLoading(false); + }); + } else { + login + .login(email, password) + .then((res: any) => { + const token = res.data.token; + setToken(token); + getUser(); + }) + .catch((e) => { + setLoading(false); + }); + } }; const getUser = () => { @@ -79,7 +93,7 @@ const LoginPage: React.FC = () => { setEmail(e.target.value); }} style={{ width: 400, height: 54 }} - placeholder="请输入学员邮箱账号" + placeholder={"请输入邮箱或uid"} onKeyUp={(e) => keyUp(e)} /> diff --git a/src/store/system/systemConfigSlice.ts b/src/store/system/systemConfigSlice.ts index 0fa2e39..eaae24f 100644 --- a/src/store/system/systemConfigSlice.ts +++ b/src/store/system/systemConfigSlice.ts @@ -1,6 +1,7 @@ import { createSlice } from "@reduxjs/toolkit"; type SystemConfigStoreInterface = { + "ldap-enabled": string; systemApiUrl: string; systemPcUrl: string; systemH5Url: string; @@ -16,6 +17,7 @@ type SystemConfigStoreInterface = { }; let defaultValue: SystemConfigStoreInterface = { + "ldap-enabled": "", systemApiUrl: "", systemPcUrl: "", systemH5Url: "",