Use cockies for token check

This commit is contained in:
Sebastien 2018-04-30 14:47:42 +02:00
parent 62130b8506
commit f757d79020
3 changed files with 4 additions and 6 deletions

View File

@ -10,5 +10,4 @@ public class CommandPostData {
public int playlistLimit; public int playlistLimit;
public String chanelId; public String chanelId;
public String name; public String name;
public String token;
} }

View File

@ -84,18 +84,18 @@ public class MusicWebAPIController {
// TODO change token to cookie // TODO change token to cookie
@RequestMapping(value = "/command", method = RequestMethod.POST) @RequestMapping(value = "/command", method = RequestMethod.POST)
public ResponseEntity<CommandResponseData> command(@RequestBody CommandPostData data, HttpServletRequest request, @RequestParam(value = "guild") String guildId){ public ResponseEntity<CommandResponseData> command(@RequestBody CommandPostData data, HttpServletRequest request, @RequestParam(value = "guild") String guildId, @CookieValue("token") String token){
if(data.command != null) { if(data.command != null) {
if(data.token != null) { if(token != null) {
Guild guild = MainBot.jda.getGuildById(guildId); Guild guild = MainBot.jda.getGuildById(guildId);
if(guild == null ){ if(guild == null ){
logger.warn("Request whit no guild!"); logger.warn("Request whit no guild!");
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); return new ResponseEntity<>(new CommandResponseData(data.command,"Missing Guild!\nPlease Re-connect.","token"), HttpStatus.UNAUTHORIZED);
} }
try { try {
UserEntity user = userUtils.getUserWithApiToken(userRepository, data.token); UserEntity user = userUtils.getUserWithApiToken(userRepository, token);
logger.info("Receive command " + data.command + " from " + request.getRemoteAddr() + " USER: " + user.getName() + " GUILD: " + guild.getName()); logger.info("Receive command " + data.command + " from " + request.getRemoteAddr() + " USER: " + user.getName() + " GUILD: " + guild.getName());
if (ApiCommandLoader.apiCommands.containsKey(data.command)) if (ApiCommandLoader.apiCommands.containsKey(data.command))

View File

@ -316,7 +316,6 @@ function updateControl(data){
function sendCommand(command){ function sendCommand(command){
modal_loading.modal('open'); modal_loading.modal('open');
command["token"] = Cookies.get('token');
console.log(command) console.log(command)
$.ajax({ $.ajax({
type: "POST", type: "POST",