diff options
author | Simon Rettberg | 2015-08-03 19:12:56 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-08-03 19:12:56 +0200 |
commit | 18e2e65e2afb5eb836ce27f6ea7061120ab819be (patch) | |
tree | 3309859afb9a081459aa89d318b939caeb4fd5b3 /dozentenmodul/src/main/java/org/openslx/dozmod/Config.java | |
parent | [client] Remove accidentally commited debug code (diff) | |
download | tutor-module-18e2e65e2afb5eb836ce27f6ea7061120ab819be.tar.gz tutor-module-18e2e65e2afb5eb836ce27f6ea7061120ab819be.tar.xz tutor-module-18e2e65e2afb5eb836ce27f6ea7061120ab819be.zip |
[client] Feature: save session to skip login
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/Config.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/Config.java | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java b/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java index 3ef0edcf..928b38d1 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java @@ -25,7 +25,7 @@ public class Config { * Logger for this class */ private final static Logger LOGGER = Logger.getLogger(Config.class); - + public static final int TRANSFER_TIMEOUT = 20 * 1000; // 20s timeout for hung transfers public static interface ErrorCallback { @@ -76,7 +76,7 @@ public class Config { } } else if (osName.contains("linux")) { configPath = System.getProperty("user.home") + "/.config"; - } + } if (configPath == null || configPath.isEmpty()) { // Not Windows nor Linux, try fallback to relative path // TODO MacOS Support? @@ -84,7 +84,8 @@ public class Config { } // Check if we got a path - configFile = new File(configPath + File.separatorChar + "bwSuite" + File.separatorChar + "config.properties"); + configFile = new File(configPath + File.separatorChar + "bwSuite" + File.separatorChar + + "config.properties"); // Check if the directory exists. if (!configFile.getParentFile().exists()) { @@ -98,7 +99,7 @@ public class Config { if (!configFile.exists()) { forceSaveInternal(); } - + // Make sure all settings are saved when we exit Runtime.getRuntime().addShutdownHook(new Thread() { @Override @@ -298,6 +299,31 @@ public class Config { setString("login.method", value); } + /** + * Saves the current session, identified by the satellite server's address + * and token. + * + * @param satAddress + * @param satToken + */ + public static void saveCurrentSession(String satAddress, String satToken) { + setString("session.address", satAddress); + setString("session.token", satToken); + } + + /** + * Load a saved session. + * + * @return Saved session, or <code>null</code> if no session was saved + */ + public static SavedSession getSavedSession() { + SavedSession session = new SavedSession(getString("session.address", ""), getString("session.token", + "")); + if (session.token.isEmpty() || session.address.isEmpty()) + return null; + return session; + } + /* * Generic helpers for different data types */ @@ -372,4 +398,14 @@ public class Config { queueSave(); } + public static class SavedSession { + public final String address; + public final String token; + + public SavedSession(String address, String token) { + this.address = address; + this.token = token; + } + } + } |