优化数据隔离,进行权限控制
This commit is contained in:
+19
-4
@@ -28,6 +28,13 @@ export async function action({ request }: ActionFunctionArgs) {
|
||||
if (!username || !password) {
|
||||
return Response.json({ error: "用户名和密码不能为空" });
|
||||
}
|
||||
|
||||
if (userRole === 'developer') {
|
||||
if (username !== 'admin' || password !== 'admin') {
|
||||
// toastService.error("管理员用户名或密码错误");
|
||||
return Response.json({ error: "管理员用户名或密码错误" });
|
||||
}
|
||||
}
|
||||
|
||||
// 在实际应用中,这里应该是对用户名和密码的验证逻辑
|
||||
// 简化起见,我们直接视为登录成功
|
||||
@@ -61,6 +68,13 @@ export default function Login() {
|
||||
const actionData = useActionData<typeof action>();
|
||||
const navigation = useNavigation();
|
||||
|
||||
// 使用 useEffect 确保错误提示只显示一次
|
||||
// useEffect(() => {
|
||||
// if(actionData?.error) {
|
||||
// toastService.error(actionData.error);
|
||||
// }
|
||||
// }, [actionData?.error]);
|
||||
|
||||
// 判断是否正在提交表单
|
||||
const isSubmitting = navigation.state === "submitting";
|
||||
|
||||
@@ -76,7 +90,10 @@ export default function Login() {
|
||||
<h2 className="login-subtitle">用户登录</h2>
|
||||
<Form method="post" className="login-form">
|
||||
{actionData?.error && (
|
||||
<div className="error-message">{actionData.error}</div>
|
||||
<div className="error-message-container">
|
||||
<div className="error-icon"><i className="ri-error-warning-line"></i></div>
|
||||
<div className="error-text">{actionData.error}</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="form-group">
|
||||
@@ -89,7 +106,6 @@ export default function Login() {
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
className="form-input"
|
||||
placeholder="请输入用户名"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -103,7 +119,6 @@ export default function Login() {
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
className="form-input"
|
||||
placeholder="请输入密码"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -118,7 +133,7 @@ export default function Login() {
|
||||
required
|
||||
>
|
||||
<option value="common">普通用户</option>
|
||||
<option value="developer">开发者</option>
|
||||
<option value="developer">管理员</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user