diff --git a/open-isle-cli/src/views/SettingsPageView.vue b/open-isle-cli/src/views/SettingsPageView.vue index d2d2fd86c..8bd51ff8d 100644 --- a/open-isle-cli/src/views/SettingsPageView.vue +++ b/open-isle-cli/src/views/SettingsPageView.vue @@ -1,13 +1,133 @@ 设置 - 这里是设置页面。 + + + + + + + 用户名 + + + + 自我介绍 + + + + + 管理员设置 + + 发布规则 + + 直接发布 + 审核后发布 + + + + 密码强度 + + 低 + 中 + 高 + + + + + 取消 + 保存 + @@ -15,4 +135,31 @@ export default { .settings-page { padding: 20px; } +.avatar-row { + display: flex; + align-items: center; + gap: 10px; + margin-bottom: 15px; +} +.avatar-preview { + width: 80px; + height: 80px; + border-radius: 40px; + object-fit: cover; +} +.form-row { + margin-bottom: 15px; + display: flex; + flex-direction: column; +} +.admin-section { + margin-top: 30px; + padding-top: 10px; + border-top: 1px solid #ccc; +} +.buttons { + margin-top: 20px; + display: flex; + gap: 10px; +} diff --git a/src/main/java/com/openisle/controller/AdminConfigController.java b/src/main/java/com/openisle/controller/AdminConfigController.java new file mode 100644 index 000000000..cb6c32949 --- /dev/null +++ b/src/main/java/com/openisle/controller/AdminConfigController.java @@ -0,0 +1,42 @@ +package com.openisle.controller; + +import com.openisle.model.PasswordStrength; +import com.openisle.model.PublishMode; +import com.openisle.service.PasswordValidator; +import com.openisle.service.PostService; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/api/admin/config") +@RequiredArgsConstructor +public class AdminConfigController { + private final PostService postService; + private final PasswordValidator passwordValidator; + + @GetMapping + public ConfigDto getConfig() { + ConfigDto dto = new ConfigDto(); + dto.setPublishMode(postService.getPublishMode()); + dto.setPasswordStrength(passwordValidator.getStrength()); + return dto; + } + + @PostMapping + public ConfigDto updateConfig(@RequestBody ConfigDto dto) { + if (dto.getPublishMode() != null) { + postService.setPublishMode(dto.getPublishMode()); + } + if (dto.getPasswordStrength() != null) { + passwordValidator.setStrength(dto.getPasswordStrength()); + } + return getConfig(); + } + + @Data + public static class ConfigDto { + private PublishMode publishMode; + private PasswordStrength passwordStrength; + } +} diff --git a/src/main/java/com/openisle/controller/UserController.java b/src/main/java/com/openisle/controller/UserController.java index 2a9615240..879d4ecb8 100644 --- a/src/main/java/com/openisle/controller/UserController.java +++ b/src/main/java/com/openisle/controller/UserController.java @@ -64,6 +64,13 @@ public class UserController { return ResponseEntity.ok(Map.of("url", url)); } + @PutMapping("/me") + public ResponseEntity updateProfile(@RequestBody UpdateProfileDto dto, + Authentication auth) { + User user = userService.updateProfile(auth.getName(), dto.getUsername(), dto.getIntroduction()); + return ResponseEntity.ok(toDto(user)); + } + @GetMapping("/{username}") public ResponseEntity getUser(@PathVariable String username) { User user = userService.findByUsername(username).orElseThrow(); @@ -128,6 +135,8 @@ public class UserController { dto.setUsername(user.getUsername()); dto.setEmail(user.getEmail()); dto.setAvatar(user.getAvatar()); + dto.setRole(user.getRole().name()); + dto.setIntroduction(user.getIntroduction()); dto.setFollowers(subscriptionService.countSubscribers(user.getUsername())); dto.setFollowing(subscriptionService.countSubscribed(user.getUsername())); return dto; @@ -158,6 +167,8 @@ public class UserController { private String username; private String email; private String avatar; + private String role; + private String introduction; private long followers; private long following; } @@ -179,6 +190,12 @@ public class UserController { private Long postId; } + @Data + private static class UpdateProfileDto { + private String username; + private String introduction; + } + @Data private static class UserAggregateDto { private UserDto user; diff --git a/src/main/java/com/openisle/model/User.java b/src/main/java/com/openisle/model/User.java index 43a726126..7d82e6973 100644 --- a/src/main/java/com/openisle/model/User.java +++ b/src/main/java/com/openisle/model/User.java @@ -37,6 +37,9 @@ public class User { private String avatar; + @Column(length = 1000) + private String introduction; + @Enumerated(EnumType.STRING) @Column(nullable = false) private Role role = Role.USER; diff --git a/src/main/java/com/openisle/service/PasswordValidator.java b/src/main/java/com/openisle/service/PasswordValidator.java index 568b061f0..c8979edae 100644 --- a/src/main/java/com/openisle/service/PasswordValidator.java +++ b/src/main/java/com/openisle/service/PasswordValidator.java @@ -7,12 +7,20 @@ import org.springframework.stereotype.Service; @Service public class PasswordValidator { - private final PasswordStrength strength; + private PasswordStrength strength; public PasswordValidator(@Value("${app.password.strength:LOW}") PasswordStrength strength) { this.strength = strength; } + public PasswordStrength getStrength() { + return strength; + } + + public void setStrength(PasswordStrength strength) { + this.strength = strength; + } + public void validate(String password) { if (password == null || password.isEmpty()) { throw new FieldException("password", "Password cannot be empty"); diff --git a/src/main/java/com/openisle/service/PostService.java b/src/main/java/com/openisle/service/PostService.java index 9dff602ca..8bbfbc14a 100644 --- a/src/main/java/com/openisle/service/PostService.java +++ b/src/main/java/com/openisle/service/PostService.java @@ -24,7 +24,7 @@ public class PostService { private final UserRepository userRepository; private final CategoryRepository categoryRepository; private final TagRepository tagRepository; - private final PublishMode publishMode; + private PublishMode publishMode; private final NotificationService notificationService; private final SubscriptionService subscriptionService; @@ -45,6 +45,14 @@ public class PostService { this.publishMode = publishMode; } + public PublishMode getPublishMode() { + return publishMode; + } + + public void setPublishMode(PublishMode publishMode) { + this.publishMode = publishMode; + } + public Post createPost(String username, Long categoryId, String title, diff --git a/src/main/java/com/openisle/service/UserService.java b/src/main/java/com/openisle/service/UserService.java index d007401e4..06ff4294e 100644 --- a/src/main/java/com/openisle/service/UserService.java +++ b/src/main/java/com/openisle/service/UserService.java @@ -94,4 +94,19 @@ public class UserService { user.setAvatar(avatarUrl); return userRepository.save(user); } + + public User updateProfile(String currentUsername, String newUsername, String introduction) { + User user = userRepository.findByUsername(currentUsername) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + if (newUsername != null && !newUsername.equals(currentUsername)) { + userRepository.findByUsername(newUsername).ifPresent(u -> { + throw new FieldException("username", "User name already exists"); + }); + user.setUsername(newUsername); + } + if (introduction != null) { + user.setIntroduction(introduction); + } + return userRepository.save(user); + } }
这里是设置页面。