Files
BiCO/src/main/java/de/jottyfan/bico/modules/profile/ProfileController.java
2025-12-14 21:51:29 +01:00

49 lines
1.3 KiB
Java

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;
import de.jottyfan.bico.modules.CommonController;
/**
*
* @author jotty
*
*/
@RestController
public class ProfileController extends CommonController {
@Autowired
private ProfileService service;
/**
* update the theme of the current user
*
* @param theme the theme
*
*/
@CrossOrigin(origins = "*")
@PostMapping("/updateTheme/{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);
}
}