User mgmnt fixes, login preparation
This commit is contained in:
parent
d32940383c
commit
195a208f67
4 changed files with 80 additions and 0 deletions
|
@ -111,6 +111,7 @@ public class ButtonWebsiteModule extends JavaPlugin {
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
addPage(new IndexPage());
|
addPage(new IndexPage());
|
||||||
|
TBMCCoreAPI.RegisterUserClass(WebUser.class);
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
|
||||||
this.getLogger().info("Starting webserver...");
|
this.getLogger().info("Starting webserver...");
|
||||||
server.setExecutor(
|
server.setExecutor(
|
||||||
|
|
|
@ -3,6 +3,8 @@ package buttondevteam.website.io;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
|
@ -148,4 +150,33 @@ public class IOHelper {
|
||||||
SendLogoutHeaders(exchange);
|
SendLogoutHeaders(exchange);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> parseQueryString(HttpExchange exchange) {
|
||||||
|
String qs = exchange.getRequestURI().getRawQuery();
|
||||||
|
Map<String, String> result = new HashMap<>();
|
||||||
|
if (qs == null)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
int last = 0, next, l = qs.length();
|
||||||
|
while (last < l) {
|
||||||
|
next = qs.indexOf('&', last);
|
||||||
|
if (next == -1)
|
||||||
|
next = l;
|
||||||
|
|
||||||
|
if (next > last) {
|
||||||
|
int eqPos = qs.indexOf('=', last);
|
||||||
|
try {
|
||||||
|
if (eqPos < 0 || eqPos > next)
|
||||||
|
result.put(URLDecoder.decode(qs.substring(last, next), "utf-8"), "");
|
||||||
|
else
|
||||||
|
result.put(URLDecoder.decode(qs.substring(last, eqPos), "utf-8"),
|
||||||
|
URLDecoder.decode(qs.substring(eqPos + 1, next), "utf-8"));
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException(e); // will never happen, utf-8 support is mandatory for java
|
||||||
|
}
|
||||||
|
}
|
||||||
|
last = next + 1;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
29
src/buttondevteam/website/page/LoginPage.java
Normal file
29
src/buttondevteam/website/page/LoginPage.java
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package buttondevteam.website.page;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
|
|
||||||
|
import buttondevteam.website.io.IOHelper;
|
||||||
|
import buttondevteam.website.io.Response;
|
||||||
|
|
||||||
|
public class LoginPage extends Page {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String GetName() {
|
||||||
|
return "login";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response handlePage(HttpExchange exchange) {
|
||||||
|
Map<String, String> q = IOHelper.parseQueryString(exchange);
|
||||||
|
if (q == null || !q.containsKey("type"))
|
||||||
|
return new Response(400, "400 Bad request", exchange);
|
||||||
|
String type = q.get("type");
|
||||||
|
/*if (type.equalsIgnoreCase("getstate"))
|
||||||
|
return new Response(200, "TODO", exchange); // TO!DO: Store and return a random state and check on other types
|
||||||
|
String state = q.get("state"), code = q.get("code");*/
|
||||||
|
return new Response(200, "", exchange);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
19
src/buttondevteam/website/page/ProfilePage.java
Normal file
19
src/buttondevteam/website/page/ProfilePage.java
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package buttondevteam.website.page;
|
||||||
|
|
||||||
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
|
|
||||||
|
import buttondevteam.website.io.Response;
|
||||||
|
|
||||||
|
public class ProfilePage extends Page {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String GetName() {
|
||||||
|
return "profile";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response handlePage(HttpExchange exchange) {
|
||||||
|
return new Response(200, "Under construction", exchange);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue