Merge pull request !3 from 白书科技/fix/0904
This commit is contained in:
白书科技 2023-09-04 09:10:51 +00:00 committed by Gitee
commit 0029e81356
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 39 additions and 14 deletions

View File

@ -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,
});
}

View File

@ -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"],

View File

@ -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<boolean>(false);
const [email, setEmail] = useState<string>("");
const [password, setPassword] = useState<string>("");
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)}
/>
</div>

View File

@ -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: "",