Skip to content

Commit

Permalink
Minor comment & code tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
erikshea committed Jan 7, 2021
1 parent 978d67e commit 704fde8
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 55 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Validation conditions are updated continuously when fields are filled. Input are
## Account modification
![](https://github.com/erikshea/nesti/blob/master/assets/readme/modification.png?raw=true)

Likewise, users can only validate changes when all conditions are met (unique username and email if those are changed...).
Likewise, users can only confirm validated changes.

## Database settings
![](https://github.com/erikshea/nesti/blob/master/assets/readme/database-settings.png?raw=true)
Expand Down Expand Up @@ -47,6 +47,8 @@ Dependencies

The "assets" directory should be in the build path. The Eclipse project in this repository also includes the following user libraries in the build path:

### JUnit 5

### javafx15
* [All jars in the "lib" folder.](https://gluonhq.com/products/javafx/)

Expand All @@ -65,6 +67,4 @@ The "assets" directory should be in the build path. The Eclipse project in this
### jdbc_sqlite
* [sqlite-jdbc-3.34.0.jar](https://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/3.34.0/sqlite-jdbc-3.34.0.jar)

### JUnit 5

To add a user library in Eclipse: *Window*>*Preferences*>*Java*>*Build Path*>*User Libraries*>*New*, then name it and add external jars.
Binary file modified assets/database/nesti.sqlite.db
Binary file not shown.
Binary file modified assets/database/nesti_settings.sqlite.db
Binary file not shown.
19 changes: 4 additions & 15 deletions src/controller/ControlledGridPane.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
package controller;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.layout.GridPane;

/**
* Base class for all panes that are to be shown inside main window
* Base class for all regions controlled by our main controller
*/
public class ControlledGridPane extends GridPane{
// Observable main controller object
protected ObjectProperty<UserAccountControl> mainController = new SimpleObjectProperty<>();
public class ControlledGridPane extends GridPane{
protected UserAccountControl mainController; // Reference to main controller

public void setMainController(UserAccountControl c) {
this.mainController.set(c);
this.mainController = c;
}

public UserAccountControl getMainController() {
return this.mainController.get();
}

public final ObjectProperty<UserAccountControl> getMainControllerPropery() {
return this.mainController;
}

public ControlledGridPane() {
this.needsLayoutProperty().addListener((e)->this.requestFocus());
}
}

4 changes: 2 additions & 2 deletions src/controller/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public SettingsDialog(){
// Fix to allow "X" button to close dialog with no "CANCEL_CLOSE" buttontype
this.getDialogPane().getScene().getWindow().setOnCloseRequest(event -> this.hide());

this.setOnShowing(e->{ // On display, frill fields from settings
this.setOnShowing(e->{ // On display, fill fields from settings
databaseType.setValue(ApplicationSettings.get("databaseType"));
settingsAddress.setText(ApplicationSettings.get("databaseAddress"));
settingsDatabaseName.setText(ApplicationSettings.get("databaseName"));
settingsLogin.setText(ApplicationSettings.get("databaseLogin"));
settingsPassword.setText(ApplicationSettings.get("databasePassword"));
});

// default button fills fields from default settings
// default button : fills fields from default settings
this.getDialogPane().lookupButton(defaultsButton).addEventFilter(ActionEvent.ACTION, event -> {
databaseType.setValue(ApplicationSettings.getDefault("databaseType"));
settingsAddress.setText(ApplicationSettings.getDefault("databaseAddress"));
Expand Down
19 changes: 11 additions & 8 deletions src/controller/UserAccountControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,34 @@ public void initialize() {
this.connectedUserBar.setMainController(this);

try {
setUpDatabaseFromSettings(); // Load connection parameters from settings, connect
setUpDatabaseFromSettings(); // Load connection parameters from settings and connect
} catch (SQLException e) {
e.printStackTrace();
}


// Load logged in user from previous session
var previousUser = RegisteredUserDAO.find( "username", ApplicationSettings.get("loggedInUsername") );
if (previousUser != null && previousUser.isPassword(ApplicationSettings.get("loggedInPassword"))) { // Check stored plainText password
this.logInUser(previousUser,""); // LOg in user, don't modify password in settings
if (previousUser != null && previousUser.isPassword(ApplicationSettings.get("loggedInPassword"))) { // Check stored plaintext password
this.logInUser(previousUser,""); // Log in user, don't modify password in settings
} else {
this.logOutUser(); // run log out user logic
}

//resize window on subsequent changes of bottom pane
this.bottomProperty().addListener((e)-> this.getScene().getWindow().sizeToScene());

this.bottomProperty().addListener((e,o,newRegion)->{
this.getScene().getWindow().sizeToScene(); // resize window on changes of bottom pane
newRegion.requestFocus(); // don't focus first field
});

// If data source changes, log out user
DatabaseManager.getConnectionParametersProperty().addListener( (e,o,n)-> this.logOutUser() );

}

/**
* Show region to fill window below menus and connected user bar)
* @param region region to show
* Set main to a region main windows bottom pane
* @param ControlledGridPane region to show
*/
public void showRegion(ControlledGridPane region) {
region.setMainController(this);
Expand Down Expand Up @@ -116,7 +119,7 @@ public static void setUpDatabaseFromSettings() throws SQLException {
/**
* Log in user, update app session settings, open information pane
* @param user to log in
* @param plaintextPassword plaintext password to check user against
* @param plaintextPassword plaintext password to store in session settings
*/
public void logInUser(RegisteredUser user, String plaintextPassword) {
this.loggedInUser.set(user); // set observable property
Expand Down
40 changes: 20 additions & 20 deletions src/controller/UserAccountInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@ public class UserAccountInfo extends ControlledGridPane{
@FXML ValidatedPasswordField fieldModifyPassword;
@FXML ValidatedConfirmPasswordField fieldConfirmModifyPassword;
@FXML Label registrationDate;

// Edited user is stored separately from logged in user, so that we can bind its properties to editable field.
private ObjectProperty<RegisteredUser> editedUser = new SimpleObjectProperty<>();

public void initialize() {
// When main controller is changed, reset fields and set up listeners
this.getMainControllerPropery().addListener((o,oldController,newController)->{
this.needsLayoutProperty().addListener((e)->{ // On layout phase, reset fields
this.reset();

this.fieldOldPassword.addValidator(
(val) -> newController.getLoggedInUser().isPassword(val), // must match old password
"Correspond avec l'ancien mot de passe."
);
this.fieldModifyUsername.addValidator(
(val) -> val.equals(newController.getLoggedInUser().getUsername()) // username should either unmodified,
|| RegisteredUserDAO.find("username", val) == null, // or not present in data source
"Nom d'utilisateur libre."
);
this.fieldModifyEmail.addValidator(
(val) -> val.equals(newController.getLoggedInUser().getEmail()) // email should either unmodified,
|| RegisteredUserDAO.find("email", val) == null, // or not present in data source
"Email libre."
);

this.fieldModifyPassword.addSpecialCase( (val) -> val.length() == 0 ); // Accept blank new password (if unchanged)
});

this.fieldOldPassword.addValidator(
(val) -> this.getMainController().getLoggedInUser().isPassword(val), // must match old password
"Correspond avec l'ancien mot de passe."
);
this.fieldModifyUsername.addValidator(
(val) -> val.equals(this.getMainController().getLoggedInUser().getUsername()) // username should either unmodified,
|| RegisteredUserDAO.find("username", val) == null, // or not present in data source
"Nom d'utilisateur libre."
);
this.fieldModifyEmail.addValidator(
(val) -> val.equals(this.getMainController().getLoggedInUser().getEmail()) // email should either unmodified,
|| RegisteredUserDAO.find("email", val) == null, // or not present in data source
"Email libre."
);

this.fieldModifyPassword.addSpecialCase( (val) -> val.length() == 0 ); // Accept blank new password (if unchanged)


// when fields are edited, make edited user properties change as well
this.editedUser.addListener((e,oldValue,newValue)->{
Expand Down
13 changes: 6 additions & 7 deletions src/controller/UserAccountRegisterForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,19 @@ public class UserAccountRegisterForm extends ControlledGridPane{
@FXML private ValidatedPasswordField fieldPassword;
@FXML private ValidatedBasePasswordField fieldConfirmPassword;
@FXML private Button registerSubmitButton;


/**
* Submit button logic
* @param event
*/
@FXML protected void handleSubmitButtonAction(ActionEvent event) {
var newUser = new RegisteredUser(
fieldUsername.getText(),
fieldEmail.getText(),
fieldFirstName.getText(),
fieldLastName.getText(),
fieldCity.getText(),
fieldPassword.getText()
fieldUsername.getText(),
fieldEmail.getText(),
fieldFirstName.getText(),
fieldLastName.getText(),
fieldCity.getText(),
fieldPassword.getText()
);
try {
RegisteredUserDAO.insert(newUser); // Add to data source
Expand Down

0 comments on commit 704fde8

Please sign in to comment.