feat(web): login gate, session identity UI and member management
- main.tsx 挂 AuthProvider 门控:未登录→登录页;must_change_password→强制改密页 - 登录页/改密页/顶栏身份(头像+姓名+角色徽章+退出)按 A·Data-console token 样式 - 全局 fetch 拦截器:任意业务请求 401 自动回登录页(会话过期/被撤销不留死表单) - 系统设置新增「成员与角色」分区(仅 admin 可见):名单、角色调整、启停、重置临时密码、新增成员 - 消灭全部手填操作人:审核/封批/确认计划集/范围规则/来源调度/UI 设置/开始处理/批量重试/ 目录差异确认共 9 处输入框删除,请求体不再携带 actor 字段(服务端从会话注入) - 测试断言方向翻转:显式验证请求体不含 operator_ref/created_by 等字段 - 附带修复:登录失败计数 SQL 参数类型无法推断导致 500(pgx 扩展协议),显式 cast 解决 前端门禁:tsc 0 错、125 用例全绿、build 通过
This commit is contained in:
@@ -108,7 +108,7 @@ func (s *Store) CreateUser(ctx context.Context, username, displayName, role, pas
|
||||
_, err = s.db.Exec(ctx, `
|
||||
INSERT INTO users(id,username,display_name,role,password_hash,must_change_password,state,created_by,created_at,updated_at)
|
||||
VALUES($1,$2,$3,$4,$5,$6,'active',$7,$8,$8)`,
|
||||
id, username, displayName, role, string(hash), true, createdBy, now.UTC())
|
||||
id, username, displayName, role, string(hash), true, createdBy, now.UTC())
|
||||
if err != nil {
|
||||
if isUniqueViolation(err) {
|
||||
return AuthUser{}, ErrAuthDuplicateUsername
|
||||
@@ -308,12 +308,15 @@ func (s *Store) userLockedUntil(ctx context.Context, userID string) (time.Time,
|
||||
}
|
||||
|
||||
func (s *Store) recordFailedLogin(ctx context.Context, userID string, now time.Time) error {
|
||||
// Explicit parameter casts: PostgreSQL cannot infer the type of a bare
|
||||
// parameter inside `$4::interval` / the integer comparison, and the
|
||||
// extended-protocol Prepare would fail with "could not determine data type".
|
||||
_, err := s.db.Exec(ctx, `
|
||||
UPDATE users SET
|
||||
failed_attempts = failed_attempts + 1,
|
||||
locked_until = CASE WHEN failed_attempts + 1 >= $3 THEN $2 + $4::interval ELSE locked_until END,
|
||||
updated_at = $2
|
||||
WHERE id = $1`, userID, now, authMaxFailedAttempts, fmt.Sprintf("%d minutes", int(authLockDuration.Minutes())))
|
||||
locked_until = CASE WHEN failed_attempts + 1 >= $3::int THEN $2::timestamptz + $4::interval ELSE locked_until END,
|
||||
updated_at = $2::timestamptz
|
||||
WHERE id = $1::varchar`, userID, now, authMaxFailedAttempts, fmt.Sprintf("%d minutes", int(authLockDuration.Minutes())))
|
||||
if err != nil {
|
||||
return fmt.Errorf("record failed login: %w", err)
|
||||
}
|
||||
@@ -521,4 +524,3 @@ func derefTime(value *time.Time) time.Time {
|
||||
}
|
||||
return *value
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user