Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Commit

Permalink
Prompt for user key
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeDane committed Jan 28, 2014
1 parent eba08cf commit aecb73e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/net/hearthstats/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,15 @@ public static void setCheckForUpdates(boolean b) {
e.printStackTrace();
}
}

public static void setUserKey(String userkey) {
// TODO Auto-generated method stub
_getIni().put("API", "userkey", userkey);
try {
_getIni().store();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
56 changes: 48 additions & 8 deletions src/net/hearthstats/Monitor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.hearthstats;

import java.net.URI;
import java.net.URISyntaxException;
import java.awt.AWTException;
import java.awt.Desktop;
import java.awt.FlowLayout;
Expand Down Expand Up @@ -73,17 +74,56 @@ public void start() throws IOException {
_analyzer.addObserver(this);
_hsHelper.addObserver(this);

// prompt user to change userkey
if(Config.getUserKey().matches("your_userkey_here")) {
_log("Config Error: your_userkey_here in config.ini must be replaced");
JOptionPane.showMessageDialog(null, "HearthStats.net Uploader Error:\n\nYou need to change [userkey] in config.ini\n\nSee readme.md for instructions");
System.exit(0);
}

_pollHearthstone();
_checkForUserKey();

}

private boolean _checkForUserKey() {
if(Config.getUserKey().equals("your_userkey_here")) {
_log("Userkey yet not entered");

JOptionPane.showMessageDialog(null,
"HearthStats.net Uploader Error:\n\n" +
"You need to enter your User Key\n\n" +
"Get it at http://beta.hearthstats.net/profiles");

// Create Desktop object
Desktop d = Desktop.getDesktop();
// Browse a URL, say google.com
try {
d.browse(new URI("http://beta.hearthstats.net/profiles"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

String[] options = {"OK", "Cancel"};
JPanel panel = new JPanel();
JLabel lbl = new JLabel("User Key");
JTextField txt = new JTextField(10);
panel.add(lbl);
panel.add(txt);
int selectedOption = JOptionPane.showOptionDialog(null, panel, "Enter your user key", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]);
if(selectedOption == 0) {
String userkey = txt.getText();
if(userkey.isEmpty()) {
_checkForUserKey();
} else {
Config.setUserKey(userkey);
_log("Userkey stored");
_pollHearthstone();
}
} else {
System.exit(0);
}
return false;
}
return true;
}

private void _getFileContents(String path) {

}
Expand Down

0 comments on commit aecb73e

Please sign in to comment.