Added option to save credentials

This commit is contained in:
JKetelaar
2014-12-25 13:40:12 +01:00
parent 4905e55bbf
commit a4d606e67c
3 changed files with 28 additions and 20 deletions
+27 -1
View File
@@ -1,15 +1,19 @@
package org.parabot;
import org.parabot.core.Configuration;
import org.parabot.core.Core;
import org.parabot.core.Directories;
import org.parabot.core.forum.AccountManager;
import org.parabot.core.ui.BotUI;
import org.parabot.core.ui.ServerSelector;
import org.parabot.core.ui.utils.UILog;
import org.parabot.environment.api.utils.WebUtil;
import javax.swing.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.net.URL;
/**
* Parabot v2.1
@@ -48,7 +52,13 @@ public final class Landing {
Core.verbose("Validating account manager...");
AccountManager.validate();
if (username != null && password != null) {
if (getCredentials() != null && getCredentials().length == 2){
if ((username = getCredentials()[0]) != null && (password = getCredentials()[1]) != null){
new BotUI(username, password);
}
username = null;
password = null;
}else if (username != null && password != null) {
new BotUI(username, password);
username = null;
password = null;
@@ -59,6 +69,22 @@ public final class Landing {
new BotUI(null, null);
}
/**
* Returns an array of string containing only the username and password
* @return String array with username and password
*/
private static String[] getCredentials(){
try {
BufferedReader bufferedReader = WebUtil.getReader(new URL(Configuration.GET_PASSWORD));
if (bufferedReader.readLine() != null){
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private static void parseArgs(String... args) {
for (int i = 0; i < args.length; i++) {
final String arg = args[i].toLowerCase();
@@ -14,6 +14,7 @@ public class Configuration {
public static final String GET_SERVER_PROVIDER_INFO = "http://bdn.parabot.org/api/get.php?action=server_information&name=";
public static final String GET_BOT_VERSION = "http://bot.parabot.org/version.txt";
public static final String REGISTRATION_PAGE = "https://www.parabot.org/community/index.php?app=core&module=global&section=register";
public static final String GET_PASSWORD = "http://bdn.parabot.org/api/get.php?action=password";
public static final double BOT_VERSION = 2.1;
}
-19
View File
@@ -120,25 +120,6 @@ public class Core {
e.printStackTrace();
}
}
//TODO Get checksum from BDN and verify
// BufferedReader br = WebUtil.getReader(Configuration.GET_BOT_VERSION);
// try {
// double version = Double.parseDouble(br.readLine());
// if (Configuration.BOT_VERSION != version) {
// Core.verbose("Updates available...");
// return false;
// }
// } catch (NumberFormatException | IOException e) {
// e.printStackTrace();
// } finally {
// try {
// br.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
return true;
}