mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-05 07:58:08 +01:00
Fix expired cookie removal
This commit is contained in:
parent
0538cea8be
commit
7aa84c27e4
@ -128,12 +128,17 @@ public class ActiveCookieStore implements SubSystem {
|
||||
Optional<User> foundUser = checkCookie(cookie);
|
||||
if (foundUser.isPresent()) {
|
||||
USERS_BY_COOKIE.remove(cookie);
|
||||
deleteCookie(foundUser.get().getUsername());
|
||||
deleteCookieByUser(foundUser.get().getUsername());
|
||||
deleteCookie(cookie);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteCookie(String username) {
|
||||
dbSystem.getDatabase().executeTransaction(CookieChangeTransaction.removeCookie(username));
|
||||
private void deleteCookie(String cookie) {
|
||||
dbSystem.getDatabase().executeTransaction(CookieChangeTransaction.removeCookie(cookie));
|
||||
}
|
||||
|
||||
private void deleteCookieByUser(String username) {
|
||||
dbSystem.getDatabase().executeTransaction(CookieChangeTransaction.removeCookieByUser(username));
|
||||
}
|
||||
|
||||
public void removeAll() {
|
||||
|
@ -20,6 +20,7 @@ import com.djrapitops.plan.storage.database.DBType;
|
||||
import com.djrapitops.plan.storage.database.sql.building.CreateTableBuilder;
|
||||
import com.djrapitops.plan.storage.database.sql.building.Sql;
|
||||
|
||||
import static com.djrapitops.plan.storage.database.sql.building.Sql.DELETE_FROM;
|
||||
import static com.djrapitops.plan.storage.database.sql.building.Sql.WHERE;
|
||||
|
||||
/**
|
||||
@ -40,13 +41,16 @@ public class CookieTable {
|
||||
COOKIE + ',' +
|
||||
EXPIRES + ") VALUES (?,?,?)";
|
||||
|
||||
public static final String DELETE_BY_USER_STATEMENT = "DELETE FROM " + TABLE_NAME +
|
||||
public static final String DELETE_BY_COOKIE_STATEMENT = DELETE_FROM + TABLE_NAME +
|
||||
WHERE + COOKIE + "=?";
|
||||
|
||||
public static final String DELETE_BY_USER_STATEMENT = DELETE_FROM + TABLE_NAME +
|
||||
WHERE + WEB_USERNAME + "=?";
|
||||
|
||||
public static final String DELETE_OLDER_STATEMENT = "DELETE FROM " + TABLE_NAME +
|
||||
public static final String DELETE_OLDER_STATEMENT = DELETE_FROM + TABLE_NAME +
|
||||
WHERE + EXPIRES + "<=?";
|
||||
|
||||
public static final String DELETE_ALL_STATEMENT = "DELETE FROM " + TABLE_NAME;
|
||||
public static final String DELETE_ALL_STATEMENT = DELETE_FROM + TABLE_NAME;
|
||||
|
||||
|
||||
private CookieTable() {
|
||||
|
@ -39,23 +39,41 @@ public class CookieChangeTransaction extends Transaction {
|
||||
return new CookieChangeTransaction(username, cookie, expires);
|
||||
}
|
||||
|
||||
public static CookieChangeTransaction removeCookie(String username) {
|
||||
public static CookieChangeTransaction removeCookieByUser(String username) {
|
||||
return new CookieChangeTransaction(username, null, null);
|
||||
}
|
||||
|
||||
public static CookieChangeTransaction removeCookie(String cookie) {
|
||||
return new CookieChangeTransaction(null, cookie, null);
|
||||
}
|
||||
|
||||
public static CookieChangeTransaction removeAll() {
|
||||
return new CookieChangeTransaction(null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
if (username == null) {
|
||||
if (username == null && cookie == null) {
|
||||
execute(new ExecStatement(CookieTable.DELETE_ALL_STATEMENT) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) {
|
||||
// No parameters
|
||||
}
|
||||
});
|
||||
} else if (username == null) {
|
||||
execute(new ExecStatement(CookieTable.DELETE_BY_COOKIE_STATEMENT) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, cookie);
|
||||
}
|
||||
});
|
||||
// Perform cleanup at the same time
|
||||
execute(new ExecStatement(CookieTable.DELETE_OLDER_STATEMENT) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setLong(1, System.currentTimeMillis());
|
||||
}
|
||||
});
|
||||
} else if (cookie == null) {
|
||||
execute(new ExecStatement(CookieTable.DELETE_BY_USER_STATEMENT) {
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user