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 514a8be..0f82d40 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/src/main/java/com/gianlu/pyxreloaded/Consts.java b/src/main/java/com/gianlu/pyxreloaded/Consts.java index 6bc1c70..5668343 100644 --- a/src/main/java/com/gianlu/pyxreloaded/Consts.java +++ b/src/main/java/com/gianlu/pyxreloaded/Consts.java @@ -565,7 +565,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 837a062..ec2a6ea 100644 --- a/src/main/java/com/gianlu/pyxreloaded/Server.java +++ b/src/main/java/com/gianlu/pyxreloaded/Server.java @@ -100,6 +100,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);