diff --git a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/Nodes/Nodes.java b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/Nodes/Nodes.java index 9e87d6ef7e8706dd8d461886cca6264000055882..0f8d98a872d2608afa2877528d6b977927c55a14 100644 --- a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/Nodes/Nodes.java +++ b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/Nodes/Nodes.java @@ -11,6 +11,7 @@ public class Nodes { // Add a list of nodes public static void AddNodes(List<Node> list) { + if(list == null) return; for(Node n : list) { AddNode(n); } diff --git a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/LoginPage.java b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/LoginPage.java index c5c33610b22289d79c6fe1c46c2a1624d65f3e2f..277a3f363df3d0212fd4137da43cd739d1ce7353 100644 --- a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/LoginPage.java +++ b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/LoginPage.java @@ -86,6 +86,7 @@ public class LoginPage implements ActionListener, MouseListener { actionButton.addActionListener(this); actionButton.addMouseListener(this); actionButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + frame.getRootPane().setDefaultButton(actionButton); bottomPanel.setBackground(Color.black); bottomPanel.setBounds(0,0,width, height); @@ -177,6 +178,11 @@ public class LoginPage implements ActionListener, MouseListener { loginSwitch = !loginSwitch; } + /* + * Sends login information to the server + * if the credentials are valid, save the user information and token + * and open welcomepage + */ private boolean handleLogin() { Map<String, String> credentials = loginPanel.getCredentials(); if(credentials.get("email").equals("") || credentials.get("password").equals("")) return false; @@ -184,7 +190,7 @@ public class LoginPage implements ActionListener, MouseListener { boolean valid = HttpRequests.LoginRequest(credentials.get("email"), credentials.get("password")); if (valid) { frame.dispose(); - WelcomePage welcomePage = new WelcomePage(); + new WelcomePage(); } else { messageLabel.setText("Invalid username or password"); loginPanel.ClearFields(); @@ -192,6 +198,9 @@ public class LoginPage implements ActionListener, MouseListener { return valid; } + /* + * Sends the registration info to the server + */ private boolean handleRegister() { if (registerPanel.validateForm()) { Map<String, String> userInfo = registerPanel.getUserInfo(); diff --git a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/WelcomePage.java b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/WelcomePage.java index 9c4476d443a9a5191966066b63c67de24040eb03..7dc5ae654a0788ef8c3c1e085a046d0f770071ab 100644 --- a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/WelcomePage.java +++ b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/frames/WelcomePage.java @@ -52,7 +52,7 @@ public class WelcomePage implements MouseListener, ActionListener { private static JFrame frame; private static JLabel chosen_label; - private static final Timer timer = new Timer(); + private static Timer timer; private static NodeDataFrame nodeDataFrame = new NodeDataFrame(leftPanelWidth, topPanelHeight, width-leftPanelWidth, height-topPanelHeight-bottomPanelHeight); private static NodeSettingsFrame nodeSettingFrame = new NodeSettingsFrame(width-leftPanelWidth, height-topPanelHeight-bottomPanelHeight); @@ -203,6 +203,7 @@ public class WelcomePage implements MouseListener, ActionListener { * Polls the backend for new data every given interval */ private static void PollData() { + timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { int timeRemaining = pollInterval; public void run() { @@ -231,9 +232,16 @@ public class WelcomePage implements MouseListener, ActionListener { } else if(arg0.getSource() == friendsLabel && arg0.getSource() != chosen_label) { cl.show(stagePanel, "3"); setActiveScene(friendsLabel); + } else if(arg0.getSource() == helpLabel) { + showHelpDialog(); + } else if(arg0.getSource() == settingsLabel) { + // TODO: make settings for user information updating } } + private static void showHelpDialog() { + // TODO: + } /* * Sets a navbar item as chosen and changes its colors accordingly diff --git a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/httpRequests/HttpRequests.java b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/httpRequests/HttpRequests.java index 477bf1afcbe881d7477a94206ad954127881fa05..3e815b01c65574e66fbd370709381e5c2cc760c0 100644 --- a/WatcherGui/src/main/java/com/joelhelkala/watcherGui/httpRequests/HttpRequests.java +++ b/WatcherGui/src/main/java/com/joelhelkala/watcherGui/httpRequests/HttpRequests.java @@ -221,6 +221,11 @@ public class HttpRequests { response.append(responseLine.trim()); } } + /*if (con.getResponseCode() == 403) { + WelcomePage.TimedOutSession(); + // Set success to true so error dialog wont be shown + return null; + }*/ data = new JSONArray(response.toString()); con.disconnect(); } catch (MalformedURLException e) { diff --git a/watcherServer/src/main/java/com/joelhelkala/watcherServer/security/config/WebSecurityConfig.java b/watcherServer/src/main/java/com/joelhelkala/watcherServer/security/config/WebSecurityConfig.java index 680b1bdad3bbab2ee4319b90c386d2b97b3272e8..181b489e6c1b566a557629ec09d007bca4c54821 100644 --- a/watcherServer/src/main/java/com/joelhelkala/watcherServer/security/config/WebSecurityConfig.java +++ b/watcherServer/src/main/java/com/joelhelkala/watcherServer/security/config/WebSecurityConfig.java @@ -44,6 +44,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { http.authorizeRequests().antMatchers("/api/v*/registration/**").permitAll(); // --------------------------- + http.authorizeRequests().antMatchers("/api/v*/nodeData").permitAll(); + http.authorizeRequests().antMatchers("/api/v*/nodeData/**").permitAll(); + // GET requests to appuser endpoint should have ADMIN roles // TODO: This does not work I think