Skip to content
This repository was archived by the owner on Mar 10, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WebContent/cardcast/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cardcast - PYX-Reloaded</title>
Expand Down
2 changes: 1 addition & 1 deletion WebContent/game.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title class="_title">{{Game name}} - PYX Reloaded</title>
Expand Down
2 changes: 1 addition & 1 deletion WebContent/games/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>Games - PYX-Reloaded</title>
Expand Down
3 changes: 1 addition & 2 deletions WebContent/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<!DOCTYPE html>
<html>

<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta name="google-site-verification" content="d1mgvYymY1hPvJcf0buZ-4e8RMETSFNRFz6aeD4BueI"/>
Expand Down
21 changes: 21 additions & 0 deletions WebContent/js/user.js
Original file line number Diff line number Diff line change
@@ -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;
}
36 changes: 36 additions & 0 deletions WebContent/user.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title class="_title">{{User name}} - PYX Reloaded</title>
<link rel="stylesheet" href="//unpkg.com/material-components-web@0.30.0/dist/material-components-web.min.css">
<link rel="stylesheet" href="//fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,400,500">
<link rel="stylesheet" href="/css/pyx-reloaded.css">
<script src="//cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
<script src="/js/theming.js"></script>
<script>Theming.apply();</script>
</head>
<body class="mdc-typography">
<div class="page-content">
<header class="mdc-toolbar mdc-toolbar--fixed mdc-elevation--z4">
<div class="mdc-toolbar__row">
<section class="mdc-toolbar__section mdc-toolbar__section--align-start">
<span class="mdc-toolbar__title _title">{{User name}} - PYX Reloaded</span>
</section>
</div>
</header>

<main class="mdc-toolbar-fixed-adjust">
</main>
</div>

<script src="//code.jquery.com/jquery-latest.min.js"></script>
<script src="//unpkg.com/material-components-web@0.30.0/dist/material-components-web.min.js"></script>
<script src="/js/communication.helper.js"></script>
<script src="/js/events.helper.js"></script>
<script src="/js/user.js"></script>
<script>mdc.autoInit();</script>

</body>
</html>
6 changes: 5 additions & 1 deletion src/main/java/com/gianlu/pyxreloaded/Consts.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/gianlu/pyxreloaded/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down