Revert "Merge branch 'devel' into origin/master"

This reverts commit 34ce297e7c1ff524cb39ee97e415cd53f624a94d.
This commit is contained in:
BrokenFire 2018-02-15 00:57:07 +01:00 committed by Unknown
parent 5eac91aada
commit 5e5419d2be
66 changed files with 160 additions and 1679 deletions

4
.gitignore vendored
View File

@ -14,7 +14,3 @@ META-INF/
classes/artifacts/Discord_Stroumpf_Beta_jar/
src/main/resources/templates/css
src/main/resources/templates/js

View File

@ -9,4 +9,4 @@ RUN chmod +x gradlew
ENV PORT=8080
ENV TOKEN=10
RUN ./gradlew build
CMD java -Xmx500m -jar build/libs/DiscordBot-0.1.0.jar -t ${TOKEN}
CMD java -jar build/libs/DiscordBot-0.1.0.jar -t ${TOKEN}

View File

@ -31,16 +31,15 @@ dependencies {
exclude group:"org.springframework.boot", module: "spring-boot-starter-logging"
}
compile("org.springframework.boot:spring-boot-starter-log4j2")
compile("com.sedmelluq:lavaplayer:1.2.49")
compile("com.sedmelluq:lavaplayer:1.2.45")
compile 'net.dv8tion:JDA:3.3.1_303'
compile group: 'org.json', name: 'json', version: '20160810'
compile 'org.springframework.security:spring-security-web:5.0.1.RELEASE'
// JPA Data (We are going to use Repositories, Entities, Hibernate, etc...)
compile("org.springframework.boot:spring-boot-starter-data-jpa") {
exclude group:"org.springframework.boot", module: "spring-boot-starter-logging"
}
// Use MySQL Connector-J
compile 'mysql:mysql-connector-java'
// JPA Data (We are going to use Repositories, Entities, Hibernate, etc...)
//compile("org.springframework.boot:spring-boot-starter-data-jpa") {
// exclude group:"org.springframework.boot", module: "spring-boot-starter-logging"
//}
// Use MySQL Connector-J
//compile 'mysql:mysql-connector-java'
compile 'org.reflections:reflections:0.9.11'

View File

@ -2,8 +2,8 @@ package net.Broken;
import net.Broken.Commands.Move;
import net.Broken.Commands.Music;
import net.Broken.Tools.AntiSpam;
import net.Broken.Tools.Moderateur;
import net.Broken.Outils.AntiSpam;
import net.Broken.Outils.Moderateur;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;

View File

@ -2,7 +2,7 @@ package net.Broken.Commands;
import net.Broken.Commande;
import net.Broken.Tools.Redirection;
import net.Broken.Outils.Redirection;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;

View File

@ -1,7 +1,7 @@
package net.Broken.Commands;
import net.Broken.Commande;
import net.Broken.Tools.EmbedMessageUtils;
import net.Broken.Outils.EmbedMessageUtils;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageChannel;

View File

@ -2,9 +2,9 @@ package net.Broken.Commands;
import net.Broken.Commande;
import net.Broken.MainBot;
import net.Broken.Tools.EmbedMessageUtils;
import net.Broken.Tools.MessageTimeOut;
import net.Broken.Tools.PrivateMessage;
import net.Broken.Outils.EmbedMessageUtils;
import net.Broken.Outils.MessageTimeOut;
import net.Broken.Outils.PrivateMessage;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.entities.Message;

View File

@ -2,8 +2,8 @@ package net.Broken.Commands;
import net.Broken.Commande;
import net.Broken.MainBot;
import net.Broken.Tools.EmbedMessageUtils;
import net.Broken.Tools.MessageTimeOut;
import net.Broken.Outils.EmbedMessageUtils;
import net.Broken.Outils.MessageTimeOut;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.*;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;

View File

@ -2,9 +2,10 @@ package net.Broken.Commands;
import net.Broken.Commande;
import net.Broken.MainBot;
import net.Broken.Tools.EmbedMessageUtils;
import net.Broken.Tools.MessageTimeOut;
import net.Broken.Outils.EmbedMessageUtils;
import net.Broken.Outils.MessageTimeOut;
import net.Broken.audio.AudioM;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;

View File

@ -1,6 +1,6 @@
package net.Broken.Commands.Over18;
import net.Broken.Tools.Command.NumberedCommande;
import net.Broken.Outils.Command.NumberedCommande;
import org.apache.logging.log4j.LogManager;
/**

View File

@ -1,6 +1,6 @@
package net.Broken.Commands.Over18;
import net.Broken.Tools.Command.NumberedCommande;
import net.Broken.Outils.Command.NumberedCommande;
import org.apache.logging.log4j.LogManager;
/**

View File

@ -1,7 +1,7 @@
package net.Broken.Commands.Over18;
import net.Broken.Commande;
import net.Broken.Tools.Redirection;
import net.Broken.Outils.Redirection;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

View File

@ -1,6 +1,6 @@
package net.Broken.Commands.Over18;
import net.Broken.Tools.Command.NumberedCommande;
import net.Broken.Outils.Command.NumberedCommande;
import org.apache.logging.log4j.LogManager;
/**

View File

@ -1,7 +1,7 @@
package net.Broken.Commands.Over18;
import net.Broken.Commande;
import net.Broken.Tools.Redirection;
import net.Broken.Outils.Redirection;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

View File

@ -2,7 +2,7 @@ package net.Broken.Commands;
import net.Broken.Commande;
import net.Broken.MainBot;
import net.Broken.Tools.MessageTimeOut;
import net.Broken.Outils.MessageTimeOut;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;

View File

@ -2,10 +2,10 @@ package net.Broken.Commands;
import net.Broken.Commande;
import net.Broken.MainBot;
import net.Broken.Tools.AntiSpam;
import net.Broken.Tools.EmbedMessageUtils;
import net.Broken.Tools.MessageTimeOut;
import net.Broken.Tools.UserSpamUtils;
import net.Broken.Outils.AntiSpam;
import net.Broken.Outils.EmbedMessageUtils;
import net.Broken.Outils.MessageTimeOut;
import net.Broken.Outils.UserSpamUtils;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;

View File

@ -2,10 +2,10 @@ package net.Broken.Commands;
import net.Broken.Commande;
import net.Broken.MainBot;
import net.Broken.Tools.EmbedMessageUtils;
import net.Broken.Tools.MessageTimeOut;
import net.Broken.Tools.PrivateMessage;
import net.Broken.Tools.UserSpamUtils;
import net.Broken.Outils.EmbedMessageUtils;
import net.Broken.Outils.MessageTimeOut;
import net.Broken.Outils.PrivateMessage;
import net.Broken.Outils.UserSpamUtils;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.entities.Message;

View File

@ -1,72 +0,0 @@
package net.Broken.DB.Entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class PendingUserEntity {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Integer id;
private String name;
private String jdaId;
private String checkToken;
private String password;
public PendingUserEntity() {
}
public PendingUserEntity(String name, String jdaId, String checkToken, String password) {
this.name = name;
this.jdaId = jdaId;
this.checkToken = checkToken;
this.password = password;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getJdaId() {
return jdaId;
}
public void setJdaId(String jdaId) {
this.jdaId = jdaId;
}
public String getCheckToken() {
return checkToken;
}
public void setCheckToken(String checkToken) {
this.checkToken = checkToken;
}
}

View File

@ -1,71 +0,0 @@
package net.Broken.DB.Entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class UserEntity {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Integer id;
private String name;
private String jdaId;
private String apiToken;
private String password;
public UserEntity() {
}
public UserEntity(PendingUserEntity pendingUserEntity, String apiToken) {
this.name = pendingUserEntity.getName();
this.jdaId = pendingUserEntity.getJdaId();
this.password = pendingUserEntity.getPassword();
this.apiToken = apiToken;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getJdaId() {
return jdaId;
}
public void setJdaId(String jdaId) {
this.jdaId = jdaId;
}
public String getApiToken() {
return apiToken;
}
public void setApiToken(String apiToken) {
this.apiToken = apiToken;
}
}

View File

@ -1,12 +0,0 @@
package net.Broken.DB.Repository;
import net.Broken.DB.Entity.PendingUserEntity;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface PendingUserRepository extends CrudRepository<PendingUserEntity, Integer> {
List<PendingUserEntity> findByJdaId(String jdaId);
}

View File

@ -1,12 +0,0 @@
package net.Broken.DB.Repository;
import net.Broken.DB.Entity.UserEntity;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface UserRepository extends CrudRepository<UserEntity, Integer>{
List<UserEntity> findByName(String name);
List<UserEntity> findByJdaId(String jdaId);
List<UserEntity> findByApiToken(String apiToken);
}

View File

@ -1,7 +1,7 @@
package net.Broken;
import net.Broken.Tools.Command.CommandLoader;
import net.Broken.Tools.DayListener;
import net.Broken.Outils.Command.CommandLoader;
import net.Broken.Outils.DayListener;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;

View File

@ -1,9 +1,8 @@
package net.Broken;
import net.Broken.Tools.Command.CommandParser;
import net.Broken.Tools.EmbedMessageUtils;
import net.Broken.Tools.UserManager.UserRegister;
import net.Broken.Tools.UserSpamUtils;
import net.Broken.Outils.Command.CommandParser;
import net.Broken.Outils.EmbedMessageUtils;
import net.Broken.Outils.UserSpamUtils;
import net.Broken.RestApi.ApiCommandLoader;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.ChannelType;
@ -18,7 +17,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Controller;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.HashMap;
@ -35,12 +33,10 @@ public class MainBot {
public static HashMap<User, Integer> message_compteur =new HashMap<>();
public static boolean roleFlag = false;
public static HashMap<User, UserSpamUtils> spamUtils = new HashMap<>();
public static UserRegister userRegister = new UserRegister();
public static JDA jda;
public static int messageTimeOut = 10;
@ -78,7 +74,6 @@ public class MainBot {
}));
}
ApiCommandLoader.load();

View File

@ -1,7 +1,10 @@
package net.Broken.Tools;
package net.Broken.Outils;
import net.Broken.MainBot;
import net.Broken.Commands.Move;
import net.Broken.Outils.EmbedMessageUtils;
import net.Broken.Outils.MessageTimeOut;
import net.Broken.Outils.UserSpamUtils;
import net.dv8tion.jda.core.entities.*;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.core.exceptions.HierarchyException;

View File

@ -1,4 +1,4 @@
package net.Broken.Tools.Command;
package net.Broken.Outils.Command;
import net.Broken.Commande;
import net.Broken.MainBot;

View File

@ -1,4 +1,4 @@
package net.Broken.Tools.Command;
package net.Broken.Outils.Command;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import org.apache.logging.log4j.LogManager;

View File

@ -1,8 +1,8 @@
package net.Broken.Tools.Command;
package net.Broken.Outils.Command;
import net.Broken.Commande;
import net.Broken.Tools.FindContentOnWebPage;
import net.Broken.Tools.LimitChecker;
import net.Broken.Tools.Redirection;
import net.Broken.Outils.FindContentOnWebPage;
import net.Broken.Outils.LimitChecker;
import net.Broken.Outils.Redirection;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

View File

@ -1,4 +1,4 @@
package net.Broken.Tools;
package net.Broken.Outils;
import net.Broken.Commands.Spam;
import net.dv8tion.jda.core.exceptions.RateLimitedException;
import org.apache.logging.log4j.LogManager;

View File

@ -1,9 +1,10 @@
package net.Broken.Tools;
package net.Broken.Outils;
import net.Broken.MainBot;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import java.awt.*;
@ -68,10 +69,5 @@ public class EmbedMessageUtils {
}
public static MessageEmbed getRegister(String message) {
return new EmbedBuilder().setTitle(":pencil: Web Registration :pencil:").setDescription(message).setColor(Color.green).setFooter("bot.seb6596.ovh", MainBot.jda.getSelfUser().getAvatarUrl()).build();
}
}

View File

@ -1,8 +1,9 @@
package net.Broken.Tools;
package net.Broken.Outils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

View File

@ -1,4 +1,4 @@
package net.Broken.Tools;
package net.Broken.Outils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

View File

@ -1,4 +1,4 @@
package net.Broken.Tools;
package net.Broken.Outils;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.exceptions.ErrorResponseException;

View File

@ -1,5 +1,5 @@
package net.Broken.Tools;
package net.Broken.Outils;
import net.Broken.MainBot;

View File

@ -1,8 +1,10 @@
package net.Broken.Tools;
package net.Broken.Outils;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.entities.PrivateChannel;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.exceptions.RateLimitedException;
import org.apache.logging.log4j.Logger;
/**

View File

@ -1,4 +1,4 @@
package net.Broken.Tools;
package net.Broken.Outils;
import java.io.IOException;
import java.io.InputStream;

View File

@ -1,4 +1,4 @@
package net.Broken.Tools;
package net.Broken.Outils;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;

View File

@ -7,6 +7,4 @@ public class CommandPostData {
public String url;
public int playlistLimit;
public String chanelId;
public String name;
public String token;
}

View File

@ -6,16 +6,9 @@ import com.fasterxml.jackson.annotation.JsonInclude;
public class CommandResponseData {
public String Commande;
public String Message;
public String error;
public CommandResponseData(String commande, String message) {
Commande = commande;
Message = message;
}
public CommandResponseData(String commande, String message, String error) {
Commande = commande;
Message = message;
this.error = error;
}
}

View File

@ -1,15 +0,0 @@
package net.Broken.RestApi.Data.UserManager;
public class CheckResposeData {
public boolean accepted;
public String name;
public String message;
public String id;
public CheckResposeData(boolean accepted, String name, String message, String id) {
this.accepted = accepted;
this.name = name;
this.message = message;
this.id = id;
}
}

View File

@ -1,7 +0,0 @@
package net.Broken.RestApi.Data.UserManager;
public class ConfirmData {
public String id;
public String checkToken;
}

View File

@ -1,25 +0,0 @@
package net.Broken.RestApi.Data.UserManager;
public class UserConnectionData {
public boolean accepted;
public String token;
public String message;
public String error;
public String name;
public UserConnectionData(boolean accepted, String name, String token, String message) {
this.accepted = accepted;
this.token = token;
this.message = message;
this.name = name;
this.error = null;
}
public UserConnectionData(boolean accepted, String message, String error) {
this.accepted = accepted;
this.token = null;
this.message = message;
this.error = error;
this.name = null;
}
}

View File

@ -1,6 +0,0 @@
package net.Broken.RestApi.Data.UserManager;
public class UserInfoData {
public String name;
public String password;
}

View File

@ -4,33 +4,24 @@ import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import net.Broken.Commands.Music;
import net.Broken.DB.Entity.UserEntity;
import net.Broken.DB.Repository.UserRepository;
import net.Broken.MainBot;
import net.Broken.RestApi.Data.*;
import net.Broken.RestApi.Data.UserManager.CheckResposeData;
import net.Broken.RestApi.Data.UserManager.UserInfoData;
import net.Broken.Tools.UserManager.Exceptions.UnknownTokenException;
import net.Broken.Tools.UserManager.Exceptions.UserNotFoundException;
import net.Broken.audio.NotConectedException;
import net.Broken.audio.NullMusicManager;
import net.dv8tion.jda.core.entities.VoiceChannel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
// import net.Broken.DB.Repository.SavedPlaylistRepository;
// import net.Broken.DB.SavedPlaylistRepository;
@RestController
@RequestMapping("/api/music/")
@ -38,9 +29,6 @@ public class MusicWebAPIController {
Logger logger = LogManager.getLogger();
// @Autowired
// public SavedPlaylistRepository savedPlaylist;
@Autowired
UserRepository userRepository;
@RequestMapping("/currentMusicInfo")
public CurrentMusicData getCurrentM(){
@ -77,32 +65,17 @@ public class MusicWebAPIController {
}
@RequestMapping(value = "/command", method = RequestMethod.POST)
public ResponseEntity<CommandResponseData> command(@RequestBody CommandPostData data, HttpServletRequest request){
public ResponseEntity<CommandResponseData> command(@RequestBody CommandPostData data){
if(data.command != null) {
if(data.token != null) {
try {
UserEntity user = MainBot.userRegister.getUserWithApiToken(userRepository, data.token);
logger.info("receive command " + data.command + " from " + request.getRemoteAddr() + " USER: " + user.getName());
logger.info("receive command: " + data.command);
Music musicCommande = (Music) MainBot.commandes.get("music");
if (ApiCommandLoader.apiCommands.containsKey(data.command))
return ApiCommandLoader.apiCommands.get(data.command).action(musicCommande, data);
if(ApiCommandLoader.apiCommands.containsKey(data.command))
return ApiCommandLoader.apiCommands.get(data.command).action(musicCommande,data);
else
return new ResponseEntity<>(new CommandResponseData(data.command, "Unknown Command", "command"), HttpStatus.BAD_REQUEST);
return new ResponseEntity<>(new CommandResponseData(data.command,"Unknown Command"), HttpStatus.BAD_REQUEST);
} catch (UnknownTokenException e) {
logger.warn("Command with unknown token from: "+request.getRemoteAddr());
return new ResponseEntity<>(new CommandResponseData(data.command,"Unknown Token!\nPlease Re-connect.", "token"), HttpStatus.UNAUTHORIZED);
}
}
else{
logger.warn("Command without token! ip: "+ request.getRemoteAddr());
return new ResponseEntity<>(new CommandResponseData(data.command,"Missing token!\nPlease Re-connect.","token"), HttpStatus.UNAUTHORIZED);
}
}
else
logger.info("Null");
@ -112,6 +85,7 @@ public class MusicWebAPIController {
@RequestMapping(value = "/getChanel", method = RequestMethod.GET)
public List<Chanel> getChanel(){
List<Chanel> temp = new ArrayList<>();
logger.info(MainBot.jda.getVoiceChannels().size());
for(VoiceChannel aChanel : MainBot.jda.getVoiceChannels()){
temp.add(new Chanel(aChanel.getName(),aChanel.getId(),aChanel.getPosition()));
}
@ -121,7 +95,6 @@ public class MusicWebAPIController {
// DB Test Ignore it
// @RequestMapping(value = "/test", method = RequestMethod.GET)

View File

@ -1,95 +0,0 @@
package net.Broken.RestApi;
import net.Broken.DB.Entity.PendingUserEntity;
import net.Broken.DB.Entity.UserEntity;
import net.Broken.DB.Repository.PendingUserRepository;
import net.Broken.DB.Repository.UserRepository;
import net.Broken.MainBot;
import net.Broken.RestApi.Data.UserManager.CheckResposeData;
import net.Broken.RestApi.Data.UserManager.ConfirmData;
import net.Broken.RestApi.Data.UserManager.UserConnectionData;
import net.Broken.RestApi.Data.UserManager.UserInfoData;
import net.Broken.Tools.UserManager.Exceptions.PasswordNotMatchException;
import net.Broken.Tools.UserManager.Exceptions.TokenNotMatch;
import net.Broken.Tools.UserManager.Exceptions.UserAlreadyRegistered;
import net.Broken.Tools.UserManager.Exceptions.UserNotFoundException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/userManagement")
public class UserManagerAPIController {
Logger logger = LogManager.getLogger();
@Autowired
PendingUserRepository pendingUserRepository;
@Autowired
UserRepository userRepository;
@Autowired
private PasswordEncoder passwordEncoder;
@RequestMapping(value = "/preRegister", method = RequestMethod.POST)
public ResponseEntity<CheckResposeData> command(@RequestBody UserInfoData data){
if(data != null && data.name != null) {
try {
String id = MainBot.userRegister.sendCheckToken(pendingUserRepository, userRepository, passwordEncoder, data);
return new ResponseEntity<>(new CheckResposeData(true, data.name, "Message sent", id), HttpStatus.OK);
} catch (UserNotFoundException e) {
logger.warn("User \"" + data.name + "\" not found!");
return new ResponseEntity<>(new CheckResposeData(false, data.name, "User not found on server!",""), HttpStatus.NOT_FOUND);
} catch (PasswordNotMatchException userAlreadyRegistered) {
return new ResponseEntity<>(new CheckResposeData(false, data.name, "User already registered in pending database and password not match!",""), HttpStatus.NOT_ACCEPTABLE);
} catch (UserAlreadyRegistered userAlreadyRegistered) {
return new ResponseEntity<>(new CheckResposeData(false, data.name, "User already registered in database!",""), HttpStatus.NOT_ACCEPTABLE);
}
}
else{
return new ResponseEntity<>(new CheckResposeData(false, "", "Missing parameter(s)",""), HttpStatus.BAD_REQUEST);
}
}
@RequestMapping(value = "/confirmAccount", method = RequestMethod.POST)
public ResponseEntity<UserConnectionData> confirAccount(@RequestBody ConfirmData data){
//TODO move pending user to accepted and return right things
try {
PendingUserEntity pUser = MainBot.userRegister.confirmCheckToken(pendingUserRepository, Integer.parseInt(data.id), data.checkToken);
UserEntity user = new UserEntity(pUser, MainBot.userRegister.generateApiToken());
userRepository.save(user);
pendingUserRepository.delete(pUser);
return new ResponseEntity<>(new UserConnectionData(true, user.getName(), user.getApiToken(),""),HttpStatus.OK);
} catch (TokenNotMatch tokenNotMatch) {
logger.warn("Pre token not match for "+data.id+"!");
return new ResponseEntity<>(new UserConnectionData(false,"Token not match!","token"),HttpStatus.NOT_ACCEPTABLE);
} catch (UserNotFoundException e) {
logger.warn("Id not found in DB ("+data.id+")");
return new ResponseEntity<>(new UserConnectionData(false,"User not found on DB!", "user"),HttpStatus.NOT_ACCEPTABLE);
}
}
@RequestMapping(value = "/requestToken", method = RequestMethod.POST)
public ResponseEntity<UserConnectionData> requestToken(@RequestBody UserInfoData data){
try {
UserEntity user = MainBot.userRegister.getUser(userRepository, passwordEncoder, data);
return new ResponseEntity<>(new UserConnectionData(true, user.getName(), user.getApiToken(), ""), HttpStatus.OK);
} catch (UserNotFoundException e) {
return new ResponseEntity<>(new UserConnectionData(false,"User not registered!", "user"),HttpStatus.NOT_ACCEPTABLE);
} catch (PasswordNotMatchException e) {
return new ResponseEntity<>(new UserConnectionData(false,"Wrong user name or password!", "password"),HttpStatus.NOT_ACCEPTABLE);
}
}
}

View File

@ -1,40 +0,0 @@
package net.Broken.Tools;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
public class ResourceLoader {
private Logger logger = LogManager.getLogger();
public String getFile(String fileName) {
StringBuilder result = new StringBuilder("");
//Get file from resources folder
ClassLoader classLoader = getClass().getClassLoader();
InputStream file = classLoader.getResourceAsStream(fileName);
try (Scanner scanner = new Scanner(file, "UTF-8")) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
result.append(line).append("\n");
}
scanner.close();
}
return result.toString();
}
}

View File

@ -1,4 +0,0 @@
package net.Broken.Tools.UserManager.Exceptions;
public class PasswordNotMatchException extends Exception{
}

View File

@ -1,4 +0,0 @@
package net.Broken.Tools.UserManager.Exceptions;
public class TokenNotMatch extends Exception {
}

View File

@ -1,4 +0,0 @@
package net.Broken.Tools.UserManager.Exceptions;
public class UnknownTokenException extends Exception{
}

View File

@ -1,4 +0,0 @@
package net.Broken.Tools.UserManager.Exceptions;
public class UserAlreadyRegistered extends Exception {
}

View File

@ -1,4 +0,0 @@
package net.Broken.Tools.UserManager.Exceptions;
public class UserNotFoundException extends Exception{
}

View File

@ -1,14 +0,0 @@
package net.Broken.Tools.UserManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
@Configuration
public class PasswordUtils {
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}

View File

@ -1,151 +0,0 @@
package net.Broken.Tools.UserManager;
import net.Broken.DB.Entity.PendingUserEntity;
import net.Broken.DB.Entity.UserEntity;
import net.Broken.DB.Repository.PendingUserRepository;
import net.Broken.DB.Repository.UserRepository;
import net.Broken.MainBot;
import net.Broken.RestApi.Data.UserManager.UserInfoData;
import net.Broken.Tools.EmbedMessageUtils;
import net.Broken.Tools.PrivateMessage;
import net.Broken.Tools.ResourceLoader;
import net.Broken.Tools.UserManager.Exceptions.*;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.entities.User;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.password.PasswordEncoder;
import java.security.SecureRandom;
import java.util.List;
import java.util.UUID;
public class UserRegister {
private Logger logger = LogManager.getLogger();
public String sendCheckToken(PendingUserRepository pendingUserRepository, UserRepository userRepository, PasswordEncoder passwordEncoder, UserInfoData userInfo) throws UserNotFoundException, PasswordNotMatchException, UserAlreadyRegistered {
logger.info("New registration for " + userInfo.name);
List<User> users = MainBot.jda.getUsersByName(userInfo.name,true);
if(users.size() < 1)
throw new UserNotFoundException();
User user = users.get(0);
logger.info("User found!");
PendingUserEntity pendingUserEntity = null;
String token = "";
//Test if exist on register user
if(userRepository.findByJdaId(user.getId()).size() > 0){
logger.warn("User already registered!");
throw new UserAlreadyRegistered();
}
//Check if exist in pading user Table
List<PendingUserEntity> pendingUsers = pendingUserRepository.findByJdaId(user.getId());
if(pendingUsers.size() != 0){
PendingUserEntity thisUser = pendingUsers.get(0);
if(passwordEncoder.matches(userInfo.password, thisUser.getPassword())){
logger.info("Password matches");
pendingUserEntity = thisUser;
token = thisUser.getCheckToken();
}else{
logger.warn("Password Not Match!");
throw new PasswordNotMatchException();
}
}
logger.info("Generating check Token...");
if(token.equals("")){
token = generateCheckToken();
}
logger.info("Token generated: " + token);
if(pendingUserEntity == null) {
pendingUserEntity = new PendingUserEntity(user.getName(), user.getId(), token, passwordEncoder.encode(userInfo.password));
pendingUserEntity = pendingUserRepository.save(pendingUserEntity);
}
String message = new ResourceLoader().getFile("MessagesTemplates/RegisterMessage.md");
message = message.replace("%code",token);
MessageEmbed ebM = EmbedMessageUtils.getRegister(message);
PrivateMessage.send(user,ebM,logger);
return pendingUserEntity.getId().toString();
}
public PendingUserEntity confirmCheckToken(PendingUserRepository pendingUserRepository, int id, String checkToken ) throws TokenNotMatch, UserNotFoundException {
PendingUserEntity pendingUser = pendingUserRepository.findOne(id);
if(pendingUser != null) {
if(pendingUser.getCheckToken().equals(checkToken)){
logger.info("Check Token match!");
}
else{
logger.warn("Check token not match!");
throw new TokenNotMatch();
}
}
else{
logger.warn("Id not Found!");
throw new UserNotFoundException();
}
return pendingUser;
}
public UserEntity getUser(UserRepository userRepository, PasswordEncoder passwordEncoder, UserInfoData userInfoData) throws UserNotFoundException, PasswordNotMatchException {
List<UserEntity> users = userRepository.findByName(userInfoData.name);
if(users.size()<1){
logger.warn("Login with unknown username: " + userInfoData.name);
throw new UserNotFoundException();
}
else{
UserEntity user = users.get(0);
if(passwordEncoder.matches(userInfoData.password,user.getPassword())){
logger.info("Login successful for " + user.getName());
return user;
}
else
{
logger.warn("Login fail for " + user.getName() + ", wrong password!");
throw new PasswordNotMatchException();
}
}
}
public UserEntity getUserWithApiToken(UserRepository userRepository, String token) throws UnknownTokenException {
List<UserEntity> users = userRepository.findByApiToken(token);
if(users.size() > 0){
return users.get(0);
}
else
throw new UnknownTokenException();
}
public String generateApiToken(){
return UUID.randomUUID().toString();
}
private String generateCheckToken(){
SecureRandom random = new SecureRandom();
long longToken = Math.abs( random.nextLong() );
String randomStr = Long.toString( longToken, 16 );
randomStr = randomStr.substring(0,4);
randomStr = randomStr.toUpperCase();
return randomStr;
}
}

View File

@ -9,13 +9,15 @@ import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import net.Broken.MainBot;
import net.Broken.Tools.EmbedMessageUtils;
import net.Broken.Tools.MessageTimeOut;
import net.Broken.Outils.EmbedMessageUtils;
import net.Broken.Outils.MessageTimeOut;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.core.events.guild.voice.GuildVoiceLeaveEvent;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.core.managers.AudioManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

View File

@ -1,16 +0,0 @@
package net.Broken.webView;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class ResisterWebView {
@RequestMapping("/register")
public String music(@RequestParam(value="id", required = true, defaultValue = "") String id, Model model){
model.addAttribute("id", id);
return "register";
}
}

View File

@ -1,5 +0,0 @@
Une tentative d'association à etait demandé.
Voici le code de vérification:
**%code**

View File

@ -1,6 +1 @@
server.port=${PORT}
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=${DB_URL}
spring.datasource.username=${DB_USER}
spring.datasource.password=${DB_PWD}
spring.thymeleaf.cache=true

View File

@ -7,29 +7,23 @@
<Pattern>[%d{HH:mm:ss.SSS}]%highlight{[%-5level]}{FATAL=red blink, ERROR=red, WARN=bright yellow , INFO=blue, DEBUG=bright black, TRACE=cyan}[%-30.30c{1.}]: %highlight{%msg%n}{FATAL=red blink, ERROR=red, WARN=bright yellow , INFO=blue, DEBUG=bright black, TRACE=cyan}</Pattern>
</PatternLayout>
</Console>
<RollingFile name="RollingFile" fileName="./logs/current-day.log"
filePattern="./logs/$${date:yyyy-MM}/discordBot-%d{yyyy-MM-dd}-%i.log.gz">
<RollingFile name="RollingFile" fileName="./logs/curent.log"
filePattern="./logs/$${date:yyyy-MM}/discordBot-%d{yyyy-MM-dd-HH}-%i.log.gz">
<PatternLayout>
<Pattern>[%d{HH:mm:ss.SSS}]%highlight{[%-5level]}{FATAL=red blink, ERROR=red, WARN=bright yellow , INFO=blue, DEBUG=bright black, TRACE=cyan}[%-30.30c{1.}]: %highlight{%msg%n}{FATAL=red blink, ERROR=red, WARN=bright yellow , INFO=blue, DEBUG=bright black, TRACE=cyan}</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<TimeBasedTriggeringPolicy interval="1"/>
<SizeBasedTriggeringPolicy size="250 MB"/>
</Policies>
<DefaultRolloverStrategy max="120"/>
</RollingFile>
<File name="current" fileName="logs/current.log" append="false">
<PatternLayout>
<Pattern>[%d{HH:mm:ss.SSS}]%highlight{[%-5level]}{FATAL=red blink, ERROR=red, WARN=bright yellow , INFO=blue, DEBUG=bright black, TRACE=cyan}[%-30.30c{1.}]: %highlight{%msg%n}{FATAL=red blink, ERROR=red, WARN=bright yellow , INFO=blue, DEBUG=bright black, TRACE=cyan}</Pattern>
</PatternLayout>
</File>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="RollingFile" level="info" />
<AppenderRef ref="Console" level="info"/>
<AppenderRef ref="RollingFile" level="info"/>
<AppenderRef ref="current" level="info"/>
</Root>
</Loggers>
</Configuration>

View File

@ -1,8 +1,8 @@
/*.nav-wrapper{*/
/*!*margin-right: 1%;*!*/
/*margin-left: 1%;*/
/*width: 100%;*/
/*}*/
.nav-wrapper{
margin-right: 1%;
margin-left: 1%;
width: 100%;
}
.collapsible-body{

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -4,9 +4,6 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0"/>
<title>Discord Bot</title>
<link rel="icon"
type="image/x-icon"
href="favicon.png"/>
<!-- CSS -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/>
@ -15,109 +12,32 @@
</head>
<body class="blue-grey lighten-5" >
<!--__________________________________________________________-->
<!-- NAV BAR -->
<!-- AND -->
<!-- LOGIN -->
<!--__________________________________________________________-->
<nav class="blue-grey darken-4 z-depth-3" role="navigation">
<div class="nav-wrapper container">
<a id="logo-container" href="/" class="brand-logo">Discord Bot</a>
<a id="logo-container" href="#" class="brand-logo">Discord Bot</a>
<ul class="right hide-on-med-and-down">
<li class="active">
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
<a href="/" data-target="slide-out" class="sidenav-trigger">Home</a>
</li>
<li>
<a class="waves-effect waves-light" href="/music" >Music Control</a>
<a href="/music" >Music Control</a>
</li>
<li id="nav-bar-account">
<a class="dropdown-account" data-activates="dropdown1"><i class="material-icons">account_box</i></a>
</li>
</ul>
<ul id="nav-mobile" class="side-nav">
<li class="active">
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
<a href="/" data-target="slide-out" class="sidenav-trigger">Home</a>
</li>
<li>
<a class="waves-effect waves-light sidenav-trigger" href="/music" data-target="slide-out" >Music Control</a>
<a href="/music" data-target="slide-out" class="sidenav-trigger">Music Control</a>
</li>
</ul>
<a href="#" data-activates="nav-mobile" class="button-navbar-mobile button-collapse"><i class="material-icons">menu</i></a>
<a href="#" data-activates="nav-mobile" class="button-collapse-1 button-collapse"><i class="material-icons">menu</i></a>
</div>
</nav>
<!-- Dropdown connected -->
<ul id="dropdown_connected" class="dropdown-content ">
<li>
<a class="center blue-grey-text text-darken-4" id="nav-name" style="text-decoration: underline; font-weight: bold"></a>
</li>
<li class="divider"></li>
<li>
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Account</a>
</li>
<li>
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Playlists</a>
</li>
<li class="divider"></li>
<li><a class="center red-text" id="nav-disconnect" style="font-weight: bold">Disconnect</a></li>
</ul>
<!--________________________________________-->
<!-- Connection modal -->
<!--________________________________________-->
<div id="modal_connection" class="modal">
<div class="modal-content">
<div class="row center">
<div class="col s12">
<h3 class="" style="font-weight: bold">Sign in</h3>
</div>
</div>
<div class="row center" style="margin-bottom: 0px">
<form name="login_form" id="login_form" action="javascript:void(0);" onsubmit="tryConnection()">
<div class="row" style="margin-bottom: 0px">
<div class="input-field col s6 offset-s3">
<i class="material-icons prefix">account_box</i>
<input name="username" id="user_input" type="text" class="validate"/>
<label for="user_input" data-error="User not registered!">User Name</label>
</div>
</div>
<div class="row">
<div class="input-field col s6 offset-s3">
<i class="material-icons prefix">security</i>
<input name="password" id="password_input" type="password" class="validate"/>
<label for="password_input" data-error="Wrong password!">Password</label>
</div>
</div>
<div class="row" style="margin-bottom: 10px">
<button id="btn-submit-connect" class="btn waves-effect waves-light light-green darken-1 scale-transition scale-out" type="submit" name="action" >
Submit<i class="material-icons right">send</i>
</button>
</div>
<div class="row">
<a class="btn waves-effect waves-light brown" href="/register">
Create account<i class="material-icons right">person_add</i>
</a>
</div>
</form>
</div>
</div>
</div>
<!--__________________________________________________________-->
<!-- -->
<!-- END -->
<!-- -->
<!--__________________________________________________________-->
<div class="section no-pad-bot main" id="index-banner">
</div>
@ -125,8 +45,14 @@
<!-- Scripts-->
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="js/materialize.js"></script>
<script src="js/navabar.js"></script>
<script src="js/js.cookie.js"></script>
<script>
$('.button-collapse-1').sideNav({
menuWidth: 400, // Default is 300
edge: 'right', // Choose the horizontal origin
closeOnClick: false, // Closes side-nav on <a> clicks, useful for Angular/Meteor
draggable: true // Choose whether you can drag to open on touch screens,
});
</script>
<!--<script src="js/init.js"></script>-->
</body>

View File

@ -25,14 +25,12 @@ $(document).ready(function() {
$('#btn_play').click(function () {
switch (state){
case "PLAYING":
sendCommand({ command: "PAUSE"})
sendCommand(JSON.stringify({ command: "PAUSE"}))
break;
case "PAUSE":
sendCommand({ command: "PLAY"})
sendCommand(JSON.stringify({ command: "PLAY"}))
break;
default:
sendCommand({command: "PLAY"})
}
});
@ -40,10 +38,10 @@ $(document).ready(function() {
$('#btn_next').click(function () {
sendCommand({ command: "NEXT"});
sendCommand(JSON.stringify({ command: "NEXT"}));
});
$('#btn_stop').click(function () {
sendCommand({ command: "STOP"});
sendCommand(JSON.stringify({ command: "STOP"}));
});
$('.dropdown-button').dropdown({
@ -87,7 +85,7 @@ $(document).ready(function() {
var command = {
command: "FLUSH"
};
sendCommand(command);
sendCommand(JSON.stringify(command));
});
$('#btn_add_top').click(function () {
@ -98,7 +96,7 @@ $(document).ready(function() {
onHead: true
};
$('#input_link').val('');
sendCommand(command);
sendCommand(JSON.stringify(command));
});
$('#btn_add_bottom').click(function () {
@ -110,7 +108,7 @@ $(document).ready(function() {
onHead: false
};
$('#input_link').val('');
sendCommand(command);
sendCommand(JSON.stringify(command));
});
$('#btn_ok_channel').click(function () {
@ -119,7 +117,7 @@ $(document).ready(function() {
command: "CONNECT",
chanelId: $('input[name=vocalRadio]:checked').val()
};
sendCommand(command);
sendCommand(JSON.stringify(command));
});
})
@ -146,7 +144,8 @@ function getCurentMusic() {
$('#btn_info').addClass("determinate").removeClass("indeterminate");
}
$('#music_progress').width("0%");
if(Cookies.get('token') != undefined){
$('#btn_play').children().text("play_arrow");
if (!$('#btn_stop').hasClass("disabled")) {
$('#btn_stop').addClass("disabled");
}
@ -166,30 +165,6 @@ function getCurentMusic() {
if ($('#btn_next').hasClass("disabled")) {
$('#btn_next').removeClass("disabled");
}
}
else{
if (!$('#btn_stop').hasClass("disabled")) {
$('#btn_stop').addClass("disabled");
}
if (!$('#btn_info').hasClass("disabled")) {
$('#btn_info').addClass("disabled");
}
if (!$('#add_btn').hasClass("disabled")) {
$('#add_btn').addClass("disabled");
}
if (!$('#flush_btn').hasClass("disabled")) {
$('#flush_btn').addClass("disabled");
}
if (!$('#btn_play').hasClass("disabled")) {
$('#btn_play').addClass("disabled");
}
if (!$('#btn_next').hasClass("disabled")) {
$('#btn_next').addClass("disabled");
}
}
$('#btn_play').children().text("play_arrow");
$('#music_img').attr("src","/img/no_music.jpg");
$('#total_time').text("00:00");
@ -231,7 +206,6 @@ function getCurentMusic() {
$('#music_progress').width("0%");
$('#btn_play').children().text("play_arrow");
if (!$('#btn_play').hasClass("disabled")) {
$('#btn_play').addClass("disabled");
}
@ -253,13 +227,11 @@ function getCurentMusic() {
$('#music_img').attr("src","/img/disconnected.png");
if(Cookies.get('token') != undefined){
if(!disconected){
getChannels();
disconected = true;
}
}
@ -306,7 +278,7 @@ function getPlayList() {
command: "DELL",
url: $(this).attr("data_url")
};
sendCommand(command);
sendCommand(JSON.stringify(command));
});
@ -362,12 +334,11 @@ function updateControl(data){
$('#music_text').text(data.info.title);
var percent = (data.currentPos / data.info.length) * 100;
// console.log(percent)
if (!$('#music_progress').hasClass("indeterminate")) {
$('#music_progress').addClass("determinate").removeClass("indeterminate");
if (!$('#btn_info').hasClass("indeterminate")) {
$('#btn_info').addClass("determinate").removeClass("indeterminate");
}
$('#music_progress').width(percent + "%");
if(Cookies.get('token') != undefined){
if ($('#btn_play').hasClass("disabled")) {
$('#btn_play').removeClass("disabled");
}
@ -387,30 +358,6 @@ function updateControl(data){
if ($('#btn_next').hasClass("disabled")) {
$('#btn_next').removeClass("disabled");
}
}
else
{
if (!$('#btn_play').hasClass("disabled")) {
$('#btn_play').addClass("disabled");
}
if (!$('#btn_stop').hasClass("disabled")) {
$('#btn_stop').addClass("disabled");
}
if (!$('#btn_info').hasClass("disabled")) {
$('#btn_info').addClass("disabled");
}
if (!$('#add_btn').hasClass("disabled")) {
$('#add_btn').addClass("disabled");
}
if (!$('#flush_btn').hasClass("disabled")) {
$('#flush_btn').addClass("disabled");
}
if (!$('#btn_next').hasClass("disabled")) {
$('#btn_next').addClass("disabled");
}
}
$('#music_img').attr("src","https://img.youtube.com/vi/"+data.info.identifier+"/hqdefault.jpg");
// console.log(data);
@ -419,15 +366,13 @@ function updateControl(data){
updateModal(data);
}
function sendCommand(command){
command["token"] = Cookies.get('token');
console.log(command)
function sendCommand(commandStr){
$.ajax({
type: "POST",
dataType: 'json',
contentType: 'application/json',
url: "/api/music/command",
data: JSON.stringify(command),
data: commandStr,
success: function (data) {
console.log(data);
}
@ -435,11 +380,6 @@ function sendCommand(command){
}).fail(function (data) {
console.log(data);
alert(data.responseJSON.Message);
if(data.responseJSON.error === "token"){
Cookies.remove('token');
Cookies.remove('name');
location.reload();
}
});
}

View File

@ -1,165 +0,0 @@
/*!
* JavaScript Cookie v2.2.0
* https://github.com/js-cookie/js-cookie
*
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack
* Released under the MIT license
*/
;(function (factory) {
var registeredInModuleLoader = false;
if (typeof define === 'function' && define.amd) {
define(factory);
registeredInModuleLoader = true;
}
if (typeof exports === 'object') {
module.exports = factory();
registeredInModuleLoader = true;
}
if (!registeredInModuleLoader) {
var OldCookies = window.Cookies;
var api = window.Cookies = factory();
api.noConflict = function () {
window.Cookies = OldCookies;
return api;
};
}
}(function () {
function extend () {
var i = 0;
var result = {};
for (; i < arguments.length; i++) {
var attributes = arguments[ i ];
for (var key in attributes) {
result[key] = attributes[key];
}
}
return result;
}
function init (converter) {
function api (key, value, attributes) {
var result;
if (typeof document === 'undefined') {
return;
}
// Write
if (arguments.length > 1) {
attributes = extend({
path: '/'
}, api.defaults, attributes);
if (typeof attributes.expires === 'number') {
var expires = new Date();
expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
attributes.expires = expires;
}
// We're using "expires" because "max-age" is not supported by IE
attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
try {
result = JSON.stringify(value);
if (/^[\{\[]/.test(result)) {
value = result;
}
} catch (e) {}
if (!converter.write) {
value = encodeURIComponent(String(value))
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
} else {
value = converter.write(value, key);
}
key = encodeURIComponent(String(key));
key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
key = key.replace(/[\(\)]/g, escape);
var stringifiedAttributes = '';
for (var attributeName in attributes) {
if (!attributes[attributeName]) {
continue;
}
stringifiedAttributes += '; ' + attributeName;
if (attributes[attributeName] === true) {
continue;
}
stringifiedAttributes += '=' + attributes[attributeName];
}
return (document.cookie = key + '=' + value + stringifiedAttributes);
}
// Read
if (!key) {
result = {};
}
// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all. Also prevents odd result when
// calling "get()"
var cookies = document.cookie ? document.cookie.split('; ') : [];
var rdecode = /(%[0-9A-Z]{2})+/g;
var i = 0;
for (; i < cookies.length; i++) {
var parts = cookies[i].split('=');
var cookie = parts.slice(1).join('=');
if (!this.json && cookie.charAt(0) === '"') {
cookie = cookie.slice(1, -1);
}
try {
var name = parts[0].replace(rdecode, decodeURIComponent);
cookie = converter.read ?
converter.read(cookie, name) : converter(cookie, name) ||
cookie.replace(rdecode, decodeURIComponent);
if (this.json) {
try {
cookie = JSON.parse(cookie);
} catch (e) {}
}
if (key === name) {
result = cookie;
break;
}
if (!key) {
result[name] = cookie;
}
} catch (e) {}
}
return result;
}
api.set = api;
api.get = function (key) {
return api.call(api, key);
};
api.getJSON = function () {
return api.apply({
json: true
}, [].slice.call(arguments));
};
api.defaults = {};
api.remove = function (key, attributes) {
api(key, '', extend(attributes, {
expires: -1
}));
};
api.withConverter = init;
return api;
}
return init(function () {});
}));

View File

@ -1,138 +0,0 @@
var nav_bar_account_link;
var connected_link = "<a class=\"dropdown-account\" data-activates=\"dropdown_connected\"><i class=\"material-icons green-text\">account_box</i></a>";
var disconnected_link = "<a class=\"waves-effect waves-light modal-trigger\" href=\"#modal_connection\"><i class=\"material-icons red-text\">account_box</i></a>";
var input_name;
var input_psw;
var btn_submit;
var btn_disconnect;
var nav_name;
$(document).ready(function() {
$('.button-navbar-mobile').sideNav({
menuWidth: 400, // Default is 300
edge: 'right', // Choose the horizontal origin
closeOnClick: false, // Closes side-nav on <a> clicks, useful for Angular/Meteor
draggable: true // Choose whether you can drag to open on touch screens,
});
nav_bar_account_link = $("#nav-bar-account");
input_name = $("#user_input");
input_psw = $("#password_input");
btn_submit = $("#btn-submit-connect");
btn_disconnect = $("#nav-disconnect");
nav_name = $("#nav-name");
if(Cookies.get('token') === undefined){
disconnected()
}
else{
connected();
}
listeners();
});
function popOutSubmit(){
if (btn_submit.hasClass("scale-in")) {
btn_submit.removeClass("scale-in");
btn_submit.addClass("scale-out");
}
}
function popInSubmit(){
if (btn_submit.hasClass("scale-out")) {
btn_submit.removeClass("scale-out");
btn_submit.addClass("scale-in");
}
}
function connected(){
console.log("Connected!");
nav_bar_account_link.html(connected_link);
$('.dropdown-account').dropdown({
constrainWidth: false, // Does not change width of dropdown to that of the activator
belowOrigin: true, // Displays dropdown below the button
alignment: 'left', // Displays dropdown with edge aligned to the left of button
stopPropagation: false // Stops event propagation
}
);
nav_name.text(Cookies.get('name'));
}
function disconnected() {
console.log("Disconnected");
nav_bar_account_link.html(disconnected_link);
var modalConnection = $('#modal_connection');
modalConnection.modal();
if (typeof needLogin !== 'undefined'){
modalConnection.modal('open');
}
}
function tryConnection() {
var request = { name: input_name.val(), password: input_psw.val()};
$.ajax({
type: "POST",
dataType: 'json',
contentType: 'application/json',
url: "/api/userManagement/requestToken",
data: JSON.stringify(request),
success: function (data) {
console.log(data);
Cookies.set('token',data.token);
Cookies.set('name', data.name);
debugger;
location.reload();
}
}).fail(function (data) {
console.log(data);
switch(data.responseJSON.error){
case "user":
input_name.addClass("invalid");
break;
case "password":
input_psw.addClass("invalid");
break;
}
});
return true;
}
function listeners() {
input_name.on("input", function () {
if(input_name.val() !== "" && input_psw.val() !== "") {
popInSubmit();
}else
{
popOutSubmit();
}
});
input_psw.on("input", function () {
if(input_name.val() !== "" && input_psw.val() !== "") {
popInSubmit();
}else
{
popOutSubmit();
}
});
btn_disconnect.click(function () {
Cookies.remove('token');
Cookies.remove('name');
location.reload();
});
}

View File

@ -1,176 +0,0 @@
var ok_passwrd = false;
$(document).ready(function() {
var baseUrl = window.location.protocol + "//" +window.location.host + window.location.pathname;
console.log(baseUrl);
$('.button-collapse-1').sideNav({
menuWidth: 400, // Default is 300
edge: 'right', // Choose the horizontal origin
closeOnClick: false, // Closes side-nav on <a> clicks, useful for Angular/Meteor
draggable: true // Choose whether you can drag to open on touch screens,
});
var sendBtn = $('#sendBtn');
$('#name').on("input", function () {
if($('#name').val() === ""){
if (sendBtn.hasClass("scale-in")) {
sendBtn.removeClass("scale-in");
sendBtn.addClass("scale-out");
}
}
else{
if (sendBtn.hasClass("scale-out") && ok_passwrd) {
sendBtn.removeClass("scale-out");
sendBtn.addClass("scale-in");
}
}
});
var passwrd = $('#passwrd');
var confirm = $('#passwrd2');
passwrd.on("input", function () {
if((passwrd.val() === confirm.val())&& passwrd.val() !== ''){
if (passwrd.hasClass("invalid")) {
passwrd.addClass("valid");
passwrd.removeClass("invalid");
confirm.addClass("valid");
confirm.removeClass("invalid");
}
if($('#name').val() !== ""){
if (sendBtn.hasClass("scale-out")) {
sendBtn.removeClass("scale-out");
sendBtn.addClass("scale-in");
}
}
ok_passwrd = true;
}
else{
if (!passwrd.hasClass("invalid")) {
passwrd.addClass("invalid");
passwrd.removeClass("valid");
confirm.addClass("invalid");
confirm.removeClass("valid");
}
if (sendBtn.hasClass("scale-in")) {
sendBtn.removeClass("scale-in");
sendBtn.addClass("scale-out");
}
ok_passwrd = false;
}
});
confirm.on("input", function () {
if((passwrd.val() === confirm.val())&& passwrd.val() !== ''){
if (passwrd.hasClass("invalid")) {
passwrd.addClass("valid");
passwrd.removeClass("invalid");
confirm.addClass("valid");
confirm.removeClass("invalid");
}
if($('#name').val() !== ""){
if (sendBtn.hasClass("scale-out")) {
sendBtn.removeClass("scale-out");
sendBtn.addClass("scale-in");
}
}
ok_passwrd = true;
}
else{
if (!passwrd.hasClass("invalid")) {
passwrd.addClass("invalid");
passwrd.removeClass("valid");
confirm.addClass("invalid");
confirm.removeClass("valid");
}
if (sendBtn.hasClass("scale-in")) {
sendBtn.removeClass("scale-in");
sendBtn.addClass("scale-out");
}
ok_passwrd = false;
}
});
$('#sendBtn').click(function () {
var name = $('#name').val();
var password = $('#passwrd').val();
$.ajax({
type: "POST",
dataType: 'json',
contentType: 'application/json',
url: "/api/userManagement/preRegister",
data: JSON.stringify({ name: name, password: password}),
success: function (data) {
console.log(data);
window.location.href = baseUrl + "?id="+data.id
}
}).fail(function (data) {
console.log(data);
if(data.status === 404){
alert("User Not Found!");
$('#name').addClass("invalid");
$('#name').removeClass("valid");
}
else{
alert(data.responseJSON.message);
}
});
});
$('#modalToken').modal({dismissible: false});
if(id !== ''){
$('#modalToken').modal('open');
}
$('#input_preToken').on("input", function () {
var sendBtn = $('#preTokenSend');
if($('#input_preToken').val().length < 4){
if (sendBtn.hasClass("scale-in")) {
sendBtn.removeClass("scale-in");
sendBtn.addClass("scale-out");
}
}
else{
if (sendBtn.hasClass("scale-out")) {
sendBtn.removeClass("scale-out");
sendBtn.addClass("scale-in");
}
}
});
$('#preTokenSend').click(function () {
$.ajax({
type: "POST",
dataType: 'json',
contentType: 'application/json',
url: "/api/userManagement/confirmAccount",
data: JSON.stringify({ id: id.toString(), checkToken: $('#input_preToken').val()}),
success: function (data) {
console.log(data);
Cookies.set('token',data.token);
Cookies.set('name', data.name);
debugger;
window.location.href = "/"
}
}).fail(function (data) {
console.log(data);
alert(data.responseJSON.message);
});
});
});

View File

@ -3,10 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0"/>
<title>Music Control - Discord Bot</title>
<link rel="icon"
type="image/x-icon"
href="favicon.png"/>
<title>Discord Bot - Music Control</title>
<!-- CSS -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/>
@ -16,106 +13,31 @@
<body class="blue-grey lighten-5" >
<!--__________________________________________________________-->
<!-- NAV BAR -->
<!-- AND -->
<!-- LOGIN -->
<!--__________________________________________________________-->
<nav class="blue-grey darken-4 z-depth-3" role="navigation">
<div class="nav-wrapper container">
<a id="logo-container" href="/" class="brand-logo">Discord Bot</a>
<a id="logo-container" href="#" class="brand-logo">Discord Bot</a>
<ul class="right hide-on-med-and-down">
<li class="">
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
<li >
<a href="/" data-target="slide-out" class="sidenav-trigger">Home</a>
</li>
<li class="active">
<a class="waves-effect waves-light" href="/music" >Music Control</a>
<a href="/music" >Music Control</a>
</li>
<li id="nav-bar-account">
<a class="dropdown-account" data-activates="dropdown1"><i class="material-icons">account_box</i></a>
</li>
</ul>
<ul id="nav-mobile" class="side-nav">
<li class="active">
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
<li >
<a href="/" data-target="slide-out" class="sidenav-trigger">Home</a>
</li>
<li>
<a class="waves-effect waves-light sidenav-trigger" href="/music" data-target="slide-out" >Music Control</a>
<li class="active">
<a href="/music" data-target="slide-out" class="sidenav-trigger">Music Control</a>
</li>
</ul>
<a href="#" data-activates="nav-mobile" class="button-navbar-mobile button-collapse"><i class="material-icons">menu</i></a>
<a href="#" data-activates="nav-mobile" class="button-collapse-1 button-collapse"><i class="material-icons">menu</i></a>
</div>
</nav>
<!-- Dropdown connected -->
<ul id="dropdown_connected" class="dropdown-content ">
<li>
<a class="center blue-grey-text text-darken-4" id="nav-name" style="text-decoration: underline; font-weight: bold"></a>
</li>
<li class="divider"></li>
<li>
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Account</a>
</li>
<li>
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Playlists</a>
</li>
<li class="divider"></li>
<li><a class="center red-text" id="nav-disconnect" style="font-weight: bold">Disconnect</a></li>
</ul>
<!--________________________________________-->
<!-- Connection modal -->
<!--________________________________________-->
<div id="modal_connection" class="modal">
<div class="modal-content">
<div class="row center">
<div class="col s12">
<h3 class="" style="font-weight: bold">Sign in</h3>
</div>
</div>
<div class="row center" style="margin-bottom: 0px">
<form name="login_form" id="login_form" action="javascript:void(0);" onsubmit="tryConnection()">
<div class="row" style="margin-bottom: 0px">
<div class="input-field col s6 offset-s3">
<i class="material-icons prefix">account_box</i>
<input name="username" id="user_input" type="text" class="validate"/>
<label for="user_input" data-error="User not registered!">User Name</label>
</div>
</div>
<div class="row">
<div class="input-field col s6 offset-s3">
<i class="material-icons prefix">security</i>
<input name="password" id="password_input" type="password" class="validate"/>
<label for="password_input" data-error="Wrong password!">Password</label>
</div>
</div>
<div class="row" style="margin-bottom: 10px">
<button id="btn-submit-connect" class="btn waves-effect waves-light light-green darken-1 scale-transition scale-out" type="submit" name="action" >
Submit<i class="material-icons right">send</i>
</button>
</div>
<div class="row">
<a class="btn waves-effect waves-light brown" href="/register">
Create account<i class="material-icons right">person_add</i>
</a>
</div>
</form>
</div>
</div>
</div>
<!--__________________________________________________________-->
<!-- -->
<!-- END -->
<!-- -->
<!--__________________________________________________________-->
<div class="section no-pad-bot main" id="index-banner">
<div class="row">
<div class="col s8">
@ -292,11 +214,6 @@
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="js/materialize.js"></script>
<script src="js/init.js"></script>
<script>
var needLogin = true;
</script>
<script src="js/navabar.js"></script>
<script src="js/js.cookie.js"></script>
</body>
</html>

View File

@ -1,210 +0,0 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0"/>
<title>User Registration - Discord Bot</title>
<link rel="icon" type="image/x-icon" href="favicon.png"/>
<!-- CSS -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/>
<link href="css/materialize.css" type="text/css" rel="stylesheet" media="screen,projection"/>
<link href="css/style.css" type="text/css" rel="stylesheet" media="screen,projection"/>
</head>
<body class="blue-grey lighten-5" >
<!--__________________________________________________________-->
<!-- NAV BAR -->
<!-- AND -->
<!-- LOGIN -->
<!--__________________________________________________________-->
<nav class="blue-grey darken-4 z-depth-3" role="navigation">
<div class="nav-wrapper container">
<a id="logo-container" href="/" class="brand-logo">Discord Bot</a>
<ul class="right hide-on-med-and-down">
<li class="">
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
</li>
<li>
<a class="waves-effect waves-light" href="/music" >Music Control</a>
</li>
<li id="nav-bar-account">
<a class="dropdown-account" data-activates="dropdown1"><i class="material-icons">account_box</i></a>
</li>
</ul>
<ul id="nav-mobile" class="side-nav">
<li class="active">
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
</li>
<li>
<a class="waves-effect waves-light sidenav-trigger" href="/music" data-target="slide-out" >Music Control</a>
</li>
</ul>
<a href="#" data-activates="nav-mobile" class="button-navbar-mobile button-collapse"><i class="material-icons">menu</i></a>
</div>
</nav>
<!-- Dropdown connected -->
<ul id="dropdown_connected" class="dropdown-content ">
<li>
<a class="center blue-grey-text text-darken-4" id="nav-name" style="text-decoration: underline; font-weight: bold"></a>
</li>
<li class="divider"></li>
<li>
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Account</a>
</li>
<li>
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Playlists</a>
</li>
<li class="divider"></li>
<li><a class="center red-text" id="nav-disconnect" style="font-weight: bold">Disconnect</a></li>
</ul>
<!--________________________________________-->
<!-- Connection modal -->
<!--________________________________________-->
<div id="modal_connection" class="modal">
<div class="modal-content">
<div class="row center">
<div class="col s12">
<h3 class="" style="font-weight: bold">Sign in</h3>
</div>
</div>
<div class="row center" style="margin-bottom: 0px">
<form name="login_form" id="login_form" action="javascript:void(0);" onsubmit="tryConnection()">
<div class="row" style="margin-bottom: 0px">
<div class="input-field col s6 offset-s3">
<i class="material-icons prefix">account_box</i>
<input name="username" id="user_input" type="text" class="validate"/>
<label for="user_input" data-error="User not registered!">User Name</label>
</div>
</div>
<div class="row">
<div class="input-field col s6 offset-s3">
<i class="material-icons prefix">security</i>
<input name="password" id="password_input" type="password" class="validate"/>
<label for="password_input" data-error="Wrong password!">Password</label>
</div>
</div>
<div class="row" style="margin-bottom: 10px">
<button id="btn-submit-connect" class="btn waves-effect waves-light light-green darken-1 scale-transition scale-out" type="submit" name="action" >
Submit<i class="material-icons right">send</i>
</button>
</div>
<div class="row">
<a class="btn waves-effect waves-light brown" href="/register">
Create account<i class="material-icons right">person_add</i>
</a>
</div>
</form>
</div>
</div>
</div>
<!--__________________________________________________________-->
<!-- -->
<!-- END -->
<!-- -->
<!--__________________________________________________________-->
<div class="section no-pad-bot main" id="index-banner">
<div class="row center">
<div class="row">
<h2 class="col s12">Account Registration</h2>
</div>
<div class="row" style="margin-bottom: 0%">
<div class="col s12">
<div class="input-field inline">
<i class="material-icons prefix">assignment_ind</i>
<input id="name" type="text" class="validate invalid"/>
<label for="name" data-error="" data-success="">Discord Name</label>
</div>
</div>
</div>
<div class="row" style="margin-bottom: 0%">
<div class="col s12">
<div class="input-field inline">
<i class="material-icons prefix">security</i>
<input id="passwrd" type="password" class="invalid"/>
<label for="passwrd" data-error="" data-success="">Password</label>
</div>
</div>
</div>
<div class="row" style="margin-bottom: 0%">
<div class="col s12">
<div class="input-field inline">
<i class="material-icons prefix">security</i>
<input id="passwrd2" type="password" class="invalid"/>
<label for="passwrd2" data-error="" data-success="">Confirm</label>
</div>
</div>
</div>
<div class="col s12">
<a id="sendBtn" class="waves-effect waves-light btn scale-transition scale-out">Send<i class="material-icons left">send</i></a>
</div>
</div>
</div>
<!-- Modal Structure -->
<div id="modalToken" class="modal">
<div class="modal-content">
<div class="row">
<h3 class="col s12 center"> User Validation</h3>
</div>
<div class="row">
<div class="col s10 offset-s1">
<p class="center">
A validation code was sent by private message, please copy it below.
</p>
</div>
</div>
<div class="row">
<div class="col s12">
<div class="row" style="margin-bottom: 0px">
<div class="input-field col s6 offset-s3">
<i class="material-icons prefix">fingerprint</i>
<input id="input_preToken" type="text" class="validate"/>
<label for="input_preToken">Verification Code</label>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<a href="#" id="preTokenSend" class="modal-action waves-effect waves-green btn scale-transition scale-out">Send</a>
</div>
</div>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="js/materialize.js"></script>
<script src="js/register.js"></script>
<script src="js/navabar.js"></script>
<script src="js/js.cookie.js"></script>
<script th:inline="javascript">
/*<![CDATA[*/
var id = [[${id}]];
console.log(id);
/*]]>*/
</script>
</body>
</html>