fixed bugs

This commit is contained in:
Jottyfan
2025-12-14 21:51:29 +01:00
parent 3726b9172c
commit b048b7c7bc
9 changed files with 64 additions and 30 deletions

View File

@@ -1,7 +1,12 @@
package de.jottyfan.bico.modules.profile;
import java.security.Principal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -23,12 +28,20 @@ public class ProfileController extends CommonController {
* update the theme of the current user
*
* @param theme the theme
*
*/
@CrossOrigin(origins = "*")
@PostMapping("/updateTheme/{theme}")
public ResponseEntity<?> updateTheme(@PathVariable("theme") String theme) {
// TODO: add profile's user name
String username = "jotty";
service.updateTheme(username, theme);
public ResponseEntity<?> updateTheme(@PathVariable("theme") String theme, Principal principal) {
String username = null;
OAuth2AuthenticationToken token = (OAuth2AuthenticationToken) principal;
if (token != null) {
OAuth2User user = token.getPrincipal();
username = user.getName();
}
if (username != null) {
service.updateTheme(username, theme);
}
return ResponseEntity.ok(null);
}