添加3个普通用户,注释管理员选项,优化登录
This commit is contained in:
@@ -6,5 +6,6 @@ node_modules
|
|||||||
.env
|
.env
|
||||||
|
|
||||||
.idea
|
.idea
|
||||||
|
.history
|
||||||
|
|
||||||
logs/
|
logs/
|
||||||
@@ -35,7 +35,7 @@ const configs: Record<string, ApiConfig> = {
|
|||||||
// postgrest
|
// postgrest
|
||||||
baseUrl: 'http://10.79.97.16:8000',
|
baseUrl: 'http://10.79.97.16:8000',
|
||||||
// minio
|
// minio
|
||||||
documentUrl: 'http://10.76.244.156:9001/docauditai/',
|
documentUrl: 'http://10.76.244.156:9000/docauditai/',
|
||||||
// 文件上传
|
// 文件上传
|
||||||
uploadUrl: 'http://10.79.97.16:8000/admin/documents/upload',
|
uploadUrl: 'http://10.79.97.16:8000/admin/documents/upload',
|
||||||
},
|
},
|
||||||
|
|||||||
+45
-11
@@ -29,8 +29,31 @@ export async function action({ request }: ActionFunctionArgs) {
|
|||||||
return Response.json({ error: "用户名和密码不能为空" });
|
return Response.json({ error: "用户名和密码不能为空" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(userRole === 'common') {
|
||||||
|
// console.log("username-----", username);
|
||||||
|
// console.log("password-----", password);
|
||||||
|
const validUsers = [
|
||||||
|
{ username: 'gdycuser', password: 'gdyc06111' },
|
||||||
|
{ username: 'gdycuser2', password: 'gdyc06112' },
|
||||||
|
{ username: 'gdycuser3', password: 'gdyc06113' }
|
||||||
|
];
|
||||||
|
const validUser = validUsers.find(user => user.username === username && user.password === password);
|
||||||
|
if (!validUser) {
|
||||||
|
return Response.json({ error: "普通用户用户名或密码错误" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log("login success", userRole);
|
||||||
|
|
||||||
|
// 管理员登录
|
||||||
if (userRole === 'developer') {
|
if (userRole === 'developer') {
|
||||||
if (username !== 'admin' || password !== 'admin') {
|
const validAdminUsers = [
|
||||||
|
{ username: 'admin', password: 'admin0611' },
|
||||||
|
// { username: 'admin2', password: 'admin06112' },
|
||||||
|
// { username: 'admin3', password: 'admin06113' }
|
||||||
|
];
|
||||||
|
const validAdminUser = validAdminUsers.find(user => user.username === username && user.password === password);
|
||||||
|
if (!validAdminUser) {
|
||||||
return Response.json({ error: "管理员用户名或密码错误" });
|
return Response.json({ error: "管理员用户名或密码错误" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,6 +96,7 @@ export default function Login() {
|
|||||||
const [username, setUsername] = useState("");
|
const [username, setUsername] = useState("");
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
const [userRole, setUserRole] = useState<UserRole>("common");
|
const [userRole, setUserRole] = useState<UserRole>("common");
|
||||||
|
const [showPassword, setShowPassword] = useState(false);
|
||||||
const actionData = useActionData<typeof action>();
|
const actionData = useActionData<typeof action>();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -111,15 +135,25 @@ export default function Login() {
|
|||||||
|
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<label htmlFor="password">密码</label>
|
<label htmlFor="password">密码</label>
|
||||||
<input
|
<div className="password-input-container">
|
||||||
type="password"
|
<input
|
||||||
id="password"
|
type={showPassword ? "text" : "password"}
|
||||||
name="password"
|
id="password"
|
||||||
value={password}
|
name="password"
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
value={password}
|
||||||
className="form-input"
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
placeholder="请输入密码"
|
className="form-input password-input"
|
||||||
/>
|
placeholder="请输入密码"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="password-toggle-btn"
|
||||||
|
onClick={() => setShowPassword(!showPassword)}
|
||||||
|
aria-label={showPassword ? "隐藏密码" : "显示密码"}
|
||||||
|
>
|
||||||
|
<i className={showPassword ? "ri-eye-off-line" : "ri-eye-line"}></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
@@ -133,7 +167,7 @@ export default function Login() {
|
|||||||
required
|
required
|
||||||
>
|
>
|
||||||
<option value="common">普通用户</option>
|
<option value="common">普通用户</option>
|
||||||
<option value="developer">管理员</option>
|
{/* <option value="developer">管理员</option> */}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -112,6 +112,40 @@
|
|||||||
box-shadow: 0 0 0 2px rgba(44, 173, 125, 0.2);
|
box-shadow: 0 0 0 2px rgba(44, 173, 125, 0.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 密码输入框容器样式 */
|
||||||
|
.password-input-container {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.password-input {
|
||||||
|
padding-right: 3rem; /* 为眼睛图标留出空间 */
|
||||||
|
}
|
||||||
|
|
||||||
|
.password-toggle-btn {
|
||||||
|
position: absolute;
|
||||||
|
right: 0.75rem;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 0.25rem;
|
||||||
|
color: #666;
|
||||||
|
font-size: 1.25rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: color 0.2s, background-color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.password-toggle-btn:hover {
|
||||||
|
color: #2cad7d;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.login-button {
|
.login-button {
|
||||||
margin-top: 1rem;
|
margin-top: 1rem;
|
||||||
padding: 0.75rem 1.5rem;
|
padding: 0.75rem 1.5rem;
|
||||||
|
|||||||
Reference in New Issue
Block a user