Search in sources :

Example 1 with SessionEntry

use of net.runelite.http.service.account.beans.SessionEntry in project runelite by runelite.

the class AuthFilter method handle.

public SessionEntry handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String runeliteAuth = request.getHeader(RuneLiteAPI.RUNELITE_AUTH);
    if (runeliteAuth == null) {
        response.sendError(401, "Access denied");
        return null;
    }
    UUID uuid = UUID.fromString(runeliteAuth);
    try (Connection con = sql2o.open()) {
        SessionEntry sessionEntry = con.createQuery("select user, uuid, created from sessions where uuid = :uuid").addParameter("uuid", uuid.toString()).executeAndFetchFirst(SessionEntry.class);
        if (sessionEntry == null) {
            response.sendError(401, "Access denied");
            return null;
        }
        Instant now = Instant.now();
        con.createQuery("update sessions set last_used = :last_used where uuid = :uuid").addParameter("last_used", Timestamp.from(now)).addParameter("uuid", uuid.toString()).executeUpdate();
        sessionEntry.setLastUsed(now);
        return sessionEntry;
    }
}
Also used : Instant(java.time.Instant) Connection(org.sql2o.Connection) UUID(java.util.UUID) SessionEntry(net.runelite.http.service.account.beans.SessionEntry)

Example 2 with SessionEntry

use of net.runelite.http.service.account.beans.SessionEntry in project runelite by runelite.

the class ConfigService method get.

@RequestMapping
public Configuration get(HttpServletRequest request, HttpServletResponse response) throws IOException {
    SessionEntry session = auth.handle(request, response);
    if (session == null) {
        return null;
    }
    List<ConfigEntry> config;
    try (Connection con = sql2o.open()) {
        config = con.createQuery("select `key`, value from config where user = :user").addParameter("user", session.getUser()).executeAndFetch(ConfigEntry.class);
    }
    return new Configuration(config);
}
Also used : ConfigEntry(net.runelite.http.api.config.ConfigEntry) Configuration(net.runelite.http.api.config.Configuration) Connection(org.sql2o.Connection) SessionEntry(net.runelite.http.service.account.beans.SessionEntry) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SessionEntry (net.runelite.http.service.account.beans.SessionEntry)2 Connection (org.sql2o.Connection)2 Instant (java.time.Instant)1 UUID (java.util.UUID)1 ConfigEntry (net.runelite.http.api.config.ConfigEntry)1 Configuration (net.runelite.http.api.config.Configuration)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1