diff --git a/pom.xml b/pom.xml index 0b6e9fa..ceeb515 100644 --- a/pom.xml +++ b/pom.xml @@ -14,8 +14,8 @@ UTF-8 - 1.7 - 1.7 + 1.8 + 1.8 diff --git a/src/main/java/xyz/thastertyn/App.java b/src/main/java/xyz/thastertyn/App.java index 56f206e..dcdb9b4 100644 --- a/src/main/java/xyz/thastertyn/App.java +++ b/src/main/java/xyz/thastertyn/App.java @@ -9,10 +9,7 @@ import xyz.thastertyn.Window.MainWindow; */ public class App { public static void main(String[] args) { - //System.out.println("Hello World!"); - - //Login l = new Login(); - //l.login(Credentials.user, Credentials.pass); + System.out.println("Hello World!"); MainWindow window = new MainWindow(); window.run(); diff --git a/src/main/java/xyz/thastertyn/Jecna/Login.java b/src/main/java/xyz/thastertyn/Jecna/Login.java index f89f4e8..8cc25be 100644 --- a/src/main/java/xyz/thastertyn/Jecna/Login.java +++ b/src/main/java/xyz/thastertyn/Jecna/Login.java @@ -43,6 +43,25 @@ public class Login { return true; } + public void saveCredentials(String user, String pass) + { + File credentials = null; + + if(System.getProperty("os.name").equals("Linux")) + { + credentials = new File("~/.local/share/jecnak/credentials.json"); + + }else if(System.getProperty("os.name").contains("Windows")) + { + credentials = new File(System.getenv("APPDATA\\jecnak\\")); + } + + if(!credentials.exists()) + { + + } + } + public String getJSESSIONID() { return Jsessionid; diff --git a/src/main/java/xyz/thastertyn/Window/Login.java b/src/main/java/xyz/thastertyn/Window/Login.java new file mode 100644 index 0000000..1253417 --- /dev/null +++ b/src/main/java/xyz/thastertyn/Window/Login.java @@ -0,0 +1,36 @@ +package xyz.thastertyn.Window; + +import com.googlecode.lanterna.gui2.WindowBasedTextGUI; + +public class Login { + + String user = ""; + String pass = ""; + + xyz.thastertyn.Jecna.Login login = new xyz.thastertyn.Jecna.Login(); + + LoginDialog dialog = new LoginDialog("Login", "Enter your username and password"); + + public void showDialog(WindowBasedTextGUI textGUI) + { + String[] input = dialog.showDialog(textGUI); + + user = input[0]; + pass = input[1]; + + login(); + } + + private void login() + { + login.login(user, pass); + + user = null; + pass = null; + } + + public String getJsessionId() + { + return login.getJSESSIONID(); + } +} diff --git a/src/main/java/xyz/thastertyn/Window/LoginDialog.java b/src/main/java/xyz/thastertyn/Window/LoginDialog.java new file mode 100644 index 0000000..f7296f4 --- /dev/null +++ b/src/main/java/xyz/thastertyn/Window/LoginDialog.java @@ -0,0 +1,112 @@ +package xyz.thastertyn.Window; + +import com.googlecode.lanterna.TerminalSize; +import com.googlecode.lanterna.gui2.Button; +import com.googlecode.lanterna.gui2.EmptySpace; +import com.googlecode.lanterna.gui2.GridLayout; +import com.googlecode.lanterna.gui2.Label; +import com.googlecode.lanterna.gui2.LocalizedString; +import com.googlecode.lanterna.gui2.Panel; +import com.googlecode.lanterna.gui2.TextBox; +import com.googlecode.lanterna.gui2.WindowBasedTextGUI; +import com.googlecode.lanterna.gui2.GridLayout.Alignment; +import com.googlecode.lanterna.gui2.dialogs.DialogWindow; +import com.googlecode.lanterna.gui2.dialogs.MessageDialog; +import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton; + +public class LoginDialog extends DialogWindow { + + private TextBox username; + private TextBox password; + private String user; + private String pass; + + LoginDialog( + String title, + String description + ) + { + super(title); + this.user = null; + this.pass = null; + this.username = new TextBox(); + this.password = new TextBox().setMask('*'); + + Panel buttonPanel = new Panel(); + buttonPanel.setLayoutManager((new GridLayout(2).setHorizontalSpacing(1))); + buttonPanel + .addComponent((new Button(LocalizedString.OK.toString(), this::onOK) + .setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.CENTER, GridLayout.Alignment.CENTER, true, false)))); + buttonPanel.addComponent(new Button(LocalizedString.Cancel.toString(), this::onCancel)); + + Panel mainPanel = new Panel(); + mainPanel.setLayoutManager(new GridLayout(1).setLeftMarginSize(1).setRightMarginSize(1)); + + if(description != null) + { + mainPanel.addComponent(new Label(description)); + } + + mainPanel.addComponent(new EmptySpace(TerminalSize.ONE)); + + Panel userPanel = new Panel() + .setLayoutManager(new GridLayout(3)) + .setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.FILL, Alignment.CENTER, true, false)); + + this.username.setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.FILL, GridLayout.Alignment.CENTER, true, false)); + + userPanel.addComponent(new Label("Username: ")) + .addComponent(username) + .addTo(mainPanel); + + this.password.setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.FILL, GridLayout.Alignment.CENTER, true, false)) + .addTo(mainPanel); + + Panel passPanel = new Panel() + .setLayoutManager(new GridLayout(3)) + .setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.FILL, Alignment.CENTER, true, false)); + + passPanel.addComponent(new Label("Password: ")) + .addComponent(password) + .addTo(mainPanel); + + mainPanel.addComponent(new EmptySpace(TerminalSize.ONE)); + + buttonPanel.setLayoutData( + GridLayout.createLayoutData( + Alignment.END, + Alignment.CENTER, + false, false)) + .addTo(mainPanel); + + setComponent(mainPanel); + } + + public void onOK() + { + if(username.getText().isEmpty() || password.getText().isEmpty()) + { + MessageDialog.showMessageDialog(getTextGUI(), getTitle(), "Username and password cannot be blank", MessageDialogButton.OK); + return; + } + + this.user = username.getText(); + this.pass = password.getText(); + + close(); + } + + public void onCancel() + { + close(); + } + + @Override + public String[] showDialog(WindowBasedTextGUI textGUI) + { + user = null; + pass = null; + super.showDialog(textGUI); + return new String[] {user, pass}; + } +} diff --git a/src/main/java/xyz/thastertyn/Window/MainWindow.java b/src/main/java/xyz/thastertyn/Window/MainWindow.java index 44d7924..1b274cb 100644 --- a/src/main/java/xyz/thastertyn/Window/MainWindow.java +++ b/src/main/java/xyz/thastertyn/Window/MainWindow.java @@ -5,6 +5,7 @@ import java.util.Arrays; import com.googlecode.lanterna.TextColor; import com.googlecode.lanterna.gui2.BasicWindow; +import com.googlecode.lanterna.gui2.Borders; import com.googlecode.lanterna.gui2.DefaultWindowManager; import com.googlecode.lanterna.gui2.Direction; import com.googlecode.lanterna.gui2.EmptySpace; @@ -49,16 +50,17 @@ public class MainWindow { final Panel content = new Panel(); mainPanel.addComponent(content); - Login l = new Login(); - l.login(Credentials.user, Credentials.pass); - Rozvrh r = new Rozvrh(); - r.download(l.getJSESSIONID()); + xyz.thastertyn.Window.Login login = new xyz.thastertyn.Window.Login(); + + /*Rozvrh r = new Rozvrh(); + r.download(login.getJsessionId()); - content.addComponent(r.getPanel()); - + content.addComponent(r.getPanel());*/ + // Create gui and start gui final MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLACK_BRIGHT)); + login.showDialog(gui); /*KeyStroke k = terminal.readInput(); if(k.equals(KeyStroke.fromString(""))) { diff --git a/target/classes/xyz/thastertyn/App.class b/target/classes/xyz/thastertyn/App.class index 356a649..8c05ee8 100644 Binary files a/target/classes/xyz/thastertyn/App.class and b/target/classes/xyz/thastertyn/App.class differ diff --git a/target/classes/xyz/thastertyn/Connection.class b/target/classes/xyz/thastertyn/Connection.class index 2fe3720..242c415 100644 Binary files a/target/classes/xyz/thastertyn/Connection.class and b/target/classes/xyz/thastertyn/Connection.class differ diff --git a/target/classes/xyz/thastertyn/Download.class b/target/classes/xyz/thastertyn/Download.class index 6c11016..51b02c3 100644 Binary files a/target/classes/xyz/thastertyn/Download.class and b/target/classes/xyz/thastertyn/Download.class differ diff --git a/target/classes/xyz/thastertyn/Jecna/Dochazka.class b/target/classes/xyz/thastertyn/Jecna/Dochazka.class index 028a458..5e44996 100644 Binary files a/target/classes/xyz/thastertyn/Jecna/Dochazka.class and b/target/classes/xyz/thastertyn/Jecna/Dochazka.class differ diff --git a/target/classes/xyz/thastertyn/Jecna/Downloader.class b/target/classes/xyz/thastertyn/Jecna/Downloader.class index dc97d60..b6a040f 100644 Binary files a/target/classes/xyz/thastertyn/Jecna/Downloader.class and b/target/classes/xyz/thastertyn/Jecna/Downloader.class differ diff --git a/target/classes/xyz/thastertyn/Jecna/Login.class b/target/classes/xyz/thastertyn/Jecna/Login.class index 4370810..f8ffa27 100644 Binary files a/target/classes/xyz/thastertyn/Jecna/Login.class and b/target/classes/xyz/thastertyn/Jecna/Login.class differ diff --git a/target/classes/xyz/thastertyn/Jecna/Rozvrh.class b/target/classes/xyz/thastertyn/Jecna/Rozvrh.class index 54fa3d9..a2940fd 100644 Binary files a/target/classes/xyz/thastertyn/Jecna/Rozvrh.class and b/target/classes/xyz/thastertyn/Jecna/Rozvrh.class differ diff --git a/target/classes/xyz/thastertyn/Jecna/Znamky.class b/target/classes/xyz/thastertyn/Jecna/Znamky.class index a1b1bbd..bc021b4 100644 Binary files a/target/classes/xyz/thastertyn/Jecna/Znamky.class and b/target/classes/xyz/thastertyn/Jecna/Znamky.class differ diff --git a/target/classes/xyz/thastertyn/Predmet.class b/target/classes/xyz/thastertyn/Predmet.class index cd35ab9..8ffad90 100644 Binary files a/target/classes/xyz/thastertyn/Predmet.class and b/target/classes/xyz/thastertyn/Predmet.class differ diff --git a/target/classes/xyz/thastertyn/RozvrhDownload.class b/target/classes/xyz/thastertyn/RozvrhDownload.class index d6fbc4c..29eccbb 100644 Binary files a/target/classes/xyz/thastertyn/RozvrhDownload.class and b/target/classes/xyz/thastertyn/RozvrhDownload.class differ diff --git a/target/classes/xyz/thastertyn/Tuple/Pair.class b/target/classes/xyz/thastertyn/Tuple/Pair.class index 2171d55..7b59897 100644 Binary files a/target/classes/xyz/thastertyn/Tuple/Pair.class and b/target/classes/xyz/thastertyn/Tuple/Pair.class differ diff --git a/target/classes/xyz/thastertyn/Window/Login.class b/target/classes/xyz/thastertyn/Window/Login.class new file mode 100644 index 0000000..efdcebf Binary files /dev/null and b/target/classes/xyz/thastertyn/Window/Login.class differ diff --git a/target/classes/xyz/thastertyn/Window/LoginDialog.class b/target/classes/xyz/thastertyn/Window/LoginDialog.class new file mode 100644 index 0000000..926ccde Binary files /dev/null and b/target/classes/xyz/thastertyn/Window/LoginDialog.class differ diff --git a/target/classes/xyz/thastertyn/Window/MainWindow.class b/target/classes/xyz/thastertyn/Window/MainWindow.class index 583b78f..299a09c 100644 Binary files a/target/classes/xyz/thastertyn/Window/MainWindow.class and b/target/classes/xyz/thastertyn/Window/MainWindow.class differ diff --git a/target/classes/xyz/thastertyn/Window/Rozvrh.class b/target/classes/xyz/thastertyn/Window/Rozvrh.class index 6982ef3..3a4dab8 100644 Binary files a/target/classes/xyz/thastertyn/Window/Rozvrh.class and b/target/classes/xyz/thastertyn/Window/Rozvrh.class differ diff --git a/target/classes/xyz/thastertyn/Window/RozvrhTableRenderer.class b/target/classes/xyz/thastertyn/Window/RozvrhTableRenderer.class deleted file mode 100644 index c4225e7..0000000 Binary files a/target/classes/xyz/thastertyn/Window/RozvrhTableRenderer.class and /dev/null differ diff --git a/target/classes/xyz/thastertyn/Window/WindowListener.class b/target/classes/xyz/thastertyn/Window/WindowListener.class deleted file mode 100644 index ae178ca..0000000 Binary files a/target/classes/xyz/thastertyn/Window/WindowListener.class and /dev/null differ diff --git a/target/test-classes/xyz/thastertyn/AppTest.class b/target/test-classes/xyz/thastertyn/AppTest.class index 91e51b6..e343e48 100644 Binary files a/target/test-classes/xyz/thastertyn/AppTest.class and b/target/test-classes/xyz/thastertyn/AppTest.class differ