use of com.djrapitops.plan.delivery.web.resolver.request.URIQuery in project Plan by plan-player-analytics.
the class RequestHandler method buildRequest.
private Request buildRequest(HttpExchange exchange) {
String requestMethod = exchange.getRequestMethod();
URIPath path = new URIPath(exchange.getRequestURI().getPath());
URIQuery query = new URIQuery(exchange.getRequestURI().getRawQuery());
byte[] requestBody = readRequestBody(exchange);
WebUser user = getWebUser(exchange);
Map<String, String> headers = getRequestHeaders(exchange);
return new Request(requestMethod, path, query, user, headers, requestBody);
}
use of com.djrapitops.plan.delivery.web.resolver.request.URIQuery in project Plan by plan-player-analytics.
the class RegisterResolver method getResponse.
public Response getResponse(Request request) {
URIQuery query = request.getQuery();
Optional<String> checkCode = query.get("code");
if (checkCode.isPresent()) {
return Response.builder().setStatus(200).setJSONContent(Collections.singletonMap("success", !RegistrationBin.contains(checkCode.get()))).build();
}
URIQuery form = RequestBodyConverter.formBody(request);
String username = getUser(form, query);
boolean alreadyExists = dbSystem.getDatabase().query(WebUserQueries.fetchUser(username)).isPresent();
if (alreadyExists)
throw new BadRequestException("User already exists!");
String password = getPassword(form, query);
try {
String code = RegistrationBin.addInfoForRegistration(username, password);
return Response.builder().setStatus(200).setJSONContent(Maps.builder(String.class, Object.class).put("success", true).put("code", code).build()).build();
} catch (PassEncryptUtil.CannotPerformOperationException e) {
throw new IllegalStateException(e);
}
}
use of com.djrapitops.plan.delivery.web.resolver.request.URIQuery in project Plan by plan-player-analytics.
the class LoginResolver method getUser.
public User getUser(Request request) {
URIQuery form = RequestBodyConverter.formBody(request);
URIQuery query = request.getQuery();
String username = getUser(form, query);
String password = getPassword(form, query);
User user = dbSystem.getDatabase().query(WebUserQueries.fetchUser(username)).orElseThrow(() -> new WebUserAuthException(FailReason.USER_PASS_MISMATCH));
boolean correctPass = user.doesPasswordMatch(password);
if (!correctPass) {
throw new WebUserAuthException(FailReason.USER_PASS_MISMATCH);
}
return user;
}
Aggregations