添加测试的行政处罚卷宗,添加登录的地区的字段(根据端口号)
This commit is contained in:
@@ -47,6 +47,7 @@ export interface UserInfo {
|
||||
ou_name?: string; // 所属部门名称
|
||||
status?: number; // 账户状态: 0=正常, 1=禁用
|
||||
is_leader?: boolean; // 是否为部门负责人
|
||||
area?: string; // 用户所属地区
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,6 +64,7 @@ export interface SsoUser {
|
||||
ou_name: string;
|
||||
status: number;
|
||||
is_leader: boolean;
|
||||
area?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
deleted_at?: string;
|
||||
@@ -517,16 +519,18 @@ async function callIDaaSLogout(accessToken: string, appId: string): Promise<void
|
||||
|
||||
/**
|
||||
* 保存用户信息到数据库
|
||||
*
|
||||
*
|
||||
* 此函数实现以下逻辑:
|
||||
* 1. 根据 userInfo.sub 查询 sso_users 表中是否已存在该用户
|
||||
* 2. 如果存在,则更新用户信息
|
||||
* 2. 如果存在,则更新用户信息(如果用户已有 area 值则不更新)
|
||||
* 3. 如果不存在,则插入新的用户记录
|
||||
*
|
||||
*
|
||||
* @param userInfo - 从 IDaaS 获取的用户信息
|
||||
* @param token - JWT令牌
|
||||
* @param area - 用户所属地区,根据端口号确定
|
||||
* @returns Promise<{success: boolean, data?: SsoUser, error?: string}>
|
||||
*/
|
||||
export async function saveUserInfo(userInfo: UserInfo, token?: string): Promise<{success: boolean, data?: SsoUser, error?: string}> {
|
||||
export async function saveUserInfo(userInfo: UserInfo, token?: string, area?: string): Promise<{success: boolean, data?: SsoUser, error?: string}> {
|
||||
try {
|
||||
console.log("开始保存用户信息", userInfo);
|
||||
|
||||
@@ -569,7 +573,15 @@ export async function saveUserInfo(userInfo: UserInfo, token?: string): Promise<
|
||||
if (existingUser) {
|
||||
// 2. 用户已存在,执行更新操作
|
||||
console.log("用户已存在,执行更新操作", existingUser.id);
|
||||
|
||||
|
||||
// 只有在现有用户没有 area 或 area 为空时,才更新 area
|
||||
if (area && !existingUser.area) {
|
||||
userData.area = area;
|
||||
console.log("用户原本无地区信息,更新地区为:", area);
|
||||
} else if (existingUser.area) {
|
||||
console.log("用户已有地区信息:", existingUser.area, "不更新");
|
||||
}
|
||||
|
||||
const updateResult = await postgrestPut<SsoUser[], Partial<SsoUser>>(
|
||||
"sso_users",
|
||||
userData,
|
||||
@@ -583,14 +595,20 @@ export async function saveUserInfo(userInfo: UserInfo, token?: string): Promise<
|
||||
}
|
||||
|
||||
console.log("用户信息更新成功");
|
||||
return {
|
||||
success: true,
|
||||
return {
|
||||
success: true,
|
||||
data: Array.isArray(updateResult.data) ? updateResult.data[0] : updateResult.data as unknown as SsoUser
|
||||
};
|
||||
} else {
|
||||
// 3. 用户不存在,执行插入操作 同时需要给这个用户默认添加一个角色,角色为common
|
||||
// 3. 用户不存在,执行插入操作,设置地区信息
|
||||
console.log("用户不存在,执行插入操作");
|
||||
|
||||
|
||||
// 新用户直接设置 area
|
||||
if (area) {
|
||||
userData.area = area;
|
||||
console.log("新用户,设置地区为:", area);
|
||||
}
|
||||
|
||||
const insertResult = await postgrestPost<SsoUser[], SsoUser>("sso_users", userData as SsoUser, token);
|
||||
|
||||
if (insertResult.error) {
|
||||
@@ -606,8 +624,8 @@ export async function saveUserInfo(userInfo: UserInfo, token?: string): Promise<
|
||||
await addDefaultRole(userData_with_id.id, 2, token);
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
return {
|
||||
success: true,
|
||||
data: userData_with_id
|
||||
};
|
||||
}
|
||||
|
||||
+35
-10
@@ -2,13 +2,34 @@ import { type LoaderFunctionArgs, redirect } from "@remix-run/node";
|
||||
import { createUserSession, saveUserInfo, sessionStorage } from "~/api/login/auth.server";
|
||||
import { JWTUtils, type UserInfoForJWT } from "~/utils/jwt";
|
||||
|
||||
/**
|
||||
* 端口号到地区的映射关系
|
||||
* 根据 ecosystem.config.cjs 配置文件
|
||||
*/
|
||||
const PORT_TO_AREA_MAP: Record<string, string> = {
|
||||
'51703': '梅州',
|
||||
'51704': '云浮',
|
||||
'51705': '揭阳',
|
||||
'51706': '潮州',
|
||||
'51707': '省局'
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据端口号获取地区
|
||||
* @param port - 端口号
|
||||
* @returns 地区名称,如果未找到则返回 undefined
|
||||
*/
|
||||
function getAreaByPort(port: string): string | undefined {
|
||||
return PORT_TO_AREA_MAP[port];
|
||||
}
|
||||
|
||||
/**
|
||||
* 辅助函数:使用 session flash 重定向到登录页面并传递错误信息
|
||||
*/
|
||||
async function redirectToLoginWithError(request: Request, errorMessage: string) {
|
||||
const session = await sessionStorage.getSession(request.headers.get("Cookie"));
|
||||
session.flash("loginError", errorMessage);
|
||||
|
||||
|
||||
return redirect("/login", {
|
||||
headers: {
|
||||
"Set-Cookie": await sessionStorage.commitSession(session)
|
||||
@@ -19,18 +40,22 @@ async function redirectToLoginWithError(request: Request, errorMessage: string)
|
||||
export async function loader({ request }: LoaderFunctionArgs) {
|
||||
const url = new URL(request.url);
|
||||
const origin = url.origin; // 获取请求的源 (e.g., "http://10.79.97.17:51703")
|
||||
const port = url.port; // 获取端口号
|
||||
const area = getAreaByPort(port); // 根据端口号获取地区
|
||||
const code = url.searchParams.get("code");
|
||||
const state = url.searchParams.get("state");
|
||||
const error = url.searchParams.get("error");
|
||||
const error_description = url.searchParams.get("error_description");
|
||||
|
||||
console.log("🔧 OAuth2.0回调参数:", {
|
||||
code: code ? `${code.substring(0, 10)}...` : null,
|
||||
state: state,
|
||||
error: error,
|
||||
error_description: error_description,
|
||||
fullUrl: request.url
|
||||
});
|
||||
// console.log("🔧 OAuth2.0回调参数:", {
|
||||
// code: code ? `${code.substring(0, 10)}...` : null,
|
||||
// state: state,
|
||||
// error: error,
|
||||
// error_description: error_description,
|
||||
// fullUrl: request.url,
|
||||
// port: port,
|
||||
// area: area
|
||||
// });
|
||||
|
||||
// 检查是否有错误
|
||||
if (error) {
|
||||
@@ -126,14 +151,14 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
const tempToken = JWTUtils.generateJWT(tempUserInfo, tokenResponse.expires_in);
|
||||
|
||||
// 成功获取用户信息之后通过auth.server.ts中的saveUserInfo方法去写入自己的数据库中,通过sub作为唯一值去添加数据
|
||||
const saveResult = await saveUserInfo(userInfo.data, tempToken);
|
||||
const saveResult = await saveUserInfo(userInfo.data, tempToken, area);
|
||||
if (!saveResult.success) {
|
||||
console.error("保存用户信息到数据库失败:", saveResult.error);
|
||||
// 注意:即使保存到数据库失败,我们仍然继续登录流程,因为用户已经通过了身份验证
|
||||
return redirectToLoginWithError(request, "保存用户信息失败,请重新登录");
|
||||
}
|
||||
|
||||
console.log("用户信息已成功保存到数据库");
|
||||
console.log("用户信息已成功保存到数据库,地区:", area || "未设置");
|
||||
const savedUserData = saveResult.data!;
|
||||
|
||||
// 生成前端专用JWT(使用完整的用户信息,包括数据库 ID)
|
||||
|
||||
@@ -387,7 +387,7 @@ export default function FilesUpload() {
|
||||
filteredTypes = types.filter(type => type.id === 1);
|
||||
} else if (reviewType === 'record') {
|
||||
// 只保留 id=2 和 id=3 的选项
|
||||
filteredTypes = types.filter(type => type.id === 2 || type.id === 3);
|
||||
filteredTypes = types.filter(type => type.id === 2 || type.id === 3 || type.id === 155);
|
||||
} else {
|
||||
// 如果reviewType不匹配任何条件,使用原始数据
|
||||
filteredTypes = types;
|
||||
@@ -2113,10 +2113,10 @@ export default function FilesUpload() {
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||
<div className="form-group">
|
||||
<label htmlFor="file-type-select" className="form-label">文件类型 <span className="text-red-500">*</span></label>
|
||||
<select
|
||||
<select
|
||||
id="file-type-select"
|
||||
name="fileType"
|
||||
className={`form-select ${fileTypeError ? 'border-red-500' : ''}`}
|
||||
className={`form-select ${fileTypeError ? 'border-red-500' : ''}`}
|
||||
value={fileType}
|
||||
onChange={handleFileTypeChange}
|
||||
disabled={uploadStage !== "idle"}
|
||||
@@ -2125,6 +2125,7 @@ export default function FilesUpload() {
|
||||
{documentTypesState.map(type => (
|
||||
<option key={type.id} value={type.id}>{type.name}</option>
|
||||
))}
|
||||
{/* <option key="TSXZCF" value="TSXZCF">测试行政处罚卷宗</option> */}
|
||||
</select>
|
||||
|
||||
{fileTypeError && (
|
||||
|
||||
Reference in New Issue
Block a user