Browse Source

登录修改

master
xingyongchun 2 years ago
parent
commit
c67bbf9531
  1. 43
      web/client/src/sections/auth/actions/auth.js
  2. 4
      web/client/src/sections/auth/containers/login.js

43
web/client/src/sections/auth/actions/auth.js

@ -27,27 +27,34 @@ export function login(username, password) {
payload: { error: "请输入账号名和密码" }, payload: { error: "请输入账号名和密码" },
}); });
return Promise.resolve(); return Promise.resolve();
}else{
if(username=='SuperAdmin'&&password=='123456'){
dispatch({
type: LOGIN_SUCCESS,
payload: { user: {authorized:true} },
});
}else{
message.error('账号或密码错误')
}
} }
const url = ApiTable.login; const url = ApiTable.login;
return Request.post(url, { username, password, p: "456" }).then( // return Request.post(url, { username, password, p: "456" }).then(
(user) => { // (user) => {
sessionStorage.setItem("user", JSON.stringify(user)); // sessionStorage.setItem("user", JSON.stringify(user));
dispatch({
type: LOGIN_SUCCESS, // },
payload: { user: user }, // (error) => {
}); // let { body } = error.response;
}, // dispatch({
(error) => { // type: LOGIN_ERROR,
let { body } = error.response; // payload: {
dispatch({ // error: body && body.message ? body.message : "账号或密码错误",
type: LOGIN_ERROR, // },
payload: { // });
error: body && body.message ? body.message : "账号或密码错误", // }
}, // );
});
}
);
}; };
} }

4
web/client/src/sections/auth/containers/login.js

@ -23,7 +23,7 @@ function Login(props) {
}, [error]); }, [error]);
// 当user发生改变时,直接跳转到后台管理 // 当user发生改变时,直接跳转到后台管理
useEffect(() => { useEffect(() => {
user && user.authorized && JSON.parse(sessionStorage.getItem("user")) user && user.authorized
? dispatch(push("/article")) ? dispatch(push("/article"))
: null; : null;
}, [user]); }, [user]);
@ -31,7 +31,7 @@ function Login(props) {
const enterHandler = (e) => { const enterHandler = (e) => {
if (e.key === "Enter") { if (e.key === "Enter") {
setInputChanged(false); setInputChanged(false);
dispatch(login(username, password)); // dispatch(login(username, password));
} }
}; };
// //

Loading…
Cancel
Save