mirror of
https://github.com/player-guest/butterfly.git
synced 2026-04-26 01:20:02 -05:00
Remove butterflywebui because api integrated in game server
This commit is contained in:
parent
5d305fc122
commit
f4af02980e
|
|
@ -3,9 +3,7 @@ rootProject.name = 'butterflyserver'
|
|||
include ':butterflymodel'
|
||||
include ':butterflydao'
|
||||
include ':butterflycore'
|
||||
include ':butterflywebui'
|
||||
|
||||
project(":butterflymodel").projectDir = file("../butterflymodel")
|
||||
project(":butterflydao").projectDir = file("../butterflydao")
|
||||
project(":butterflycore").projectDir = file("../butterflycore")
|
||||
project(":butterflywebui").projectDir = file("../butterflywebui")
|
||||
|
|
|
|||
|
|
@ -1,71 +0,0 @@
|
|||
group 'com.buttongames'
|
||||
version '1.0-SNAPSHOT'
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'application'
|
||||
apply plugin: 'com.github.johnrengelman.shadow'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
|
||||
mainClassName = "com.buttongames.butterflywebui.Main"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: '../lib', include: ['*.jar'])
|
||||
implementation project(':butterflymodel')
|
||||
implementation project(':butterflydao')
|
||||
implementation project(':butterflycore')
|
||||
|
||||
implementation 'org.json:json:20190722'
|
||||
|
||||
implementation 'com.google.code.gson:gson:2.8.5'
|
||||
|
||||
testImplementation('org.junit.jupiter:junit-jupiter:5.5.1')
|
||||
|
||||
// Spark, core HTTP server provider
|
||||
compile group: 'com.sparkjava', name: 'spark-core', version: '2.8.0'
|
||||
|
||||
// Log4j, logging
|
||||
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.1'
|
||||
compile group: 'org.slf4j', name: 'slf4j-simple', version:'1.7.21'
|
||||
|
||||
// Spring, dependency injection
|
||||
compile group: 'org.springframework', name: 'spring-context', version: '5.1.3.RELEASE'
|
||||
testCompile group: 'org.springframework', name: 'spring-test', version: '5.1.3.RELEASE'
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes(
|
||||
'Main-Class': 'com.buttongames.butterflywebui.Main'
|
||||
)
|
||||
}
|
||||
|
||||
from {
|
||||
configurations.compile.collect {
|
||||
it.isDirectory() ? it : zipTree(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.github.jengelman.gradle.plugins:shadow:5.1.0'
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
run {
|
||||
if (project.hasProperty("appArgs")) {
|
||||
args Eval.me(appArgs)
|
||||
}
|
||||
|
||||
systemProperties System.getProperties()
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
rootProject.name = 'butterflywebui'
|
||||
|
||||
include ':butterflymodel'
|
||||
include ':butterflydao'
|
||||
include ':butterflycore'
|
||||
|
||||
project(":butterflymodel").projectDir = file("../butterflymodel")
|
||||
project(":butterflydao").projectDir = file("../butterflydao")
|
||||
project(":butterflycore").projectDir = file("../butterflycore")
|
||||
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
package com.buttongames.butterflywebui;
|
||||
|
||||
import com.buttongames.butterflywebui.http.WebUiHttpServer;
|
||||
import com.buttongames.butterflywebui.spring.configuration.ApplicationConfiguration;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
public class Main {
|
||||
|
||||
private static AnnotationConfigApplicationContext applicationContext;
|
||||
public static void main(String[] args) {
|
||||
|
||||
applicationContext = new AnnotationConfigApplicationContext(ApplicationConfiguration.class);
|
||||
final WebUiHttpServer webUiHttpServer = applicationContext.getBean(WebUiHttpServer.class);
|
||||
|
||||
webUiHttpServer.startServer();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,282 +0,0 @@
|
|||
package com.buttongames.butterflywebui.http;
|
||||
|
||||
import com.buttongames.butterflycore.util.JSONUtil;
|
||||
import com.buttongames.butterflycore.util.TimeUtils;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.TokenDao;
|
||||
import com.buttongames.butterflymodel.model.ButterflyUser;
|
||||
import com.buttongames.butterflymodel.model.Token;
|
||||
import com.buttongames.butterflywebui.http.controllers.api.CardHandler;
|
||||
import com.buttongames.butterflywebui.http.controllers.api.MachineHandler;
|
||||
import com.buttongames.butterflywebui.http.controllers.api.UserHandler;
|
||||
import com.buttongames.butterflywebui.http.controllers.api.admin.game.MatixxManageHandler;
|
||||
import com.buttongames.butterflywebui.http.controllers.api.game.MatixxHandler;
|
||||
import com.buttongames.butterflywebui.util.PropertyNames;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import spark.Request;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static spark.Spark.*;
|
||||
|
||||
/**
|
||||
* The main HTTP server. This class is responsible for the top-level handling of incoming
|
||||
* requests, then delegates the responsibility to the appropriate controller.
|
||||
* @author skogaby (skogabyskogaby@gmail.com)
|
||||
*/
|
||||
@Component
|
||||
public class WebUiHttpServer {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(WebUiHttpServer.class);
|
||||
|
||||
|
||||
private final TokenDao tokenDao;
|
||||
|
||||
private final UserHandler userHandler;
|
||||
|
||||
private final CardHandler cardHandler;
|
||||
|
||||
private final MachineHandler machineHandler;
|
||||
|
||||
private final MatixxHandler matixxHandler;
|
||||
|
||||
private final MatixxManageHandler matixxManageHandler;
|
||||
|
||||
|
||||
/** The port the server listens on */
|
||||
@Value(PropertyNames.PORT)
|
||||
private String port;
|
||||
|
||||
@Autowired
|
||||
public WebUiHttpServer(TokenDao tokenDao, UserHandler userHandler, CardHandler cardHandler, MachineHandler machineHandler, MatixxHandler matixxHandler, MatixxManageHandler matixxManageHandler) {
|
||||
this.tokenDao = tokenDao;
|
||||
this.userHandler = userHandler;
|
||||
this.cardHandler = cardHandler;
|
||||
this.machineHandler = machineHandler;
|
||||
this.matixxHandler = matixxHandler;
|
||||
this.matixxManageHandler = matixxManageHandler;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Configures the routes on our server and begins listening.
|
||||
*/
|
||||
public void startServer() {
|
||||
// configure the server properties
|
||||
int maxThreads = 20;
|
||||
int minThreads = 2;
|
||||
int timeOutMillis = 30000;
|
||||
|
||||
// once routes are configured, the server automatically begins
|
||||
threadPool(maxThreads, minThreads, timeOutMillis);
|
||||
port(Integer.parseInt(this.port));
|
||||
this.configureRoutesAndExceptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the HTTP server.
|
||||
*/
|
||||
public void stopServer() {
|
||||
stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the routes on the server, and the exception handlers.
|
||||
*/
|
||||
private void configureRoutesAndExceptions() {
|
||||
|
||||
staticFiles.location("/public");
|
||||
|
||||
before("/register/",(req,resp)->{
|
||||
if(checkAuth(req)) resp.redirect("/");
|
||||
});
|
||||
before("/portal/",(req,resp)->{
|
||||
if(!checkAuth(req)) resp.redirect("/");
|
||||
});
|
||||
before("/profile/",(req,resp)->{
|
||||
if(!checkAuth(req)) resp.redirect("/");
|
||||
});
|
||||
before("/card/",(req,resp)->{
|
||||
if(!checkAuth(req)) resp.redirect("/");
|
||||
});
|
||||
before("/machine/",(req,resp)->{
|
||||
if(!checkAuth(req)) resp.redirect("/");
|
||||
});
|
||||
|
||||
get("/", (req, resp) -> {
|
||||
if(checkAuth(req)) resp.redirect("/portal/");
|
||||
return renderContent("/public/index/content.html");
|
||||
});
|
||||
|
||||
get("/register/", (req, resp) -> renderContent("/public/register/content.html"));
|
||||
|
||||
get("/portal/", (req, resp) -> renderContent("/public/portal/content.html"));
|
||||
|
||||
get("/profile/", (req, resp) -> renderContent("/public/profile/content.html"));
|
||||
|
||||
get("/card/", (req, resp) -> renderContent("/public/card/content.html"));
|
||||
|
||||
get("/machine/", (req, resp) -> renderContent("/public/machine/content.html"));
|
||||
|
||||
|
||||
path("/api",() -> {
|
||||
|
||||
|
||||
|
||||
before("/*",(req,resp)-> {
|
||||
resp.type("application/json");
|
||||
LOG.info("API Call:"+req.requestMethod()+" "+req.uri());
|
||||
resp.header("Access-Control-Allow-Origin", "*");
|
||||
resp.header("Access-Control-Allow-Methods","GET, POST");
|
||||
resp.header("Access-Control-Allow-Headers","Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
resp.header("Access-Control-Max-Age","86400");
|
||||
if(req.requestMethod().equals("OPTIONS")){
|
||||
halt(200, "ok");
|
||||
}
|
||||
});
|
||||
|
||||
path("/user",()->{
|
||||
post("/auth",(req,resp) -> userHandler.handleRequest("auth", req, resp));
|
||||
post("/register",(req,resp) -> userHandler.handleRequest("register", req, resp));
|
||||
post("/logout",(req,resp) -> userHandler.handleRequest("logout", req, resp));
|
||||
});
|
||||
|
||||
before("/admin/*",(req,resp)-> {
|
||||
if(!checkAuth(req)){
|
||||
halt(401, JSONUtil.errorMsg("Unauthenticated"));
|
||||
}else if(!getUser(req).getUser_group().equals("admin")){
|
||||
halt(401, JSONUtil.errorMsg("No Permission"));
|
||||
}
|
||||
});
|
||||
|
||||
path("/admin", ()->{
|
||||
post("/musiclist",(req,resp)-> matixxManageHandler.handleRequest("set_musiclist", req, resp));
|
||||
});
|
||||
|
||||
before("/card/*",(req,resp)-> {
|
||||
if(!checkAuth(req)){
|
||||
halt(401, JSONUtil.errorMsg("Unauthenticated"));
|
||||
}
|
||||
});
|
||||
|
||||
path("/card",()->{
|
||||
get("/list",(req,resp) -> cardHandler.handleRequest("get", getUser(req), req,resp));
|
||||
post("/bind",(req,resp) -> cardHandler.handleRequest("bind", getUser(req), req,resp));
|
||||
post("/unbind",(req,resp) -> cardHandler.handleRequest("unbind", getUser(req), req,resp));
|
||||
});
|
||||
|
||||
before("/machine/*",(req,resp)-> {
|
||||
if(!checkAuth(req)){
|
||||
halt(401, JSONUtil.errorMsg("Unauthenticated"));
|
||||
}
|
||||
});
|
||||
|
||||
path("/machine",()->{
|
||||
get("/list",(req,resp) -> machineHandler.handleRequest("get", getUser(req), req,resp));
|
||||
post("/generate",(req,resp) -> machineHandler.handleRequest("generate", getUser(req), req,resp));
|
||||
post("/delete",(req,resp) -> machineHandler.handleRequest("delete", getUser(req), req,resp));
|
||||
});
|
||||
|
||||
|
||||
path("/game",()->{
|
||||
|
||||
path("/matixx",()->{
|
||||
get("/profile", (req,resp)-> matixxHandler.handleRequest("get_profile", getUser(req),req,resp));
|
||||
post("/profile", (req,resp)-> matixxHandler.handleRequest("update_profile", getUser(req),req,resp));
|
||||
get("/musiclist", (req,resp)-> matixxHandler.handleRequest("musiclist", getUser(req),req,resp));
|
||||
get("/recordlist", (req,resp)-> matixxHandler.handleRequest("play_record_list", getUser(req),req,resp));
|
||||
});
|
||||
|
||||
});
|
||||
notFound((req, resp) -> {
|
||||
resp.type("application/json");
|
||||
return JSONUtil.errorMsg("404 Not found");
|
||||
});
|
||||
|
||||
internalServerError((req, resp) -> {
|
||||
resp.type("application/json");
|
||||
return JSONUtil.errorMsg("500 Internal server error");
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private boolean checkAuth(Request request){
|
||||
String tokenstr = null;
|
||||
// Cookies
|
||||
if(request.cookie("token")!=null){
|
||||
tokenstr = request.cookie("token");
|
||||
}else if(request.headers("Authorization")!=null){
|
||||
// Authorization header
|
||||
tokenstr = request.headers("Authorization");
|
||||
}
|
||||
|
||||
if(tokenstr!=null&&!tokenstr.equals("")){
|
||||
Token token = tokenDao.findByToken(tokenstr);
|
||||
if(token!=null){
|
||||
LocalDateTime now = TimeUtils.getLocalDateTimeInUTC();
|
||||
if(now.isBefore(token.getExpireTime())){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private ButterflyUser getUser(Request request){
|
||||
String tokenstr = null;
|
||||
// Cookies
|
||||
if(request.cookie("token")!=null){
|
||||
tokenstr = request.cookie("token");
|
||||
}else if(request.headers("Authorization")!=null){
|
||||
// Authorization header
|
||||
tokenstr = request.headers("Authorization");
|
||||
}
|
||||
|
||||
if(tokenstr!=null){
|
||||
return tokenDao.findByToken(tokenstr).getUser();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String renderContent(String htmlFile) throws Exception {
|
||||
final URI uri = getClass().getResource(htmlFile).toURI();
|
||||
FileSystem zipfs = initFileSystem(uri);
|
||||
Path path = Paths.get(uri);
|
||||
String result = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
||||
zipfs.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
private FileSystem initFileSystem(URI uri) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
return FileSystems.getFileSystem(uri);
|
||||
}
|
||||
catch( FileSystemNotFoundException e )
|
||||
{
|
||||
Map<String, String> env = new HashMap<>();
|
||||
env.put("create", "true");
|
||||
return FileSystems.newFileSystem(uri, env);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
package com.buttongames.butterflywebui.http.controllers;
|
||||
|
||||
public class BaseController {
|
||||
}
|
||||
|
|
@ -1,110 +0,0 @@
|
|||
package com.buttongames.butterflywebui.http.controllers.api;
|
||||
|
||||
import com.buttongames.butterflycore.util.JSONUtil;
|
||||
import com.buttongames.butterflycore.util.ObjectUtils;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.ButterflyUserDao;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.CardDao;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.TokenDao;
|
||||
import com.buttongames.butterflymodel.model.ButterflyUser;
|
||||
import com.buttongames.butterflymodel.model.Card;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.json.JSONObject;
|
||||
import spark.Request;
|
||||
import spark.Response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CardHandler {
|
||||
|
||||
private final Logger LOG = LogManager.getLogger(UserHandler.class);
|
||||
|
||||
final ButterflyUserDao userDao;
|
||||
|
||||
final TokenDao tokenDao;
|
||||
|
||||
final CardDao cardDao;
|
||||
|
||||
public CardHandler(ButterflyUserDao userDao, TokenDao tokenDao, CardDao cardDao) {
|
||||
this.userDao = userDao;
|
||||
this.tokenDao = tokenDao;
|
||||
this.cardDao = cardDao;
|
||||
}
|
||||
|
||||
public Object handleRequest(final String function, final ButterflyUser user, final Request request, final Response response) {
|
||||
JSONObject reqBody = JSONUtil.getBody(request.body());
|
||||
|
||||
if(function.equals("get")){
|
||||
return handleGetRequest(reqBody, user, request, response);
|
||||
}else if(function.equals("bind")){
|
||||
return handleBindRequest(reqBody, user, request, response);
|
||||
}else if(function.equals("unbind")){
|
||||
return handleUnbindRequest(reqBody, user, request, response);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object handleGetRequest(final JSONObject reqBody, final ButterflyUser user, final Request request, final Response response){
|
||||
Gson gson = new GsonBuilder()
|
||||
.excludeFieldsWithoutExposeAnnotation()
|
||||
.create();
|
||||
|
||||
List<Card> cardList = cardDao.findByUser(user);
|
||||
return JSONUtil.createStr("SUCCESS", gson.toJson(cardList));
|
||||
|
||||
}
|
||||
|
||||
private Object handleBindRequest(final JSONObject reqBody, final ButterflyUser user, final Request request, final Response response){
|
||||
|
||||
final String nfcId = reqBody.getString("nfcId");
|
||||
final String passcode = reqBody.getString("pin");
|
||||
|
||||
if(nfcId!=null){
|
||||
Card card = cardDao.findByNfcId(nfcId);
|
||||
if(card!=null){
|
||||
if(card.getUser()==null){
|
||||
if(card.getPin().equals(passcode)){
|
||||
card.setUser(user);
|
||||
cardDao.update(card);
|
||||
response.status(200);
|
||||
return JSONUtil.successMsg("OK");
|
||||
}else{
|
||||
response.status(403);
|
||||
return JSONUtil.errorMsg("The Passcode of this card is wrong");
|
||||
}
|
||||
}else{
|
||||
response.status(403);
|
||||
return JSONUtil.errorMsg("This card had been bind to another account");
|
||||
}
|
||||
}else{
|
||||
response.status(404);
|
||||
return JSONUtil.errorMsg("Card not found. You must play one time in game");
|
||||
}
|
||||
}
|
||||
|
||||
response.status(400);
|
||||
return JSONUtil.errorMsg("Missing Parameter");
|
||||
|
||||
}
|
||||
|
||||
private Object handleUnbindRequest(final JSONObject reqBody, final ButterflyUser user, final Request request, final Response response){
|
||||
final long cardId = reqBody.getLong("id");
|
||||
|
||||
Card card = cardDao.findById(cardId);
|
||||
if(card!=null){
|
||||
if(card.getUser().getId()==user.getId()){
|
||||
card.setUser(null);
|
||||
cardDao.update(card);
|
||||
return JSONUtil.successMsg("Unbinded");
|
||||
}
|
||||
}
|
||||
|
||||
response.status(400);
|
||||
return JSONUtil.errorMsg("Wrong Parameter");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
package com.buttongames.butterflywebui.http.controllers.api;
|
||||
|
||||
import com.buttongames.butterflycore.util.JSONUtil;
|
||||
import com.buttongames.butterflycore.util.StringUtils;
|
||||
import com.buttongames.butterflycore.util.TimeUtils;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.ButterflyUserDao;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.CardDao;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.MachineDao;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.TokenDao;
|
||||
import com.buttongames.butterflymodel.model.ButterflyUser;
|
||||
import com.buttongames.butterflymodel.model.Card;
|
||||
import com.buttongames.butterflymodel.model.Machine;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import spark.Request;
|
||||
import spark.Response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MachineHandler {
|
||||
|
||||
private final Logger LOG = LogManager.getLogger(MachineHandler.class);
|
||||
|
||||
final ButterflyUserDao userDao;
|
||||
|
||||
final TokenDao tokenDao;
|
||||
|
||||
final MachineDao machineDao;
|
||||
|
||||
public MachineHandler(ButterflyUserDao userDao, TokenDao tokenDao, MachineDao machineDao) {
|
||||
this.userDao = userDao;
|
||||
this.tokenDao = tokenDao;
|
||||
this.machineDao = machineDao;
|
||||
}
|
||||
|
||||
public Object handleRequest(final String function, final ButterflyUser user, final Request request, final Response response) {
|
||||
JSONObject reqBody = JSONUtil.getBody(request.body());
|
||||
|
||||
if(function.equals("get")){
|
||||
return handleGetRequest(reqBody, user, request, response);
|
||||
}else if(function.equals("generate")){
|
||||
return handleGenerateRequest(reqBody, user, request, response);
|
||||
}else if(function.equals("delete")){
|
||||
return handleDeleteRequest(reqBody, user, request, response);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object handleGetRequest(final JSONObject reqBody, final ButterflyUser user, final Request request, final Response response){
|
||||
Gson gson = new GsonBuilder()
|
||||
.excludeFieldsWithoutExposeAnnotation()
|
||||
.create();
|
||||
|
||||
List<Machine> machineList = machineDao.findByUser(user);
|
||||
return JSONUtil.createStr("SUCCESS", gson.toJson(machineList));
|
||||
|
||||
}
|
||||
|
||||
private Object handleGenerateRequest(final JSONObject reqBody, final ButterflyUser user, final Request request, final Response response){
|
||||
List<Machine> machineList = machineDao.findByUser(user);
|
||||
if(machineList.size()>=3){
|
||||
response.status(403);
|
||||
return JSONUtil.errorMsg("You exceed the limit of 3");
|
||||
}else{
|
||||
String pcbId = "";
|
||||
do{
|
||||
pcbId = "0120100000"+ StringUtils.getRandomHexString(10);
|
||||
}while (machineDao.findByPcbId(pcbId)!=null);
|
||||
Machine machine = new Machine(user,pcbId, TimeUtils.getLocalDateTimeInUTC(),true,5700);
|
||||
machineDao.create(machine);
|
||||
return JSONUtil.successMsg("OK");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Object handleDeleteRequest(final JSONObject reqBody, final ButterflyUser user, final Request request, final Response response){
|
||||
final long machineId = reqBody.getLong("id");
|
||||
|
||||
Machine machine = machineDao.findById(machineId);
|
||||
if(machine!=null){
|
||||
if(machine.getUser().getId()==user.getId()){
|
||||
machineDao.delete(machine);
|
||||
return JSONUtil.successMsg("Deleted");
|
||||
}
|
||||
}
|
||||
|
||||
response.status(400);
|
||||
return JSONUtil.errorMsg("Wrong Parameter");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
package com.buttongames.butterflywebui.http.controllers.api;
|
||||
|
||||
import com.buttongames.butterflycore.util.JSONUtil;
|
||||
import com.buttongames.butterflycore.util.MD5Utils;
|
||||
import com.buttongames.butterflycore.util.StringUtils;
|
||||
import com.buttongames.butterflycore.util.TimeUtils;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.ButterflyUserDao;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.TokenDao;
|
||||
import com.buttongames.butterflymodel.model.ButterflyUser;
|
||||
import com.buttongames.butterflymodel.model.Token;
|
||||
import org.json.*;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import spark.Request;
|
||||
import spark.Response;
|
||||
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
public class UserHandler {
|
||||
|
||||
private final Logger LOG = LogManager.getLogger(UserHandler.class);
|
||||
|
||||
final ButterflyUserDao userDao;
|
||||
|
||||
final TokenDao tokenDao;
|
||||
|
||||
public UserHandler(ButterflyUserDao userDao,TokenDao tokenDao) {
|
||||
this.userDao = userDao;
|
||||
this.tokenDao = tokenDao;
|
||||
}
|
||||
|
||||
public Object handleRequest(final String function, final Request request, final Response response) {
|
||||
JSONObject reqBody = JSONUtil.getBody(request.body());
|
||||
|
||||
if(function.equals("auth")){
|
||||
return handleAuthRequest(reqBody, request, response);
|
||||
}else if(function.equals("register")){
|
||||
return handleRegisterRequest(reqBody, request, response);
|
||||
}else if(function.equals("logout")){
|
||||
return handleLogoutRequest(reqBody,request,response);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object handleAuthRequest(final JSONObject reqBody, final Request request, final Response response){
|
||||
final String email = reqBody.getString("email");
|
||||
final String password = reqBody.getString("password");
|
||||
ButterflyUser user = userDao.getByEmail(email);
|
||||
if(user!=null){
|
||||
String passhash = MD5Utils.getHash(user.getSalt(),password);
|
||||
if(passhash.equals(user.getPasswordHash())){
|
||||
Token token = new Token(user, StringUtils.getRandomHexString(20), TimeUtils.getLocalDateTimeInUTC().plus(30, ChronoUnit.DAYS));
|
||||
tokenDao.create(token);
|
||||
response.status(200);
|
||||
// change cookies to secured after debug
|
||||
response.cookie("/","token",token.getToken(),2628000,false,true);
|
||||
String jsonString = new JSONObject()
|
||||
.put("userId", user.getId())
|
||||
.put("token", token.getToken())
|
||||
.put("expire", token.getExpireTime()).toString();
|
||||
return jsonString;
|
||||
}
|
||||
}
|
||||
response.status(401);
|
||||
String jsonString = new JSONObject()
|
||||
.put("status", "failure")
|
||||
.put("data", new JSONObject().put("message", "Wrong E-Mail or Password")).toString();
|
||||
return jsonString;
|
||||
}
|
||||
|
||||
private Object handleRegisterRequest(final JSONObject reqBody, final Request request, final Response response){
|
||||
final String email = reqBody.getString("email");
|
||||
final String password = reqBody.getString("password");
|
||||
ButterflyUser user = userDao.getByEmail(email);
|
||||
if(user!=null){
|
||||
response.status(401);
|
||||
return JSONUtil.errorMsg("This E-Mail had been registered");
|
||||
}else{
|
||||
//check password
|
||||
final String salt = MD5Utils.genSalt();
|
||||
ButterflyUser newUser = new ButterflyUser(email,salt,MD5Utils.getHash(salt, password),TimeUtils.getLocalDateTimeInUTC(),null,3000,"player");
|
||||
userDao.create(newUser);
|
||||
|
||||
return JSONUtil.successMsg("Account created");
|
||||
}
|
||||
}
|
||||
|
||||
private Object handleLogoutRequest(final JSONObject reqBody, final Request request, final Response response){
|
||||
final String cookietoken = request.cookie("token");
|
||||
final String authtoken = request.headers("Authorization");
|
||||
String token = null;
|
||||
if(cookietoken!=null){
|
||||
token = cookietoken;
|
||||
}else if(authtoken!=null){
|
||||
token = authtoken;
|
||||
}
|
||||
|
||||
if(token!=null){
|
||||
Token tokenObject = tokenDao.findByToken(token);
|
||||
tokenDao.delete(tokenObject);
|
||||
return JSONUtil.successMsg("Logouted");
|
||||
}
|
||||
|
||||
|
||||
response.status(403);
|
||||
return JSONUtil.errorMsg("Token Unavailable");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
package com.buttongames.butterflywebui.http.controllers.api.admin.game;
|
||||
|
||||
import com.buttongames.butterflycore.util.JSONUtil;
|
||||
import com.buttongames.butterflycore.xml.XmlUtils;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.gdmatixx.MatixxMusicDao;
|
||||
import com.buttongames.butterflymodel.model.gdmatixx.matixxMusic;
|
||||
import com.buttongames.butterflywebui.http.controllers.api.game.MatixxHandler;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
import spark.Request;
|
||||
import spark.Response;
|
||||
|
||||
public class MatixxManageHandler {
|
||||
|
||||
private final Logger LOG = LogManager.getLogger(MatixxManageHandler.class);
|
||||
|
||||
final MatixxMusicDao matixxMusicDao;
|
||||
|
||||
public MatixxManageHandler(MatixxMusicDao matixxMusicDao) {
|
||||
this.matixxMusicDao = matixxMusicDao;
|
||||
}
|
||||
|
||||
public Object handleRequest(final String function, final Request request, final Response response){
|
||||
|
||||
if (function.equals("set_musiclist")) {
|
||||
return handleSetMusiclistRequest(request, response);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object handleSetMusiclistRequest(final Request request, final Response response){
|
||||
|
||||
byte[] mdb_mtfile = request.bodyAsBytes();
|
||||
Element mdb = XmlUtils.byteArrayToXmlFile(mdb_mtfile);
|
||||
NodeList mdb_datas = XmlUtils.nodesAtPath(mdb,"/mdb_data");
|
||||
|
||||
LOG.info("Adding "+mdb_datas.getLength()+" records");
|
||||
|
||||
for(int j=0;j<mdb_datas.getLength();j++) {
|
||||
|
||||
Element item = (Element) mdb_datas.item(j);
|
||||
int music_id = XmlUtils.intAtChild(item, "music_id");
|
||||
|
||||
boolean isNew = false;
|
||||
matixxMusic musicObj = matixxMusicDao.findByMusicId(music_id);
|
||||
if(musicObj==null) {
|
||||
isNew = true;
|
||||
musicObj = new matixxMusic();
|
||||
musicObj.setMusicid(music_id);
|
||||
|
||||
//omnimix
|
||||
musicObj.setList_type(2);
|
||||
|
||||
String[] l1 = XmlUtils.strAtChild(item, "xg_diff_list").split(" ");
|
||||
|
||||
String guitar_diff = l1[0] + " " + l1[1] + " " + l1[2] + " " + l1[3] + " " + l1[4];
|
||||
String bass_diff = l1[10] + " " + l1[11] + " " + l1[12] + " " + l1[13] + " " + l1[14];
|
||||
String drum_diff = l1[5] + " " + l1[6] + " " + l1[7] + " " + l1[8] + " " + l1[9];
|
||||
|
||||
musicObj.setGuitar_diff(guitar_diff);
|
||||
musicObj.setBass_diff(bass_diff);
|
||||
musicObj.setDrum_diff(drum_diff);
|
||||
|
||||
musicObj.setIs_hot(false);
|
||||
|
||||
musicObj.setContain_stat(XmlUtils.strAtChild(item, "contain_stat"));
|
||||
|
||||
musicObj.setFirst_ver(XmlUtils.strAtChild(item, "first_ver"));
|
||||
|
||||
musicObj.setFirst_classic_ver(XmlUtils.strAtChild(item, "first_classic_ver"));
|
||||
|
||||
musicObj.setB_long(XmlUtils.boolAtChild(item, "b_long"));
|
||||
|
||||
musicObj.setB_eemail(XmlUtils.boolAtChild(item, "b_eemall"));
|
||||
|
||||
musicObj.setBpm(XmlUtils.intAtChild(item, "bpm"));
|
||||
|
||||
musicObj.setBpm2(XmlUtils.intAtChild(item, "bpm2"));
|
||||
|
||||
String title_name = XmlUtils.strAtChild(item, "title_name");
|
||||
musicObj.setTitle_name(title_name);
|
||||
|
||||
musicObj.setTitle_ascii(XmlUtils.strAtChild(item, "title_ascii"));
|
||||
|
||||
musicObj.setArtist_title_ascii(XmlUtils.strAtChild(item, "artist_title_ascii"));
|
||||
|
||||
musicObj.setXg_secret(XmlUtils.strAtChild(item, "xg_secret"));
|
||||
|
||||
musicObj.setXg_b_session(XmlUtils.boolAtChild(item, "xg_b_session"));
|
||||
|
||||
musicObj.setSpeed(XmlUtils.intAtChild(item, "speed"));
|
||||
|
||||
musicObj.setChart_list(XmlUtils.strAtChild(item, "chart_list"));
|
||||
|
||||
musicObj.setOrigin(XmlUtils.intAtChild(item, "origin"));
|
||||
|
||||
musicObj.setMusic_type(XmlUtils.intAtChild(item, "music_type"));
|
||||
|
||||
musicObj.setGenre(XmlUtils.intAtChild(item, "genre"));
|
||||
|
||||
musicObj.setType_category(XmlUtils.intAtChild(item, "type_category"));
|
||||
|
||||
if (isNew) {
|
||||
matixxMusicDao.create(musicObj);
|
||||
LOG.info("Added " + title_name);
|
||||
} else {
|
||||
matixxMusicDao.update(musicObj);
|
||||
LOG.info("Updated " + title_name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return JSONUtil.successMsg("OK");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
package com.buttongames.butterflywebui.http.controllers.api.game;
|
||||
|
||||
import com.buttongames.butterflycore.util.JSONUtil;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.ButterflyUserDao;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.CardDao;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.gdmatixx.MatixxMusicDao;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.gdmatixx.MatixxProfileDao;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.gdmatixx.MatixxStageDao;
|
||||
import com.buttongames.butterflymodel.model.ButterflyUser;
|
||||
import com.buttongames.butterflymodel.model.Card;
|
||||
import com.buttongames.butterflymodel.model.gdmatixx.matixxPlayerProfile;
|
||||
import com.buttongames.butterflymodel.model.gdmatixx.matixxStageRecord;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.json.JSONObject;
|
||||
import spark.Request;
|
||||
import spark.Response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MatixxHandler {
|
||||
|
||||
|
||||
private final Logger LOG = LogManager.getLogger(MatixxHandler.class);
|
||||
|
||||
final ButterflyUserDao butterflyUserDao;
|
||||
|
||||
final CardDao cardDao;
|
||||
|
||||
final MatixxProfileDao matixxProfileDao;
|
||||
|
||||
final MatixxStageDao matixxStageDao;
|
||||
|
||||
final MatixxMusicDao matixxMusicDao;
|
||||
|
||||
public MatixxHandler(ButterflyUserDao butterflyUserDao, CardDao cardDao, MatixxProfileDao matixxProfileDao, MatixxStageDao matixxStageDao, MatixxMusicDao matixxMusicDao) {
|
||||
this.butterflyUserDao = butterflyUserDao;
|
||||
this.cardDao = cardDao;
|
||||
this.matixxProfileDao = matixxProfileDao;
|
||||
this.matixxStageDao = matixxStageDao;
|
||||
this.matixxMusicDao = matixxMusicDao;
|
||||
}
|
||||
|
||||
public Object handleRequest(final String function, final ButterflyUser user, final Request request, final Response response) {
|
||||
JSONObject reqBody = JSONUtil.getBody(request.body());
|
||||
|
||||
|
||||
if (function.equals("musiclist")) {
|
||||
return handleMusicListRequest(reqBody, request, response);
|
||||
}
|
||||
|
||||
/** Method after here need a matixx profile*/
|
||||
|
||||
Card card = cardDao.findByUser(user).get(0);
|
||||
if(card==null){
|
||||
response.status(400);
|
||||
return JSONUtil.errorMsg("You have not bind card to this account");
|
||||
}
|
||||
|
||||
matixxPlayerProfile profile = matixxProfileDao.findByCard(card);
|
||||
if(profile==null){
|
||||
response.status(400);
|
||||
return JSONUtil.errorMsg("Can't find a profile by your first card. Multiple card not support now");
|
||||
}
|
||||
|
||||
if (function.equals("get_profile")) {
|
||||
return handleGetProfileRequest(reqBody, profile, request, response);
|
||||
} else if (function.equals("update_profile")) {
|
||||
return handleUpdateProfileRequest(reqBody, profile, request, response);
|
||||
} else if (function.equals("play_record_list")) {
|
||||
return handlePlayRecordListRequest(reqBody, card, request, response);
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
private Object handleGetProfileRequest(final JSONObject reqBody, final matixxPlayerProfile profile, final Request request, final Response response){
|
||||
|
||||
final String player_name = profile.getName();
|
||||
final String player_title = profile.getTitle();
|
||||
final String[] player_skill = profile.getSkilldata().split(",");
|
||||
|
||||
|
||||
return JSONUtil.create("SUCCESS", new JSONObject().put("player_name", player_name)
|
||||
.put("player_title", player_title)
|
||||
.put("player_skill", player_skill[0])
|
||||
);
|
||||
}
|
||||
|
||||
private Object handleUpdateProfileRequest(final JSONObject reqBody, final matixxPlayerProfile profile, final Request request, final Response response){
|
||||
int count=0;
|
||||
|
||||
final String player_name = reqBody.getString("player_name");
|
||||
if(player_name!=null&&!player_name.equals("")){
|
||||
profile.setName(player_name);
|
||||
}else{count++;}
|
||||
final String player_title = reqBody.getString("player_title");
|
||||
if(player_title!=null&&!player_title.equals("")){
|
||||
profile.setTitle(player_title);
|
||||
}else{count++;}
|
||||
if(count==2){
|
||||
response.status(400);
|
||||
return JSONUtil.errorMsg("You input a null value");
|
||||
}else{
|
||||
matixxProfileDao.update(profile);
|
||||
return new JSONObject().put("player_name", profile.getName())
|
||||
.put("player_title", profile.getTitle())
|
||||
.put("player_skill", profile.getSkilldata().split(",")[0]).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Object handleMusicListRequest(final JSONObject reqBody, final Request request, final Response response){
|
||||
Gson gson = new GsonBuilder()
|
||||
.excludeFieldsWithoutExposeAnnotation()
|
||||
.create();
|
||||
return gson.toJson(matixxMusicDao.findAll());
|
||||
|
||||
|
||||
}
|
||||
|
||||
private Object handlePlayRecordListRequest(final JSONObject reqBody, final Card card, final Request request, final Response response){
|
||||
Gson gson = new GsonBuilder()
|
||||
.excludeFieldsWithoutExposeAnnotation()
|
||||
.create();
|
||||
|
||||
List<matixxStageRecord> list = matixxStageDao.findByCard(card);
|
||||
return gson.toJson(list);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
package com.buttongames.butterflywebui.http.controllers.web;
|
||||
|
||||
import com.buttongames.butterflywebui.Main;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.net.MediaType;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import spark.Request;
|
||||
import spark.Response;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class WebUIHandler {
|
||||
private final Logger LOG = LogManager.getLogger(WebUIHandler.class);
|
||||
|
||||
public Object sendResponse(final Request request, final Response response){
|
||||
final HttpServletResponse rawResponse = response.raw();
|
||||
response.type(MediaType.HTML_UTF_8.toString());
|
||||
String path = request.uri();
|
||||
byte[] bytes;
|
||||
|
||||
try {
|
||||
if(path.contains("/public/static")){
|
||||
bytes = ByteStreams.toByteArray(Main.class.getResourceAsStream(path));
|
||||
}else{
|
||||
bytes = ByteStreams.toByteArray(Main.class.getResourceAsStream("/public/index/index.html"));
|
||||
}
|
||||
rawResponse.getOutputStream().write(bytes);
|
||||
rawResponse.getOutputStream().flush();
|
||||
rawResponse.getOutputStream().close();
|
||||
|
||||
LOG.info("Response sent: " + path);
|
||||
return 200;
|
||||
}catch (Exception e){
|
||||
LOG.info("Static file not found: " + path);
|
||||
response.status(404);
|
||||
return 404;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
package com.buttongames.butterflywebui.spring.configuration;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Bean config class for the top-level application.
|
||||
* @author skogaby (skogabyskogaby@gmail.com)
|
||||
*/
|
||||
@Configuration
|
||||
@ComponentScan({"com.buttongames.butterflywebui.spring.configuration"})
|
||||
public class ApplicationConfiguration {
|
||||
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
package com.buttongames.butterflywebui.spring.configuration;
|
||||
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.ButterflyUserDao;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.CardDao;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.MachineDao;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.TokenDao;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.gdmatixx.MatixxMusicDao;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.gdmatixx.MatixxProfileDao;
|
||||
import com.buttongames.butterflydao.hibernate.dao.impl.gdmatixx.MatixxStageDao;
|
||||
import com.buttongames.butterflywebui.http.WebUiHttpServer;
|
||||
import com.buttongames.butterflywebui.http.controllers.api.CardHandler;
|
||||
import com.buttongames.butterflywebui.http.controllers.api.MachineHandler;
|
||||
import com.buttongames.butterflywebui.http.controllers.api.UserHandler;
|
||||
import com.buttongames.butterflywebui.http.controllers.api.admin.game.MatixxManageHandler;
|
||||
import com.buttongames.butterflywebui.http.controllers.api.game.MatixxHandler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
/**
|
||||
* Bean config class for HTTP-related classes.
|
||||
* @author skogaby (skogabyskogaby@gmail.com)
|
||||
*/
|
||||
@Configuration
|
||||
@ComponentScan({"com.buttongames.butterflywebui.spring.configuration",
|
||||
"com.buttongames.butterflydao.spring.configuration"})
|
||||
@PropertySource("classpath:butterflywebui.properties")
|
||||
public class HttpConfiguration {
|
||||
|
||||
@Bean
|
||||
public WebUiHttpServer webUiHttpServer(final TokenDao tokenDao, final UserHandler userHandler, final CardHandler cardHandler, final MachineHandler machineHandler, final MatixxHandler matixxHandler, final MatixxManageHandler matixxManageHandler){
|
||||
return new WebUiHttpServer(tokenDao,userHandler,cardHandler,machineHandler,matixxHandler,matixxManageHandler);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UserHandler userHandler(final ButterflyUserDao butterflyUserDao, final TokenDao tokenDao){
|
||||
return new UserHandler(butterflyUserDao,tokenDao);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CardHandler cardHandler(final ButterflyUserDao userDao, final TokenDao tokenDao, final CardDao cardDao){
|
||||
return new CardHandler(userDao, tokenDao, cardDao);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MachineHandler machineHandler(ButterflyUserDao userDao, TokenDao tokenDao, MachineDao machineDao){
|
||||
return new MachineHandler(userDao,tokenDao,machineDao);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MatixxHandler matixxHandler(ButterflyUserDao userDao, CardDao cardDao, MatixxProfileDao matixxProfileDao, MatixxStageDao matixxStageDao, MatixxMusicDao matixxMusicDao){
|
||||
return new MatixxHandler(userDao,cardDao,matixxProfileDao,matixxStageDao,matixxMusicDao);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MatixxManageHandler matixxManageHandler(MatixxMusicDao matixxMusicDao){
|
||||
return new MatixxManageHandler(matixxMusicDao);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package com.buttongames.butterflywebui.util;
|
||||
|
||||
/**
|
||||
* Simple class to hold our config / property keys for reading properties files.
|
||||
* @author skogaby (skogabyskogaby@gmail.com)
|
||||
*/
|
||||
public class PropertyNames {
|
||||
|
||||
public static final String PORT = "${server.port}";
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
# Server properties
|
||||
server.port = 8081
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.4 KiB |
|
|
@ -1,148 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Card</title>
|
||||
<style>
|
||||
body{
|
||||
background-color: rgb(223, 255, 255);
|
||||
}
|
||||
tbody {
|
||||
text-align: center;
|
||||
}
|
||||
#index_list tr{
|
||||
background-color: rgb(182, 221, 221);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<center>
|
||||
<table width="95%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td height="20">
|
||||
<font color="black">
|
||||
Card
|
||||
</font>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table width="95%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<center>
|
||||
<table id="card_list" border="1" width="95%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Display ID</th>
|
||||
<th>NFC ID</th>
|
||||
<th>Type</th>
|
||||
<th>Function</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</center>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<button onclick="bindCard()">Add Card</button>
|
||||
<p style="color:red;">Caution: Binding multiple card may not work as expected.</p>
|
||||
</center>
|
||||
|
||||
<script>
|
||||
function getCard() {
|
||||
let http = new XMLHttpRequest();
|
||||
let url = "/api/card/list";
|
||||
http.withCredentials = true;
|
||||
http.onreadystatechange = function () {
|
||||
if (http.readyState == XMLHttpRequest.DONE) {
|
||||
let resp = JSON.parse(http.responseText);
|
||||
if (http.status == 200) {
|
||||
let table = document.getElementById("card_list");
|
||||
if(resp.data.length>0){
|
||||
resp.data.forEach(function(item){
|
||||
let row = table.insertRow(-1);
|
||||
|
||||
row.insertCell(0).innerText = item.id;
|
||||
row.insertCell(1).innerText = item.displayId;
|
||||
row.insertCell(2).innerText = item.nfcId;
|
||||
row.insertCell(3).innerText = item.type;
|
||||
row.insertCell(4).innerHTML = '<button onclick="unbind('+item.id+')">Unbind</button>';
|
||||
})
|
||||
}
|
||||
} else {
|
||||
alert(resp.data.message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
http.open("GET", url);
|
||||
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
http.send();
|
||||
|
||||
}
|
||||
|
||||
function bindCard(){
|
||||
let nfcId = prompt("Please enter the card NFC ID","");
|
||||
let passcode = prompt("Please enter the Passcode of this card","");
|
||||
let http = new XMLHttpRequest();
|
||||
let url = "/api/card/bind";
|
||||
http.withCredentials = true;
|
||||
http.onreadystatechange = function () {
|
||||
if (http.readyState == XMLHttpRequest.DONE) {
|
||||
let resp = JSON.parse(http.responseText);
|
||||
if (http.status == 200) {
|
||||
alert("OK");
|
||||
let table = document.getElementById("card_list");
|
||||
table.innerHTML = "";
|
||||
location.reload();
|
||||
} else {
|
||||
alert(resp.data.message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
http.open("POST", url);
|
||||
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
http.send(JSON.stringify({"nfcId":nfcId,"passcode":passcode}));
|
||||
}
|
||||
|
||||
function unbind(id){
|
||||
let http = new XMLHttpRequest();
|
||||
let url = "/api/card/unbind";
|
||||
http.withCredentials = true;
|
||||
http.onreadystatechange = function () {
|
||||
if (http.readyState == XMLHttpRequest.DONE) {
|
||||
let resp = JSON.parse(http.responseText);
|
||||
if (http.status == 200) {
|
||||
alert("OK");
|
||||
location.reload();
|
||||
} else {
|
||||
alert(resp.data.message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
http.open("POST", url);
|
||||
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
http.send(JSON.stringify({"cardId":id}));
|
||||
console.log(this.parentElement.nodeName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
window.onload = function(){
|
||||
getCard();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>EA Server</title>
|
||||
<style>
|
||||
tbody {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body background="/bg.gif">
|
||||
<center>
|
||||
<table width="95%">
|
||||
<tbody>
|
||||
<tr bgcolor="#204020">
|
||||
<td height="20">
|
||||
<font color="white">
|
||||
Welcome!
|
||||
</font>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table width="40%" style="border: solid;margin-top:50px;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td height="20">
|
||||
Login
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="20">
|
||||
E-Mail:<input id="email" type="text">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="20">
|
||||
Password:<input id="password" type="password">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="20">
|
||||
<button id="login_btn" onclick="login()">Login</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<a href="/register/">New User?</a>
|
||||
</center>
|
||||
|
||||
<script>
|
||||
function login(){
|
||||
var http = new XMLHttpRequest();
|
||||
var url = "/api/user/auth";
|
||||
let email = document.getElementById("email").value;
|
||||
let password = document.getElementById("password").value;
|
||||
http.withCredentials = true;
|
||||
http.onreadystatechange = function() {
|
||||
if(http.readyState == XMLHttpRequest.DONE){
|
||||
if(http.status==200){
|
||||
location.href = "/portal/";
|
||||
}else{
|
||||
resp = JSON.parse(http.responseText);
|
||||
alert(resp.data.message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
http.open("POST",url);
|
||||
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
http.send(JSON.stringify({"email":email,"password":password}));
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Machine</title>
|
||||
<style>
|
||||
body{
|
||||
background-color: rgb(223, 255, 255);
|
||||
}
|
||||
tbody {
|
||||
text-align: center;
|
||||
}
|
||||
#index_list tr{
|
||||
background-color: rgb(182, 221, 221);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<center>
|
||||
<table width="95%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td height="20">
|
||||
<font color="black">
|
||||
Machine
|
||||
</font>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table width="95%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<center>
|
||||
<table id="machine_list" border="1" width="95%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>PCB ID</th>
|
||||
<th>Function</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</center>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<button onclick="genMachine()">New Machine</button>
|
||||
<p style="color:red;"></p>
|
||||
</center>
|
||||
|
||||
<script>
|
||||
function getMachine() {
|
||||
let http = new XMLHttpRequest();
|
||||
let url = "/api/machine/list";
|
||||
http.withCredentials = true;
|
||||
http.onreadystatechange = function () {
|
||||
if (http.readyState == XMLHttpRequest.DONE) {
|
||||
let resp = JSON.parse(http.responseText);
|
||||
if (http.status == 200) {
|
||||
let table = document.getElementById("machine_list");
|
||||
if(resp.data[0].id){
|
||||
resp.data.forEach(function(item){
|
||||
let row = table.insertRow(-1);
|
||||
|
||||
row.insertCell(0).innerText = item.id;
|
||||
row.insertCell(1).innerText = item.pcbId;
|
||||
row.insertCell(2).innerHTML = '<button onclick="deleteMachine('+item.id+')">Delete</button>';
|
||||
})
|
||||
}
|
||||
} else {
|
||||
alert(resp.data.message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
http.open("GET", url);
|
||||
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
http.send();
|
||||
}
|
||||
|
||||
function genMachine(){
|
||||
let http = new XMLHttpRequest();
|
||||
let url = "/api/machine/generate";
|
||||
http.withCredentials = true;
|
||||
http.onreadystatechange = function () {
|
||||
if (http.readyState == XMLHttpRequest.DONE) {
|
||||
let resp = JSON.parse(http.responseText);
|
||||
if (http.status == 200) {
|
||||
alert("OK");
|
||||
let table = document.getElementById("machine_list");
|
||||
table.innerHTML = "";
|
||||
location.reload();
|
||||
} else {
|
||||
alert(resp.data.message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
http.open("POST", url);
|
||||
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
http.send();
|
||||
}
|
||||
|
||||
function deleteMachine(id){
|
||||
let http = new XMLHttpRequest();
|
||||
let url = "/api/machine/delete";
|
||||
http.withCredentials = true;
|
||||
http.onreadystatechange = function () {
|
||||
if (http.readyState == XMLHttpRequest.DONE) {
|
||||
let resp = JSON.parse(http.responseText);
|
||||
if (http.status == 200) {
|
||||
alert("OK");
|
||||
location.reload();
|
||||
} else {
|
||||
alert(resp.data.message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
http.open("POST", url);
|
||||
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
http.send(JSON.stringify({"machineId":id}));
|
||||
console.log(this.parentElement.nodeName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
window.onload = function(){
|
||||
getMachine();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>EA Server</title>
|
||||
<style>
|
||||
body{
|
||||
background-color: rgb(223, 255, 255);
|
||||
}
|
||||
tbody {
|
||||
text-align: center;
|
||||
}
|
||||
#index_list tr{
|
||||
background-color: rgb(182, 221, 221);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<center>
|
||||
<table width="95%">
|
||||
<tbody>
|
||||
<tr bgcolor="#204020">
|
||||
<td height="20">
|
||||
<font color="white">
|
||||
GameServer!
|
||||
</font>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table width="40%" style="margin:30px;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td height="20">
|
||||
Welcome
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table width="95%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td width="20%">
|
||||
<center>
|
||||
<table id="index_list">
|
||||
<font color="red">INDEX</font>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<center>
|
||||
<font face="IMPACT"><a href="/profile/" target="iframe">Profile</a>
|
||||
</font>
|
||||
</center>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<center>
|
||||
<font face="IMPACT"><a href="/card/" target="iframe">Card</a>
|
||||
</font>
|
||||
</center>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<center>
|
||||
<font face="IMPACT"><a href="/machine/" target="iframe">Machine</a>
|
||||
</font>
|
||||
</center>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</center>
|
||||
|
||||
</td>
|
||||
<td width="80%">
|
||||
<iframe name="iframe" src="/profile/" width="100%" height="500px"></iframe>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</center>
|
||||
|
||||
<script>
|
||||
function login() {
|
||||
var http = new XMLHttpRequest();
|
||||
var url = "/api/user/auth";
|
||||
let email = document.getElementById("email").value;
|
||||
let password = document.getElementById("password").value;
|
||||
http.withCredentials = true;
|
||||
http.onreadystatechange = function () {
|
||||
if (http.readyState == XMLHttpRequest.DONE) {
|
||||
if (http.status == 200) {
|
||||
location.href = "/portal/";
|
||||
} else {
|
||||
resp = JSON.parse(http.responseText);
|
||||
alert(resp.data.message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
http.open("POST", url);
|
||||
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
http.send(JSON.stringify({ "email": email, "password": password }));
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Profile</title>
|
||||
<style>
|
||||
body{
|
||||
background-color: rgb(223, 255, 255);
|
||||
}
|
||||
tbody {
|
||||
text-align: center;
|
||||
}
|
||||
#index_list tr{
|
||||
background-color: rgb(182, 221, 221);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body >
|
||||
<center>
|
||||
<table width="40%" style="margin:50px;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td height="20">
|
||||
Profile
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table width="95%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td width="20%">
|
||||
<center>
|
||||
|
||||
</center>
|
||||
|
||||
</td>
|
||||
<td width="80%">
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</center>
|
||||
|
||||
<script>
|
||||
function login() {
|
||||
var http = new XMLHttpRequest();
|
||||
var url = "/api/user/auth";
|
||||
let email = document.getElementById("email").value;
|
||||
let password = document.getElementById("password").value;
|
||||
http.withCredentials = true;
|
||||
http.onreadystatechange = function () {
|
||||
if (http.readyState == XMLHttpRequest.DONE) {
|
||||
if (http.status == 200) {
|
||||
location.href = "/portal/";
|
||||
} else {
|
||||
resp = JSON.parse(http.responseText);
|
||||
alert(resp.data.message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
http.open("POST", url);
|
||||
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
http.send(JSON.stringify({ "email": email, "password": password }));
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>EA Server - Register</title>
|
||||
<style>
|
||||
tbody {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body background="/bg.gif">
|
||||
<center>
|
||||
<table width="95%">
|
||||
<tbody>
|
||||
<tr bgcolor="#204020">
|
||||
<td height="20">
|
||||
<font color="white">
|
||||
Welcome!
|
||||
</font>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table width="40%" style="border: solid;margin-top:50px;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td height="20">
|
||||
Register
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="20">
|
||||
E-Mail:<input id="email" type="text">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="20">
|
||||
Password:<input id="password" type="password">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="20">
|
||||
<button id="login_btn" onclick="register()">Register</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</center>
|
||||
|
||||
<script>
|
||||
function register(){
|
||||
var http = new XMLHttpRequest();
|
||||
var url = "/api/user/register";
|
||||
let email = document.getElementById("email").value;
|
||||
let password = document.getElementById("password").value;
|
||||
http.withCredentials = true;
|
||||
http.onreadystatechange = function() {
|
||||
if(http.readyState == XMLHttpRequest.DONE){
|
||||
let resp = JSON.parse(http.responseText);
|
||||
if(http.status==200){
|
||||
alert(resp.data.message);
|
||||
location.href = "/";
|
||||
}else{
|
||||
alert(resp.data.message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
http.open("POST",url);
|
||||
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
http.send(JSON.stringify({"email":email,"password":password}));
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -1 +0,0 @@
|
|||
/* Styles File */
|
||||
|
|
@ -4,5 +4,4 @@ include 'butterflymodel'
|
|||
include 'butterflydao'
|
||||
include 'butterflycore'
|
||||
include 'butterflyserver'
|
||||
include 'butterflywebui'
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user