feat: implement settings page and config management

This commit is contained in:
Tim
2025-07-07 20:41:52 +08:00
parent fbf0d9fe2f
commit 693d6d5e6b
7 changed files with 244 additions and 4 deletions

View File

@@ -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");

View File

@@ -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,

View File

@@ -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);
}
}