feat: 开发中...
This commit is contained in:
@@ -10,12 +10,6 @@ group = 'cn.hamster3.application.blog'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '17'
|
||||
|
||||
configurations {
|
||||
compileOnly {
|
||||
extendsFrom annotationProcessor
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url "https://maven.airgame.net/maven-public"
|
||||
@@ -32,10 +26,6 @@ dependencies {
|
||||
implementation 'org.mapstruct:mapstruct: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
|
||||
compileOnly 'org.jetbrains:annotations:24.0.0'
|
||||
|
||||
|
@@ -22,7 +22,8 @@ public class AuthenticationFilter extends OncePerRequestFilter {
|
||||
}
|
||||
|
||||
@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);
|
||||
if (session == null) {
|
||||
filterChain.doFilter(request, response);
|
||||
|
@@ -15,9 +15,9 @@ public class SecurityConfig {
|
||||
return http.authorizeHttpRequests(request -> request
|
||||
.requestMatchers(HttpMethod.GET, "/", "/index", "/index.html").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.POST, "/api/v1/user/").anonymous()
|
||||
.requestMatchers(HttpMethod.POST, "/api/v1/user/", "/api/v1/user/login").anonymous()
|
||||
.anyRequest().authenticated())
|
||||
.cors().and()
|
||||
.csrf().disable()
|
||||
|
@@ -41,7 +41,7 @@ public class UserController {
|
||||
}
|
||||
|
||||
@GetMapping("/current")
|
||||
@Operation(summary = "查询当前用户")
|
||||
@Operation(summary = "查询当前登录用户信息")
|
||||
public ResponseVO<UserInfoResponseVO> getCurrentUserInfo() {
|
||||
return userService.getCurrentUserInfo();
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class UserController {
|
||||
}
|
||||
|
||||
@GetMapping("/{userID}/")
|
||||
@Operation(summary = "查询用户")
|
||||
@Operation(summary = "查询指定用户信息")
|
||||
public ResponseVO<UserInfoResponseVO> getUserInfo(@Parameter(description = "用户ID") @PathVariable UUID userID) {
|
||||
return userService.getUserInfo(userID);
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package cn.hamster3.application.blog.service.impl;
|
||||
|
||||
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.mapper.BlogMapper;
|
||||
import cn.hamster3.application.blog.entity.repo.BlogRepository;
|
||||
@@ -60,11 +59,15 @@ public class BlogService implements IBlogService {
|
||||
if (blogEntity == null) {
|
||||
return ResponseVO.failed("该博文不存在!");
|
||||
}
|
||||
if (user.getRole() == UserRole.GUEST) {
|
||||
return ResponseVO.failed("你没有这个权限!");
|
||||
}
|
||||
if (user.getRole() != UserRole.ADMIN) {
|
||||
if (!blogEntity.getCreator().getId().equals(user.getId())) {
|
||||
switch (user.getRole()) {
|
||||
case ADMIN -> {
|
||||
}
|
||||
case AUTHOR -> {
|
||||
if (!blogEntity.getCreator().getId().equals(user.getId())) {
|
||||
return ResponseVO.failed("你没有这个权限!");
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
return ResponseVO.failed("你没有这个权限!");
|
||||
}
|
||||
}
|
||||
@@ -85,16 +88,16 @@ public class BlogService implements IBlogService {
|
||||
return ResponseVO.unauthorized();
|
||||
}
|
||||
switch (user.getRole()) {
|
||||
case AUTHOR -> {
|
||||
if (!blogRepo.existsByIdAndCreator_Id(blogID, user.getId())) {
|
||||
return ResponseVO.failed("该博文不存在或不属于你!");
|
||||
}
|
||||
}
|
||||
case ADMIN -> {
|
||||
if (!blogRepo.existsById(blogID)) {
|
||||
return ResponseVO.failed("该博文不存在!");
|
||||
}
|
||||
}
|
||||
case AUTHOR -> {
|
||||
if (!blogRepo.existsByIdAndCreator_Id(blogID, user.getId())) {
|
||||
return ResponseVO.failed("该博文不存在或不属于你!");
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
return ResponseVO.failed("你没有这个权限!");
|
||||
}
|
||||
@@ -103,4 +106,5 @@ public class BlogService implements IBlogService {
|
||||
blogRepo.deleteById(blogID);
|
||||
return ResponseVO.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -73,11 +73,6 @@ public class UserService implements IUserService {
|
||||
log.info("prepare to save userinfo: {}", 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));
|
||||
}
|
||||
|
||||
@@ -153,8 +148,7 @@ public class UserService implements IUserService {
|
||||
|
||||
@Override
|
||||
public @NotNull ResponseVO<PageableVO<UserInfoResponseVO>> getAllUserInfo(@NotNull Pageable pageable) {
|
||||
return PageableVO.success(
|
||||
userRepo.findAll(pageable).map(o -> userMapper.entityToInfoVO(o)));
|
||||
return PageableVO.success(userRepo.findAll(pageable).map(o -> userMapper.entityToInfoVO(o)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -166,15 +160,15 @@ public class UserService implements IUserService {
|
||||
|
||||
@Override
|
||||
public @NotNull ResponseVO<PageableVO<BlogInfoResponseVO>> getUserBlogList(@NotNull UUID userID, @NotNull Pageable pageable) {
|
||||
return PageableVO.success(
|
||||
blogRepo.findByCreator_IdOrderByCreateTimeDesc(userID, pageable)
|
||||
.map(o -> blogMapper.entityToInfoVO(o)));
|
||||
return PageableVO.success(blogRepo.findByCreator_IdOrderByCreateTimeDesc(userID, pageable)
|
||||
.map(o -> blogMapper.entityToInfoVO(o))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ResponseVO<PageableVO<AttachInfoResponseVO>> getUserAttachList(@NotNull UUID userID, @NotNull Pageable pageable) {
|
||||
return PageableVO.success(
|
||||
attachRepo.findByCreator_IdOrderByCreateTimeDesc(userID, pageable)
|
||||
.map(o -> attachMapper.entityToInfoVO(o)));
|
||||
return PageableVO.success(attachRepo.findByCreator_IdOrderByCreateTimeDesc(userID, pageable)
|
||||
.map(o -> attachMapper.entityToInfoVO(o))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@ import { UserInfoResponseVORoleEnum } from "@/swagger";
|
||||
const menuIndex = ref<string>(document.location.pathname);
|
||||
|
||||
onMounted(() => {
|
||||
menuIndex.value = document.location.pathname;
|
||||
// 获取站点标题
|
||||
api.SettingController.getSettingContent(siteSetting.keys.site.title).then(
|
||||
(response) => {
|
||||
|
@@ -1,16 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
import "@wangeditor/editor/dist/css/style.css";
|
||||
import { ref } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
|
||||
import { api, globalStore } from "@/api";
|
||||
import router from "@/router";
|
||||
import type { BlogInfoResponseVO } from "@/swagger";
|
||||
import { ElMessage } from "element-plus";
|
||||
|
||||
const blogInfo = ref<BlogInfoResponseVO>();
|
||||
|
||||
const blogID = useRoute().params.id.toString();
|
||||
const blogID = parseInt(useRoute().params.id.toString());
|
||||
if (blogID) {
|
||||
api.BlogController.getBlogInfo(parseInt(blogID)).then((resp) => {
|
||||
api.BlogController.getBlogInfo(blogID).then((resp) => {
|
||||
const vo = resp.data;
|
||||
blogInfo.value = vo.content;
|
||||
});
|
||||
@@ -21,6 +23,21 @@ function editBlog() {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
</script>
|
||||
@@ -50,10 +67,10 @@ function deleteBlog() {
|
||||
</el-container>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
<style>
|
||||
.blog-container {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
margin: 0 auto;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
@@ -89,7 +106,30 @@ function deleteBlog() {
|
||||
}
|
||||
|
||||
.blog-content {
|
||||
width: 100%;
|
||||
width: 95%;
|
||||
margin: 0 auto;
|
||||
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>
|
||||
|
@@ -42,21 +42,20 @@ function load() {
|
||||
|
||||
<style scoped>
|
||||
.infinite-list {
|
||||
width: 95%;
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
margin: 0 auto;
|
||||
list-style: none;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.infinite-list .infinite-list-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
.infinite-list .infinite-list-item {
|
||||
margin-top: 10px;
|
||||
.infinite-list-item {
|
||||
margin: 10px 10px 0 10px;
|
||||
}
|
||||
</style>
|
||||
|
Reference in New Issue
Block a user