Add configurations for basic authentication
This commit is contained in:
@@ -31,12 +31,9 @@ public class Application extends javafx.application.Application {
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
fxmlLoader.setLocation(this.getClass().getClassLoader().getResource("fxml/sample.fxml"));
|
||||
|
||||
rootNode = fxmlLoader.load();
|
||||
|
||||
primaryStage.setTitle("GoGreen");
|
||||
primaryStage.setTitle("Greenify");
|
||||
Scene scene = new Scene(rootNode);
|
||||
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
@@ -6,11 +6,12 @@ import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@Controller
|
||||
public class DashBoardController {
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
private int count = 0;
|
||||
|
||||
@FXML
|
||||
public AnchorPane menuBar;
|
||||
@@ -18,31 +19,22 @@ public class DashBoardController {
|
||||
public AnchorPane userPane;
|
||||
public AnchorPane activitiesPane;
|
||||
public Label welcomebacktext;
|
||||
// public Button addActivityButton;
|
||||
// public ComboBox addActivity;
|
||||
|
||||
@FXML
|
||||
public Button dashboardButton;
|
||||
public Button activitiesButton;
|
||||
public Button userButton;
|
||||
public Button veganMealButton;
|
||||
public Label counter;
|
||||
public Label scoreField;
|
||||
|
||||
// DropShadow shadow = new DropShadow();
|
||||
|
||||
|
||||
/**
|
||||
* displays the dashboard pane.
|
||||
* @param event the event (clicking the button)
|
||||
*/
|
||||
public void displayDashboard(ActionEvent event) {
|
||||
|
||||
System.out.println("display dashboard");
|
||||
dashboardPane.setVisible(true);
|
||||
userPane.setVisible(false);
|
||||
activitiesPane.setVisible(false);
|
||||
|
||||
|
||||
// welcomebacktext.setText("Welcome back, " + UserController.getUsernameText() + "!");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,14 +59,15 @@ public class DashBoardController {
|
||||
activitiesPane.setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
// public void addShadow(MouseEvent event) {
|
||||
// userButton.setEffect(shadow);
|
||||
// }
|
||||
//
|
||||
// public void removeShadow(MouseEvent event) {
|
||||
// userButton.setEffect(null);
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* adds a vegetarian meal.
|
||||
* @param event the event (clicking the button)
|
||||
*/
|
||||
public void addVeganMeal(ActionEvent event) {
|
||||
count++;
|
||||
counter.setText("Count: " + count);
|
||||
UserService service = new UserService();
|
||||
service.addVeganMeal(null, null);
|
||||
System.out.println("Vegetarian meal is added");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,7 @@ public class RegisterWindowController {
|
||||
*/
|
||||
@FXML
|
||||
public void handleSignUpButton(ActionEvent event) {
|
||||
// System.out.println("pressed sign up button!");
|
||||
|
||||
//set the window to the current window (for displaying the alerts)
|
||||
//set the window to the current window (for displaying the alerts)
|
||||
Window owner = signupButton.getScene().getWindow();
|
||||
//check if the username field is empty
|
||||
if (userNameText.getText().isEmpty()) {
|
||||
@@ -44,9 +42,6 @@ public class RegisterWindowController {
|
||||
"Please enter a username!");
|
||||
return;
|
||||
}
|
||||
// else {
|
||||
// System.out.println("username is " + userNameText.getText());
|
||||
// }
|
||||
|
||||
//check if the password field is empty
|
||||
if (passwordField.getText().isEmpty()) {
|
||||
@@ -55,9 +50,6 @@ public class RegisterWindowController {
|
||||
"Please enter a password!");
|
||||
return;
|
||||
}
|
||||
// else {
|
||||
// System.out.println("password is " + passwordField.getText());
|
||||
// }
|
||||
|
||||
//check if the two password fields are equal
|
||||
if (!passwordField.getText().equals(passwordField2.getText())) {
|
||||
@@ -66,11 +58,6 @@ public class RegisterWindowController {
|
||||
"Please make sure the passwords entered are the same!");
|
||||
return;
|
||||
}
|
||||
// else {
|
||||
// System.out.println("registered user with username:"
|
||||
// + userNameText.getText()
|
||||
// + ", and password:" + passwordField.getText());
|
||||
// }
|
||||
|
||||
userService.registerUser(userNameText.getText(), passwordField.getText());
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@ public class UserController {
|
||||
"Please enter your username");
|
||||
return;
|
||||
} else {
|
||||
// newUser.setUsername(usernameField.getText());
|
||||
System.out.println("Username is " + usernameField.getText());
|
||||
}
|
||||
if (passwordField.getText().isEmpty()) {
|
||||
@@ -50,23 +49,9 @@ public class UserController {
|
||||
"Please enter a password");
|
||||
return;
|
||||
} else {
|
||||
// newUser.setPassword(passwordField.getText());
|
||||
System.out.println("Password is " + passwordField.getText());
|
||||
}
|
||||
|
||||
userService.registerUser(usernameField.getText(), passwordField.getText());
|
||||
|
||||
// load the dashboard stage
|
||||
// Parent parent = FXMLLoader.load(
|
||||
// this.getClass().getClassLoader().getResource("/fxml/dashboard.fxml")
|
||||
// );
|
||||
//
|
||||
// Scene scene = new Scene(parent);
|
||||
// Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
|
||||
// app_stage.setScene(scene);
|
||||
// app_stage.setFullScreen(true);
|
||||
// app_stage.show();
|
||||
|
||||
userService.loginUser(usernameField.getText(), passwordField.getText());
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
openDashboard();
|
||||
@@ -79,15 +64,13 @@ public class UserController {
|
||||
* @author sem
|
||||
*/
|
||||
public void openDashboard() throws IOException {
|
||||
// Font.loadFont(getClass().getResourceAsStream("stylesheets/DesignioRegular.otf"), 21);
|
||||
Parent dash = FXMLLoader.load(
|
||||
this.getClass().getClassLoader().getResource("fxml/Dashboard.fxml")
|
||||
this.getClass().getClassLoader().getResource("fxml/dashboard.fxml")
|
||||
);
|
||||
Scene scene = new Scene(dash);
|
||||
scene.getStylesheets().add(getClass().getClassLoader().getResource("stylesheets/dashboardStyle.css").toExternalForm());
|
||||
Stage appStage = new Stage();
|
||||
appStage.setScene(scene);
|
||||
// app_stage.setFullScreen(true);
|
||||
appStage.show();
|
||||
}
|
||||
|
||||
@@ -112,7 +95,6 @@ public class UserController {
|
||||
}
|
||||
}
|
||||
|
||||
//method to open the register window
|
||||
public void handleRegisterButtonAction(ActionEvent event) throws Exception{
|
||||
//load the fxml file
|
||||
Parent registerWindow = FXMLLoader.load (
|
||||
|
||||
@@ -6,16 +6,18 @@ import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
@Component
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate(RestTemplateBuilder builder) {
|
||||
RestTemplate restTemplate(RestTemplateBuilder builder) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@@ -35,4 +37,26 @@ public class UserService {
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
}
|
||||
|
||||
public UserDTO loginUser(String name, String password) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/loginUser")
|
||||
.queryParam("name", name)
|
||||
.queryParam("password", password);
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
}
|
||||
|
||||
public UserDTO addVeganMeal(Long id, String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/addVeganMeal")
|
||||
.queryParam("id", id)
|
||||
.queryParam("name", name);
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.image.*?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.PasswordField?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
|
||||
<AnchorPane prefHeight="300.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.RegisterWindowController">
|
||||
<children>
|
||||
<ImageView fitHeight="312.0" fitWidth="300.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../registerBackground.png" />
|
||||
</image>
|
||||
</ImageView>
|
||||
<Text fill="#00650d" layoutX="103.0" layoutY="42.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Register">
|
||||
<font>
|
||||
<Font size="26.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField fx:id="userNameText" layoutX="69.0" layoutY="94.0" promptText="Username">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</TextField>
|
||||
<Button fx:id="signupButton" layoutX="115.0" layoutY="229.0" mnemonicParsing="false" onAction="#handleSignUpButton" style="-fx-background-color: #005e07;" text="Sign up!" textFill="#c4eec9">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="14.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<PasswordField fx:id="passwordField" layoutX="69.0" layoutY="138.0" promptText="Password">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</PasswordField>
|
||||
<PasswordField fx:id="passwordField2" layoutX="69.0" layoutY="182.0" promptText="Re-enter password">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</PasswordField>
|
||||
</children>
|
||||
<children>
|
||||
<ImageView fitHeight="312.0" fitWidth="300.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../registerBackground.png" />
|
||||
</image>
|
||||
</ImageView>
|
||||
<Text fill="#00650d" layoutX="103.0" layoutY="42.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Register">
|
||||
<font>
|
||||
<Font size="26.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField fx:id="userNameText" layoutX="69.0" layoutY="94.0" promptText="Username">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</TextField>
|
||||
<Button fx:id="signupButton" layoutX="115.0" layoutY="229.0" mnemonicParsing="false" onAction="#handleSignUpButton" style="-fx-background-color: #005e07;" text="Sign up!" textFill="#c4eec9">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="14.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<PasswordField fx:id="passwordField" layoutX="69.0" layoutY="138.0" promptText="Password">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</PasswordField>
|
||||
<PasswordField fx:id="passwordField2" layoutX="69.0" layoutY="182.0" promptText="Re-enter password">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</PasswordField>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.shape.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.collections.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.collections.FXCollections?>
|
||||
|
||||
<AnchorPane prefHeight="602.0" prefWidth="926.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||
<?import javafx.scene.shape.Line?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<AnchorPane prefHeight="602.0" prefWidth="934.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||
<children>
|
||||
<AnchorPane fx:id="menuBar" prefHeight="603.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
||||
<children>
|
||||
@@ -45,11 +40,16 @@
|
||||
<Font size="30.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Button layoutX="60.0" layoutY="116.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" text="Add a vegetarian meal" textFill="#e0ffe1">
|
||||
<Button fx:id="veganMealButton" layoutX="60.0" layoutY="116.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" onAction="#addVeganMeal" text="Add a vegetarian meal" textFill="#e0ffe1">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<Label fx:id="counter" layoutX="288.0" layoutY="110.0" prefHeight="44.0" prefWidth="115.0" text="Count: ">
|
||||
<font>
|
||||
<Font size="25.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children></AnchorPane>
|
||||
<AnchorPane fx:id="userPane" layoutX="215.0" layoutY="-1.0" prefHeight="603.0" prefWidth="711.0" visible="false">
|
||||
<children>
|
||||
@@ -93,14 +93,6 @@
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
|
||||
<!--<ComboBox fx:id="addActivity" layoutX="532.0" layoutY="28.0" prefWidth="150.0" promptText="Add an Activity" style="-fx-background-color: #1f951f;">-->
|
||||
<!--<items>-->
|
||||
<!--<FXCollections fx:factory="observableArrayList">-->
|
||||
<!--<String fx:value="Ate a vegetarian meal" />-->
|
||||
<!--</FXCollections>-->
|
||||
<!--</items>-->
|
||||
<!--</ComboBox>-->
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</children>
|
||||
|
||||
@@ -1,23 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Hyperlink?>
|
||||
<?import javafx.scene.control.PasswordField?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
|
||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="574.0" prefWidth="934.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.UserController">
|
||||
<?import javafx.scene.text.*?>
|
||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="602.0" prefWidth="934.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.UserController">
|
||||
<children>
|
||||
<ImageView fitHeight="574.0" fitWidth="943.0" layoutX="-1.0" pickOnBounds="true">
|
||||
<ImageView fitHeight="600.0" fitWidth="943.0" layoutX="-1.0" pickOnBounds="true">
|
||||
<image>
|
||||
<Image url="@../pinkleaf.jpg" />
|
||||
</image></ImageView>
|
||||
@@ -27,18 +17,18 @@
|
||||
</font>
|
||||
</Text>
|
||||
<Button fx:id="loginButton" layoutX="419.0" layoutY="274.0" mnemonicParsing="false" onAction="#handleLoginButtonAction" prefHeight="26.0" prefWidth="96.0" text="Login" textAlignment="CENTER" />
|
||||
<Button fx:id="signupButton" layoutX="49.0" layoutY="52.0" mnemonicParsing="false" onAction="#handleRegisterButtonAction" prefHeight="6.0" prefWidth="61.0" text="Sign up!" />
|
||||
<Button fx:id="signupButton" layoutX="42.0" layoutY="52.0" mnemonicParsing="false" onAction="#handleRegisterButtonAction" prefHeight="10.0" prefWidth="96.0" text="Sign up!" />
|
||||
<PasswordField fx:id="passwordField" layoutX="318.0" layoutY="210.0" prefHeight="42.0" prefWidth="303.0" promptText="Password" />
|
||||
<Hyperlink layoutX="392.0" layoutY="308.0" prefHeight="42.0" prefWidth="173.0" text="Forgot Password?" textAlignment="CENTER" textFill="WHITE" textOverrun="LEADING_WORD_ELLIPSIS">
|
||||
<font>
|
||||
<Font name="Bodoni MT Bold" size="18.0" />
|
||||
</font>
|
||||
</Hyperlink>
|
||||
<Text fill="#23773d" layoutX="7.0" layoutY="40.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Not Member?" textAlignment="CENTER" wrappingWidth="146.13673400878906">
|
||||
<Text fill="#23773d" layoutX="20.0" layoutY="40.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Not Member?" textAlignment="CENTER" wrappingWidth="146.13673400878906">
|
||||
<font>
|
||||
<Font name="Californian FB" size="14.0" />
|
||||
<Font name="Californian FB" size="20.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField fx:id="usernameField" layoutX="319.0" layoutY="154.0" prefHeight="42.0" prefWidth="303.0" promptText="Username" />
|
||||
<TextField fx:id="usernameField" layoutX="319.0" layoutY="154.0" prefHeight="42.0" prefWidth="303.0" promptText="Username" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
||||
@@ -1,34 +1,11 @@
|
||||
/*.button {*/
|
||||
/*-fx-border-width: 0px 0px 1px 0px;*/
|
||||
/*-fx-border-color: #f9f9f9;*/
|
||||
/*-fx-border-radius: 0%;*/
|
||||
/*}*/
|
||||
|
||||
/*@font-face {*/
|
||||
/*font-family: 'Nunito Sans';*/
|
||||
/*src: url('https://fonts.googleapis.com/css?family=Nunito+Sans:200');*/
|
||||
/*}*/
|
||||
|
||||
@font-face {
|
||||
font-family: 'Designio Regular ';
|
||||
src: url('stylesheets/DesignioRegular.otf');
|
||||
}
|
||||
|
||||
/*@font-face {*/
|
||||
/*font-family: 'Big Designer';*/
|
||||
/*src: url('Big Designer.ttf');*/
|
||||
/*}*/
|
||||
/*test if fonts work*/
|
||||
/*@font-face {*/
|
||||
/*font-family: 'ConcertOne';*/
|
||||
/*src: url('https://fonts.googleapis.com/css?family=Concert+One');*/
|
||||
/*}*/
|
||||
.root {
|
||||
-fx-background-color: #f9fffb;
|
||||
-fx-font-family: "Big Designer";
|
||||
/*-fx-font-family: Designio;*/
|
||||
/*-fx-font-family: "Nunito Sans";*/
|
||||
/*-fx-font-family: "Concert One";*/
|
||||
}
|
||||
|
||||
#dashboardButton {
|
||||
|
||||
Reference in New Issue
Block a user