登录增加验证码切换
This commit is contained in:
@@ -25,6 +25,8 @@ public class User extends BaseEntity {
|
|||||||
|
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
private String role; // admin-管理员, user-普通用户
|
||||||
|
|
||||||
@TableField("storage_used")
|
@TableField("storage_used")
|
||||||
private Long storageUsed;
|
private Long storageUsed;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.filesystem.security;
|
package com.filesystem.security;
|
||||||
|
|
||||||
|
import com.filesystem.entity.User;
|
||||||
|
import com.filesystem.mapper.UserMapper;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import jakarta.servlet.FilterChain;
|
import jakarta.servlet.FilterChain;
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
@@ -25,6 +27,9 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
@Resource
|
@Resource
|
||||||
private JwtUtil jwtUtil;
|
private JwtUtil jwtUtil;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserMapper userMapper;
|
||||||
|
|
||||||
private static final List<AntPathRequestMatcher> EXCLUDE_MATCHERS = List.of(
|
private static final List<AntPathRequestMatcher> EXCLUDE_MATCHERS = List.of(
|
||||||
new AntPathRequestMatcher("/api/auth/login"),
|
new AntPathRequestMatcher("/api/auth/login"),
|
||||||
new AntPathRequestMatcher("/api/auth/register"),
|
new AntPathRequestMatcher("/api/auth/register"),
|
||||||
@@ -71,7 +76,14 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
String username = jwtUtil.getUsernameFromToken(token);
|
String username = jwtUtil.getUsernameFromToken(token);
|
||||||
Long userId = jwtUtil.getUserIdFromToken(token);
|
Long userId = jwtUtil.getUserIdFromToken(token);
|
||||||
|
|
||||||
UserPrincipal principal = new UserPrincipal(userId, username);
|
// 查询用户角色
|
||||||
|
String role = "user";
|
||||||
|
User user = userMapper.selectById(userId);
|
||||||
|
if (user != null && "admin".equals(user.getRole())) {
|
||||||
|
role = "admin";
|
||||||
|
}
|
||||||
|
|
||||||
|
UserPrincipal principal = new UserPrincipal(userId, username, role);
|
||||||
|
|
||||||
UsernamePasswordAuthenticationToken authentication =
|
UsernamePasswordAuthenticationToken authentication =
|
||||||
new UsernamePasswordAuthenticationToken(principal, null, new ArrayList<>());
|
new UsernamePasswordAuthenticationToken(principal, null, new ArrayList<>());
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ import lombok.Data;
|
|||||||
public class UserPrincipal {
|
public class UserPrincipal {
|
||||||
private Long userId;
|
private Long userId;
|
||||||
private String username;
|
private String username;
|
||||||
|
private String role; // admin-管理员, user-普通用户
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ CREATE TABLE IF NOT EXISTS sys_user (
|
|||||||
email VARCHAR(100) COMMENT '邮箱',
|
email VARCHAR(100) COMMENT '邮箱',
|
||||||
phone VARCHAR(20) COMMENT '手机号',
|
phone VARCHAR(20) COMMENT '手机号',
|
||||||
status INT DEFAULT 1 COMMENT '状态 0-禁用 1-启用',
|
status INT DEFAULT 1 COMMENT '状态 0-禁用 1-启用',
|
||||||
storage_used BIGINT DEFAULT 0 COMMENT '已用存储空间(字节)',
|
role VARCHAR(20) DEFAULT 'user' COMMENT '角色 admin-管理员 user-普通用户',
|
||||||
storage_limit BIGINT DEFAULT 10737418240 COMMENT '存储限制(字节) 默认10GB',
|
|
||||||
register_ip VARCHAR(50) COMMENT '注册IP',
|
register_ip VARCHAR(50) COMMENT '注册IP',
|
||||||
allowed_ips VARCHAR(500) COMMENT '允许的IP段,逗号分隔',
|
allowed_ips VARCHAR(500) COMMENT '允许的IP段,逗号分隔',
|
||||||
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
@@ -75,6 +74,6 @@ CREATE TABLE IF NOT EXISTS sys_message (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='消息表';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='消息表';
|
||||||
|
|
||||||
-- 插入默认管理员账户 (密码: admin123)
|
-- 插入默认管理员账户 (密码: admin123)
|
||||||
INSERT INTO sys_user (username, password, nickname, status, storage_limit, allowed_ips)
|
INSERT INTO sys_user (username, password, nickname, status, storage_limit, role, allowed_ips)
|
||||||
VALUES ('admin', '$2a$10$N.zmdr9k7uOCQb376NoUnuTJ8iAt6Z5EHsM8lE9lBOsl7iAt6Z5EH', '管理员', 1, 10737418240, '0.0.0.0/0')
|
VALUES ('admin', '$2a$10$N.zmdr9k7uOCQb376NoUnuTJ8iAt6Z5EHsM8lE9lBOsl7iAt6Z5EH', '管理员', 1, 10737418240, 'admin', '0.0.0.0/0')
|
||||||
ON DUPLICATE KEY UPDATE username = username;
|
ON DUPLICATE KEY UPDATE username = username;
|
||||||
|
|||||||
Reference in New Issue
Block a user