mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-06-03 16:37:41 +08:00
feat: implement settings page and config management
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user