From 21a7ec7aaccf708951e3e9d71e7c26ae0af462bc Mon Sep 17 00:00:00 2001
From: joalhelk <joalhelk@jyu.fi>
Date: Sat, 12 Feb 2022 19:48:21 +0200
Subject: [PATCH] updates to ui

---
 .../java/com/joelhelkala/watcherGui/Nodes/Nodes.java  |  1 +
 .../com/joelhelkala/watcherGui/frames/LoginPage.java  | 11 ++++++++++-
 .../joelhelkala/watcherGui/frames/WelcomePage.java    | 10 +++++++++-
 .../watcherGui/httpRequests/HttpRequests.java         |  5 +++++
 .../security/config/WebSecurityConfig.java            |  3 +++
 5 files changed, 28 insertions(+), 2 deletions(-)

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 9e87d6e..0f8d98a 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 c5c3361..277a3f3 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 9c4476d..7dc5ae6 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 477bf1a..3e815b0 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 680b1bd..181b489 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
-- 
GitLab