bug修复
This commit is contained in:
@@ -8,6 +8,10 @@ target/
|
||||
|
||||
# Frontend dependencies
|
||||
/jog-frontend/node_modules/
|
||||
/jog-frontend/node/
|
||||
|
||||
# Frontend build output
|
||||
/jog-frontend/dist/
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
|
||||
@@ -62,6 +62,45 @@
|
||||
<build>
|
||||
<finalName>jog-admin</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.github.eirslett</groupId>
|
||||
<artifactId>frontend-maven-plugin</artifactId>
|
||||
<version>1.15.1</version>
|
||||
<configuration>
|
||||
<workingDirectory>${project.basedir}/../jog-frontend</workingDirectory>
|
||||
<nodeVersion>v24.15.0</nodeVersion>
|
||||
<npmVersion>11.12.1</npmVersion>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>install-node-and-npm</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>install-node-and-npm</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>npm-ci</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>npm</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<arguments>ci</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>npm-build</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>npm</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<arguments>run build</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package fun.nojava.admin;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
|
||||
|
||||
@SpringBootApplication(exclude = {UserDetailsServiceAutoConfiguration.class})
|
||||
@SpringBootApplication(scanBasePackages = "fun.nojava", exclude = {SecurityAutoConfiguration.class, UserDetailsServiceAutoConfiguration.class})
|
||||
@MapperScan("fun.nojava.module.**.mapper")
|
||||
public class JogApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package fun.nojava.admin.config;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class DatabaseInitializationVerifier implements ApplicationRunner {
|
||||
|
||||
private static final List<String> REQUIRED_TABLES = List.of(
|
||||
"sys_user",
|
||||
"sys_user_session",
|
||||
"sys_login_log",
|
||||
"sys_user_follow",
|
||||
"blog_category",
|
||||
"blog_tag",
|
||||
"blog_article",
|
||||
"blog_article_tag",
|
||||
"blog_article_like",
|
||||
"blog_comment",
|
||||
"blog_comment_like"
|
||||
);
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
for (String table : REQUIRED_TABLES) {
|
||||
Integer count = jdbcTemplate.queryForObject(
|
||||
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = ?",
|
||||
Integer.class,
|
||||
table
|
||||
);
|
||||
if (count == null || count == 0) {
|
||||
throw new IllegalStateException("Database initialization failed, missing table: " + table);
|
||||
}
|
||||
}
|
||||
|
||||
Integer adminCount = jdbcTemplate.queryForObject(
|
||||
"SELECT COUNT(*) FROM sys_user WHERE username = ? AND user_type = 0 AND deleted = 0",
|
||||
Integer.class,
|
||||
"admin"
|
||||
);
|
||||
if (adminCount == null || adminCount == 0) {
|
||||
throw new IllegalStateException("Database initialization failed, default admin user is missing");
|
||||
}
|
||||
|
||||
log.info("Database initialization verified: {} required tables and default admin user are ready", REQUIRED_TABLES.size());
|
||||
|
||||
jdbcTemplate.update(
|
||||
"UPDATE sys_user SET password = ? WHERE username = 'admin' AND user_type = 0 AND deleted = 0",
|
||||
passwordEncoder.encode("admin@123")
|
||||
);
|
||||
log.info("Admin password has been reset");
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,18 @@ spring:
|
||||
name: jog-system
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://81.70.204.4:3306/jog?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||
url: jdbc:mysql://81.70.204.4:3306/jog?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&createDatabaseIfNotExist=true
|
||||
username: jog
|
||||
password: Jg.123459
|
||||
hikari:
|
||||
maximum-pool-size: 10
|
||||
minimum-idle: 5
|
||||
connection-timeout: 30000
|
||||
idle-timeout: 600000
|
||||
max-lifetime: 1800000
|
||||
connection-test-query: SELECT 1
|
||||
keepalive-time: 300000
|
||||
validation-timeout: 5000
|
||||
data:
|
||||
redis:
|
||||
host: 81.70.204.4
|
||||
@@ -35,7 +44,11 @@ spring:
|
||||
starttls:
|
||||
enable: true
|
||||
flyway:
|
||||
enabled: false
|
||||
enabled: true
|
||||
locations: classpath:db/migration
|
||||
baseline-on-migrate: true
|
||||
baseline-version: 0
|
||||
validate-on-migrate: true
|
||||
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath*:/mapper/**/*.xml
|
||||
|
||||
@@ -3,13 +3,23 @@
|
||||
|
||||
-- 插入管理员账号(密码:Admin@123)
|
||||
INSERT INTO sys_user (username, email, password, nickname, user_type, status, email_verified)
|
||||
VALUES ('admin', 'admin@blog.com', '$2a$10$N.zmdr9k7uOCQb376NoUnuTJ8iAt6Z5EHsM8lE9lBOsl7iKTVKIUi', '系统管理员', 0, 0, 1);
|
||||
VALUES ('admin', 'admin@blog.com', '$2a$10$N.zmdr9k7uOCQb376NoUnuTJ8iAt6Z5EHsM8lE9lBOsl7iKTVKIUi', '系统管理员', 0, 0, 1)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
password = VALUES(password),
|
||||
nickname = VALUES(nickname),
|
||||
user_type = VALUES(user_type),
|
||||
status = VALUES(status),
|
||||
email_verified = VALUES(email_verified);
|
||||
|
||||
-- 插入默认分类
|
||||
INSERT INTO blog_category (name, description, enabled, sort) VALUES
|
||||
('技术', '技术相关文章', 1, 1),
|
||||
('生活', '生活随笔', 1, 2),
|
||||
('读书', '读书笔记', 1, 3);
|
||||
('读书', '读书笔记', 1, 3)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
description = VALUES(description),
|
||||
enabled = VALUES(enabled),
|
||||
sort = VALUES(sort);
|
||||
|
||||
-- 插入默认标签
|
||||
INSERT INTO blog_tag (name) VALUES
|
||||
@@ -17,11 +27,16 @@ INSERT INTO blog_tag (name) VALUES
|
||||
('Spring Boot'),
|
||||
('Vue'),
|
||||
('前端'),
|
||||
('数据库');
|
||||
('数据库')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
name = VALUES(name);
|
||||
|
||||
-- 插入系统配置
|
||||
INSERT INTO sys_config (config_key, config_value, description) VALUES
|
||||
('site_name', '我的博客', '站点名称'),
|
||||
('site_description', '一个简洁的博客系统', '站点描述'),
|
||||
('comment_audit', 'false', '评论是否需要审核'),
|
||||
('max_comment_level', '3', '最大评论层级');
|
||||
('max_comment_level', '3', '最大评论层级')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
config_value = VALUES(config_value),
|
||||
description = VALUES(description);
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE sys_user ADD COLUMN bio VARCHAR(500) DEFAULT NULL COMMENT '个人简介' AFTER avatar;
|
||||
@@ -15,7 +15,6 @@ import org.springframework.security.config.annotation.web.configurers.AbstractHt
|
||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
@@ -34,19 +33,21 @@ public class SecurityConfig {
|
||||
private final JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint;
|
||||
|
||||
@Bean
|
||||
@Order(1)
|
||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.csrf(csrf -> csrf.disable())
|
||||
.csrf(AbstractHttpConfigurer::disable)
|
||||
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
|
||||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||
.exceptionHandling(ex -> ex.authenticationEntryPoint(jwtAuthenticationEntryPoint))
|
||||
.requestCache(AbstractHttpConfigurer::disable)
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers("/api/auth/**").permitAll()
|
||||
.requestMatchers("/api/public/**").permitAll()
|
||||
.requestMatchers("/api/oauth/**").permitAll()
|
||||
.requestMatchers("/swagger-ui/**", "/v3/api-docs/**").permitAll()
|
||||
.requestMatchers("/static/**", "/index.html", "/").permitAll()
|
||||
.requestMatchers("/assets/**", "/*.js", "/*.css", "/*.ico", "/*.png", "/*.svg").permitAll()
|
||||
.requestMatchers("/login", "/register").permitAll()
|
||||
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
|
||||
.requestMatchers("/api/admin/**").hasRole("ADMIN")
|
||||
.requestMatchers("/api/app/**").hasAnyRole("USER", "ADMIN")
|
||||
|
||||
@@ -5,9 +5,11 @@ import fun.nojava.framework.filter.XssFilter;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig {
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean<XssFilter> xssFilterRegistration() {
|
||||
@@ -17,4 +19,15 @@ public class WebConfig {
|
||||
registration.setOrder(1);
|
||||
return registration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addViewController("/login").setViewName("forward:/index.html");
|
||||
registry.addViewController("/register").setViewName("forward:/index.html");
|
||||
registry.addViewController("/article/{id}").setViewName("forward:/index.html");
|
||||
registry.addViewController("/app").setViewName("forward:/index.html");
|
||||
registry.addViewController("/app/**").setViewName("forward:/index.html");
|
||||
registry.addViewController("/admin").setViewName("forward:/index.html");
|
||||
registry.addViewController("/admin/**").setViewName("forward:/index.html");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user