Add Badge and UserBadge functionality with criteria support and service updates
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package SuMoC.backend.user.service;
|
||||
|
||||
import SuMoC.backend.user.models.User;
|
||||
import SuMoC.backend.user.repository.UserRepository;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class CurrentUserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public CurrentUserService(UserRepository userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
public User get() {
|
||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
if (auth == null || !auth.isAuthenticated()) {
|
||||
throw new RuntimeException("Nicht authentifiziert");
|
||||
}
|
||||
|
||||
return userRepository.findByEmail(auth.getName())
|
||||
.orElseThrow(() -> new RuntimeException("User existiert nicht mehr"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user