From 4b3ad51c3e2d7c610127a4b94934cb3d2ef5fd8e Mon Sep 17 00:00:00 2001 From: Gianlu Date: Sat, 3 Mar 2018 16:08:12 +0100 Subject: [PATCH] Some stuff --- WebContent/cardcast/index.html | 2 +- WebContent/game.html | 2 +- WebContent/games/index.html | 2 +- WebContent/index.html | 3 +- WebContent/js/user.js | 21 +++++++++++ WebContent/user.html | 36 +++++++++++++++++++ pom.xml | 3 +- .../java/com/gianlu/pyxreloaded/Consts.java | 6 +++- .../java/com/gianlu/pyxreloaded/Server.java | 4 +++ .../handlers/GetUserInfoHandler.java | 29 +++++++++++++++ .../gianlu/pyxreloaded/handlers/Handlers.java | 1 + .../gianlu/pyxreloaded/server/Parameters.java | 10 +++++- 12 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 WebContent/js/user.js create mode 100644 WebContent/user.html create mode 100644 src/main/java/com/gianlu/pyxreloaded/handlers/GetUserInfoHandler.java diff --git a/WebContent/cardcast/index.html b/WebContent/cardcast/index.html index abe320c..9cf3c8d 100644 --- a/WebContent/cardcast/index.html +++ b/WebContent/cardcast/index.html @@ -1,5 +1,5 @@ - + Cardcast - PYX-Reloaded diff --git a/WebContent/game.html b/WebContent/game.html index 09740ff..76cc205 100644 --- a/WebContent/game.html +++ b/WebContent/game.html @@ -1,5 +1,5 @@ - + {{Game name}} - PYX Reloaded diff --git a/WebContent/games/index.html b/WebContent/games/index.html index 9e15648..bdf84dd 100644 --- a/WebContent/games/index.html +++ b/WebContent/games/index.html @@ -1,5 +1,5 @@ - + Games - PYX-Reloaded diff --git a/WebContent/index.html b/WebContent/index.html index 1989bb7..d98e7e7 100644 --- a/WebContent/index.html +++ b/WebContent/index.html @@ -1,6 +1,5 @@ - - + diff --git a/WebContent/js/user.js b/WebContent/js/user.js new file mode 100644 index 0000000..a4174b1 --- /dev/null +++ b/WebContent/js/user.js @@ -0,0 +1,21 @@ +class UserManager { + + constructor(nickname) { + this.nickname = nickname; + } + + setup() { + Requester.request("gui", {"n": this.nickname}, (data) => { + + }, (error) => { + + }); + } +} + +const userManager = new UserManager(getLastPathSegment()); +userManager.setup(); + +function getLastPathSegment() { + return decodeURIComponent(new RegExp('[^\\/]+(?=\\/$|$)').exec(window.location.href) || [null, '']) || null; +} \ No newline at end of file diff --git a/WebContent/user.html b/WebContent/user.html new file mode 100644 index 0000000..84ffb75 --- /dev/null +++ b/WebContent/user.html @@ -0,0 +1,36 @@ + + + + + {{User name}} - PYX Reloaded + + + + + + + + + +
+
+
+
+ {{User name}} - PYX Reloaded +
+
+
+ +
+
+
+ + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6e9354a..cdb1af7 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,6 @@ UTF-8 - 1.4.21.Final 1.8 1.8 @@ -115,7 +114,7 @@ io.undertow undertow-core - ${undertow.version} + 1.4.21.Final diff --git a/src/main/java/com/gianlu/pyxreloaded/Consts.java b/src/main/java/com/gianlu/pyxreloaded/Consts.java index eee2f55..6f920c6 100644 --- a/src/main/java/com/gianlu/pyxreloaded/Consts.java +++ b/src/main/java/com/gianlu/pyxreloaded/Consts.java @@ -569,7 +569,11 @@ public enum Operation { /** * Create an user account. */ - CREATE_ACCOUNT("ca"); + CREATE_ACCOUNT("ca"), + /** + * Retrieves user info. + */ + GET_USER_INFO("gui"); private final String op; diff --git a/src/main/java/com/gianlu/pyxreloaded/Server.java b/src/main/java/com/gianlu/pyxreloaded/Server.java index e69f8d0..5120269 100644 --- a/src/main/java/com/gianlu/pyxreloaded/Server.java +++ b/src/main/java/com/gianlu/pyxreloaded/Server.java @@ -94,6 +94,10 @@ public static void main(String[] args) throws IOException, SQLException, Unrecov RoutingHandler router = new RoutingHandler(); router.setFallbackHandler(pathHandler) + .get("/user/{nickname}/", exchange -> { + exchange.setRelativePath("/user.html"); + resourceHandler.handleRequest(exchange); + }) .get("/game/{gid}/", exchange -> { exchange.setRelativePath("/game.html"); resourceHandler.handleRequest(exchange); diff --git a/src/main/java/com/gianlu/pyxreloaded/handlers/GetUserInfoHandler.java b/src/main/java/com/gianlu/pyxreloaded/handlers/GetUserInfoHandler.java new file mode 100644 index 0000000..9473bfb --- /dev/null +++ b/src/main/java/com/gianlu/pyxreloaded/handlers/GetUserInfoHandler.java @@ -0,0 +1,29 @@ +package com.gianlu.pyxreloaded.handlers; + +import com.gianlu.pyxreloaded.Consts; +import com.gianlu.pyxreloaded.data.JsonWrapper; +import com.gianlu.pyxreloaded.data.User; +import com.gianlu.pyxreloaded.server.Annotations; +import com.gianlu.pyxreloaded.server.BaseCahHandler; +import com.gianlu.pyxreloaded.server.BaseJsonHandler; +import com.gianlu.pyxreloaded.server.Parameters; +import com.gianlu.pyxreloaded.singletons.UsersWithAccount; +import io.undertow.server.HttpServerExchange; + +public class GetUserInfoHandler extends BaseHandler { + public static final String OP = Consts.Operation.GET_USER_INFO.toString(); + private final UsersWithAccount accounts; + + public GetUserInfoHandler(@Annotations.UsersWithAccount UsersWithAccount accounts) { + this.accounts = accounts; + } + + @Override + public JsonWrapper handle(User requester, Parameters params, HttpServerExchange exchange) throws BaseJsonHandler.StatusException { + String nickname = params.getStringNotNull(Consts.GeneralKeys.NICKNAME); + + if (!accounts.hasNickname(nickname)) throw new BaseCahHandler.CahException(Consts.ErrorCode.NO_SUCH_USER); + + return new JsonWrapper(Consts.GeneralKeys.NICKNAME, nickname); + } +} diff --git a/src/main/java/com/gianlu/pyxreloaded/handlers/Handlers.java b/src/main/java/com/gianlu/pyxreloaded/handlers/Handlers.java index 37160af..7da51e1 100644 --- a/src/main/java/com/gianlu/pyxreloaded/handlers/Handlers.java +++ b/src/main/java/com/gianlu/pyxreloaded/handlers/Handlers.java @@ -41,6 +41,7 @@ public class Handlers { LIST.put(GameOptionsSuggestionDecisionHandler.OP, GameOptionsSuggestionDecisionHandler.class); LIST.put(GetSuggestedGameOptionsHandler.OP, GetSuggestedGameOptionsHandler.class); LIST.put(CreateAccountHandler.OP, CreateAccountHandler.class); + LIST.put(GetUserInfoHandler.OP, GetUserInfoHandler.class); SKIP_USER_CHECK = new ArrayList<>(); SKIP_USER_CHECK.add(RegisterHandler.OP); diff --git a/src/main/java/com/gianlu/pyxreloaded/server/Parameters.java b/src/main/java/com/gianlu/pyxreloaded/server/Parameters.java index 4334709..517951d 100644 --- a/src/main/java/com/gianlu/pyxreloaded/server/Parameters.java +++ b/src/main/java/com/gianlu/pyxreloaded/server/Parameters.java @@ -3,6 +3,7 @@ import com.gianlu.pyxreloaded.Consts; import io.undertow.server.HttpServerExchange; import io.undertow.util.QueryParameterUtils; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.IOException; @@ -39,10 +40,17 @@ public boolean has(Consts.ReceivableKey key) { } @Nullable - public String get(Consts.ReceivableKey key) { + public String getString(Consts.ReceivableKey key) { return get(key.toString()); } + @NotNull + public String getStringNotNull(Consts.ReceivableKey key) throws BaseCahHandler.CahException { + String val = getString(key); + if (val == null) throw new BaseCahHandler.CahException(Consts.ErrorCode.BAD_REQUEST); + else return val; + } + public boolean getBoolean(Consts.ReceivableKey key, boolean fallback) { return getBoolean(key.toString(), fallback); }