Search in sources :

Example 1 with URIQuery

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);
}
Also used : URIPath(com.djrapitops.plan.delivery.web.resolver.request.URIPath) Request(com.djrapitops.plan.delivery.web.resolver.request.Request) WebUser(com.djrapitops.plan.delivery.web.resolver.request.WebUser) URIQuery(com.djrapitops.plan.delivery.web.resolver.request.URIQuery)

Example 2 with URIQuery

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);
    }
}
Also used : BadRequestException(com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException) PassEncryptUtil(com.djrapitops.plan.utilities.PassEncryptUtil) URIQuery(com.djrapitops.plan.delivery.web.resolver.request.URIQuery)

Example 3 with URIQuery

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;
}
Also used : User(com.djrapitops.plan.delivery.domain.auth.User) WebUserAuthException(com.djrapitops.plan.exceptions.WebUserAuthException) URIQuery(com.djrapitops.plan.delivery.web.resolver.request.URIQuery)

Aggregations

URIQuery (com.djrapitops.plan.delivery.web.resolver.request.URIQuery)3 User (com.djrapitops.plan.delivery.domain.auth.User)1 BadRequestException (com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException)1 Request (com.djrapitops.plan.delivery.web.resolver.request.Request)1 URIPath (com.djrapitops.plan.delivery.web.resolver.request.URIPath)1 WebUser (com.djrapitops.plan.delivery.web.resolver.request.WebUser)1 WebUserAuthException (com.djrapitops.plan.exceptions.WebUserAuthException)1 PassEncryptUtil (com.djrapitops.plan.utilities.PassEncryptUtil)1