feat: 开发中...
This commit is contained in:
@@ -10,12 +10,6 @@ group = 'cn.hamster3.application.blog'
|
|||||||
version = '0.0.1-SNAPSHOT'
|
version = '0.0.1-SNAPSHOT'
|
||||||
sourceCompatibility = '17'
|
sourceCompatibility = '17'
|
||||||
|
|
||||||
configurations {
|
|
||||||
compileOnly {
|
|
||||||
extendsFrom annotationProcessor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
url "https://maven.airgame.net/maven-public"
|
url "https://maven.airgame.net/maven-public"
|
||||||
@@ -32,10 +26,6 @@ dependencies {
|
|||||||
implementation 'org.mapstruct:mapstruct:1.5.3.Final'
|
implementation 'org.mapstruct:mapstruct:1.5.3.Final'
|
||||||
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final'
|
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final'
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/com.github.therapi/therapi-runtime-javadoc
|
|
||||||
implementation 'com.github.therapi:therapi-runtime-javadoc:0.15.0'
|
|
||||||
annotationProcessor 'com.github.therapi:therapi-runtime-javadoc:0.15.0'
|
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/org.jetbrains/annotations
|
// https://mvnrepository.com/artifact/org.jetbrains/annotations
|
||||||
compileOnly 'org.jetbrains:annotations:24.0.0'
|
compileOnly 'org.jetbrains:annotations:24.0.0'
|
||||||
|
|
||||||
|
@@ -22,7 +22,8 @@ public class AuthenticationFilter extends OncePerRequestFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doFilterInternal(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull FilterChain filterChain) throws ServletException, IOException {
|
protected void doFilterInternal(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response,
|
||||||
|
@NotNull FilterChain filterChain) throws ServletException, IOException {
|
||||||
HttpSession session = request.getSession(false);
|
HttpSession session = request.getSession(false);
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
|
@@ -15,9 +15,9 @@ public class SecurityConfig {
|
|||||||
return http.authorizeHttpRequests(request -> request
|
return http.authorizeHttpRequests(request -> request
|
||||||
.requestMatchers(HttpMethod.GET, "/", "/index", "/index.html").permitAll()
|
.requestMatchers(HttpMethod.GET, "/", "/index", "/index.html").permitAll()
|
||||||
.requestMatchers(HttpMethod.GET, "/favicon.ico", "/assets/**").permitAll()
|
.requestMatchers(HttpMethod.GET, "/favicon.ico", "/assets/**").permitAll()
|
||||||
.requestMatchers(HttpMethod.GET, "/register", "/login").permitAll()
|
.requestMatchers(HttpMethod.GET, "/api/v1/**").permitAll()
|
||||||
.requestMatchers(HttpMethod.GET, "/swagger-ui/**", "v3/api-docs/**").permitAll()
|
.requestMatchers(HttpMethod.GET, "/swagger-ui/**", "v3/api-docs/**").permitAll()
|
||||||
.requestMatchers(HttpMethod.POST, "/api/v1/user/").anonymous()
|
.requestMatchers(HttpMethod.POST, "/api/v1/user/", "/api/v1/user/login").anonymous()
|
||||||
.anyRequest().authenticated())
|
.anyRequest().authenticated())
|
||||||
.cors().and()
|
.cors().and()
|
||||||
.csrf().disable()
|
.csrf().disable()
|
||||||
|
@@ -41,7 +41,7 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/current")
|
@GetMapping("/current")
|
||||||
@Operation(summary = "查询当前用户")
|
@Operation(summary = "查询当前登录用户信息")
|
||||||
public ResponseVO<UserInfoResponseVO> getCurrentUserInfo() {
|
public ResponseVO<UserInfoResponseVO> getCurrentUserInfo() {
|
||||||
return userService.getCurrentUserInfo();
|
return userService.getCurrentUserInfo();
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{userID}/")
|
@GetMapping("/{userID}/")
|
||||||
@Operation(summary = "查询用户")
|
@Operation(summary = "查询指定用户信息")
|
||||||
public ResponseVO<UserInfoResponseVO> getUserInfo(@Parameter(description = "用户ID") @PathVariable UUID userID) {
|
public ResponseVO<UserInfoResponseVO> getUserInfo(@Parameter(description = "用户ID") @PathVariable UUID userID) {
|
||||||
return userService.getUserInfo(userID);
|
return userService.getUserInfo(userID);
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package cn.hamster3.application.blog.service.impl;
|
package cn.hamster3.application.blog.service.impl;
|
||||||
|
|
||||||
import cn.hamster3.application.blog.config.security.BlogUser;
|
import cn.hamster3.application.blog.config.security.BlogUser;
|
||||||
import cn.hamster3.application.blog.constant.UserRole;
|
|
||||||
import cn.hamster3.application.blog.entity.BlogEntity;
|
import cn.hamster3.application.blog.entity.BlogEntity;
|
||||||
import cn.hamster3.application.blog.entity.mapper.BlogMapper;
|
import cn.hamster3.application.blog.entity.mapper.BlogMapper;
|
||||||
import cn.hamster3.application.blog.entity.repo.BlogRepository;
|
import cn.hamster3.application.blog.entity.repo.BlogRepository;
|
||||||
@@ -60,11 +59,15 @@ public class BlogService implements IBlogService {
|
|||||||
if (blogEntity == null) {
|
if (blogEntity == null) {
|
||||||
return ResponseVO.failed("该博文不存在!");
|
return ResponseVO.failed("该博文不存在!");
|
||||||
}
|
}
|
||||||
if (user.getRole() == UserRole.GUEST) {
|
switch (user.getRole()) {
|
||||||
return ResponseVO.failed("你没有这个权限!");
|
case ADMIN -> {
|
||||||
}
|
}
|
||||||
if (user.getRole() != UserRole.ADMIN) {
|
case AUTHOR -> {
|
||||||
if (!blogEntity.getCreator().getId().equals(user.getId())) {
|
if (!blogEntity.getCreator().getId().equals(user.getId())) {
|
||||||
|
return ResponseVO.failed("你没有这个权限!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
return ResponseVO.failed("你没有这个权限!");
|
return ResponseVO.failed("你没有这个权限!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,16 +88,16 @@ public class BlogService implements IBlogService {
|
|||||||
return ResponseVO.unauthorized();
|
return ResponseVO.unauthorized();
|
||||||
}
|
}
|
||||||
switch (user.getRole()) {
|
switch (user.getRole()) {
|
||||||
case AUTHOR -> {
|
|
||||||
if (!blogRepo.existsByIdAndCreator_Id(blogID, user.getId())) {
|
|
||||||
return ResponseVO.failed("该博文不存在或不属于你!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case ADMIN -> {
|
case ADMIN -> {
|
||||||
if (!blogRepo.existsById(blogID)) {
|
if (!blogRepo.existsById(blogID)) {
|
||||||
return ResponseVO.failed("该博文不存在!");
|
return ResponseVO.failed("该博文不存在!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case AUTHOR -> {
|
||||||
|
if (!blogRepo.existsByIdAndCreator_Id(blogID, user.getId())) {
|
||||||
|
return ResponseVO.failed("该博文不存在或不属于你!");
|
||||||
|
}
|
||||||
|
}
|
||||||
default -> {
|
default -> {
|
||||||
return ResponseVO.failed("你没有这个权限!");
|
return ResponseVO.failed("你没有这个权限!");
|
||||||
}
|
}
|
||||||
@@ -103,4 +106,5 @@ public class BlogService implements IBlogService {
|
|||||||
blogRepo.deleteById(blogID);
|
blogRepo.deleteById(blogID);
|
||||||
return ResponseVO.success();
|
return ResponseVO.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -73,11 +73,6 @@ public class UserService implements IUserService {
|
|||||||
log.info("prepare to save userinfo: {}", entity);
|
log.info("prepare to save userinfo: {}", entity);
|
||||||
UserEntity save = userRepo.save(entity);
|
UserEntity save = userRepo.save(entity);
|
||||||
|
|
||||||
Authentication authenticate = authenticationManager.authenticate(
|
|
||||||
new UsernamePasswordAuthenticationToken(requireVO.getEmail(), requireVO.getPassword())
|
|
||||||
);
|
|
||||||
HttpSession session = request.getSession();
|
|
||||||
session.setAttribute("Authentication", authenticate);
|
|
||||||
return ResponseVO.success("注册成功!", userMapper.entityToInfoVO(save));
|
return ResponseVO.success("注册成功!", userMapper.entityToInfoVO(save));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,8 +148,7 @@ public class UserService implements IUserService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull ResponseVO<PageableVO<UserInfoResponseVO>> getAllUserInfo(@NotNull Pageable pageable) {
|
public @NotNull ResponseVO<PageableVO<UserInfoResponseVO>> getAllUserInfo(@NotNull Pageable pageable) {
|
||||||
return PageableVO.success(
|
return PageableVO.success(userRepo.findAll(pageable).map(o -> userMapper.entityToInfoVO(o)));
|
||||||
userRepo.findAll(pageable).map(o -> userMapper.entityToInfoVO(o)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -166,15 +160,15 @@ public class UserService implements IUserService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull ResponseVO<PageableVO<BlogInfoResponseVO>> getUserBlogList(@NotNull UUID userID, @NotNull Pageable pageable) {
|
public @NotNull ResponseVO<PageableVO<BlogInfoResponseVO>> getUserBlogList(@NotNull UUID userID, @NotNull Pageable pageable) {
|
||||||
return PageableVO.success(
|
return PageableVO.success(blogRepo.findByCreator_IdOrderByCreateTimeDesc(userID, pageable)
|
||||||
blogRepo.findByCreator_IdOrderByCreateTimeDesc(userID, pageable)
|
.map(o -> blogMapper.entityToInfoVO(o))
|
||||||
.map(o -> blogMapper.entityToInfoVO(o)));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull ResponseVO<PageableVO<AttachInfoResponseVO>> getUserAttachList(@NotNull UUID userID, @NotNull Pageable pageable) {
|
public @NotNull ResponseVO<PageableVO<AttachInfoResponseVO>> getUserAttachList(@NotNull UUID userID, @NotNull Pageable pageable) {
|
||||||
return PageableVO.success(
|
return PageableVO.success(attachRepo.findByCreator_IdOrderByCreateTimeDesc(userID, pageable)
|
||||||
attachRepo.findByCreator_IdOrderByCreateTimeDesc(userID, pageable)
|
.map(o -> attachMapper.entityToInfoVO(o))
|
||||||
.map(o -> attachMapper.entityToInfoVO(o)));
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,7 @@ import { UserInfoResponseVORoleEnum } from "@/swagger";
|
|||||||
const menuIndex = ref<string>(document.location.pathname);
|
const menuIndex = ref<string>(document.location.pathname);
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
menuIndex.value = document.location.pathname;
|
||||||
// 获取站点标题
|
// 获取站点标题
|
||||||
api.SettingController.getSettingContent(siteSetting.keys.site.title).then(
|
api.SettingController.getSettingContent(siteSetting.keys.site.title).then(
|
||||||
(response) => {
|
(response) => {
|
||||||
|
@@ -1,16 +1,18 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import "@wangeditor/editor/dist/css/style.css";
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { useRoute } from "vue-router";
|
import { useRoute } from "vue-router";
|
||||||
|
|
||||||
import { api, globalStore } from "@/api";
|
import { api, globalStore } from "@/api";
|
||||||
import router from "@/router";
|
import router from "@/router";
|
||||||
import type { BlogInfoResponseVO } from "@/swagger";
|
import type { BlogInfoResponseVO } from "@/swagger";
|
||||||
|
import { ElMessage } from "element-plus";
|
||||||
|
|
||||||
const blogInfo = ref<BlogInfoResponseVO>();
|
const blogInfo = ref<BlogInfoResponseVO>();
|
||||||
|
|
||||||
const blogID = useRoute().params.id.toString();
|
const blogID = parseInt(useRoute().params.id.toString());
|
||||||
if (blogID) {
|
if (blogID) {
|
||||||
api.BlogController.getBlogInfo(parseInt(blogID)).then((resp) => {
|
api.BlogController.getBlogInfo(blogID).then((resp) => {
|
||||||
const vo = resp.data;
|
const vo = resp.data;
|
||||||
blogInfo.value = vo.content;
|
blogInfo.value = vo.content;
|
||||||
});
|
});
|
||||||
@@ -21,6 +23,21 @@ function editBlog() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function deleteBlog() {
|
function deleteBlog() {
|
||||||
|
api.BlogController.removeBlog(blogID).then((resp) => {
|
||||||
|
const vo = resp.data;
|
||||||
|
if (vo.code === 200) {
|
||||||
|
ElMessage({
|
||||||
|
type: "success",
|
||||||
|
message: "博文删除成功!",
|
||||||
|
});
|
||||||
|
router.push("/");
|
||||||
|
} else {
|
||||||
|
ElMessage({
|
||||||
|
type: "warning",
|
||||||
|
message: "博文删除失败:" + vo.msg,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
console.log("deleteBlog " + blogID);
|
console.log("deleteBlog " + blogID);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -50,10 +67,10 @@ function deleteBlog() {
|
|||||||
</el-container>
|
</el-container>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style>
|
||||||
.blog-container {
|
.blog-container {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0 auto;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
@@ -89,7 +106,30 @@ function deleteBlog() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.blog-content {
|
.blog-content {
|
||||||
width: 100%;
|
width: 95%;
|
||||||
|
margin: 0 auto;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
}
|
}
|
||||||
|
.blog-content > h1,
|
||||||
|
h2,
|
||||||
|
h3,
|
||||||
|
h4,
|
||||||
|
h5 {
|
||||||
|
line-height: 64px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.blog-content > p {
|
||||||
|
line-height: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.blog-content > * {
|
||||||
|
font-family: system-ui;
|
||||||
|
font-size: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.blog-content > pre {
|
||||||
|
margin: 12px 0 12px 0;
|
||||||
|
padding: 12px 12px 12px 12px;
|
||||||
|
background-color: #ccc;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@@ -42,21 +42,20 @@ function load() {
|
|||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.infinite-list {
|
.infinite-list {
|
||||||
|
width: 95%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0 auto;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
margin-right: 10px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.infinite-list .infinite-list-item {
|
.infinite-list .infinite-list-item {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
margin: 10px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.infinite-list .infinite-list-item {
|
.infinite-list-item {
|
||||||
margin-top: 10px;
|
margin: 10px 10px 0 10px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
Reference in New Issue
Block a user