Commit 68af9454 authored by Poz's avatar Poz

Reformatage du code Close #29

parent 365d390d
......@@ -2,7 +2,7 @@ package fr.unantes.software.construction.Reference;
public interface MultipleReference<T> {
boolean add (T value);
boolean add(T value);
boolean remove(T value);
......
......@@ -4,27 +4,18 @@ import java.util.Objects;
/**
* A city
* @Author Thomas Dumont
* @version 1.0
*/
public class City {
/**
* Nom du pays
* @see String
* **/
private String country;
/**
* nom de la ville
* @see String
* **/
private String name;
/**
* Constructeur de City
*
* @param country String correspondant au nom du pays de la ville
* @param name String correspondant au nom de la ville
* @param name String correspondant au nom de la ville
* @version 1.0
* **/
**/
public City(String country, String name) {
this.setCountry(country);
this.setName(name);
......@@ -33,7 +24,7 @@ public class City {
/**
* @return String, le nom du pays
* @version 1.0
* **/
**/
public String getCountry() {
return country;
}
......@@ -41,7 +32,7 @@ public class City {
/**
* @param country le nouveau nom du pays voulu
* @version 1.0
* **/
**/
public void setCountry(String country) {
this.country = country;
}
......@@ -49,7 +40,7 @@ public class City {
/**
* @return String, le nom de la ville
* @version 1.0
* **/
**/
public String getName() {
return name;
}
......@@ -57,17 +48,18 @@ public class City {
/**
* @param name le nouveau nom de la ville
* @version 1.0
* **/
**/
public void setName(String name) {
this.name = name;
}
/**
* override de equals
*
* @param o Objet dont on cherche a obtenir l'egaliter
* @return true si l'objet est le meme ou si le nom du pays et de la ville sont les meme, false sinon
* @version 1.0
* **/
**/
@Override
public boolean equals(Object o) {
if (this == o) return true;
......@@ -79,9 +71,10 @@ public class City {
/**
* override de hashCode
*
* @return le hashcode
* @version 1.0
* **/
**/
@Override
public int hashCode() {
return Objects.hash(getCountry(), getName());
......
package fr.unantes.software.construction.security;
import com.lambdaworks.crypto.SCryptUtil;
import java.util.regex.Pattern;
/**
......@@ -19,7 +20,8 @@ public class PasswordManager {
/**
* Check if a password is equal to his hash
* @param clearPassword - not hashed password
*
* @param clearPassword - not hashed password
* @param encodedPassword - hashed password
* @return True if the password is valid, false otherwise
*/
......@@ -29,6 +31,7 @@ public class PasswordManager {
/**
* Encrypt a password
*
* @param clearPassword - Password to encrypt
* @return Encrypted password
*/
......@@ -38,6 +41,7 @@ public class PasswordManager {
/**
* Test if the password is strong enought
*
* @param password - Password to test
* @return true if the password is strong enough, otherwise false
*/
......@@ -47,6 +51,7 @@ public class PasswordManager {
/**
* Compute the strength of a password
*
* @param clearPassword - password to test
* @return the strength in AES equivalent key size
*/
......
......@@ -46,11 +46,12 @@ final public class UserManager {
/**
* Get the only instance of the UserManager
*
* @return the instance of the UserManager
*/
public final static UserManager getInstance() {
if (UserManager.instance == null) {
synchronized(UserManager.class) {
synchronized (UserManager.class) {
if (UserManager.instance == null) {
UserManager.instance = new UserManager();
}
......@@ -61,10 +62,11 @@ final public class UserManager {
/**
* Connect a user from the application
*
* @return if the connection succeed or not
*/
public boolean connectUser(String name, String password) {
if ( namesToUsers.containsKey(name) && passwordManager.validate(password, usersToPasswords.get(name)) ) {
if (namesToUsers.containsKey(name) && passwordManager.validate(password, usersToPasswords.get(name))) {
currentUser = namesToUsers.get(name);
return true;
}
......@@ -80,6 +82,7 @@ final public class UserManager {
/**
* Get the current logged in user
*
* @return A Person who is currently logged in
*/
public Person getCurrentUser() {
......@@ -88,6 +91,7 @@ final public class UserManager {
/**
* Test if an user is registered in the manager
*
* @param person - User to search for
* @return True if the user is registered, False otherwise
*/
......@@ -97,7 +101,8 @@ final public class UserManager {
/**
* Add a new user to the manager
* @param person - User to add to the manager
*
* @param person - User to add to the manager
* @param clearPassword - User's password
* @return True if everything went smoothly, False otherwise
* @throws IllegalArgumentException If the person is already registered
......@@ -107,7 +112,7 @@ final public class UserManager {
throw new IllegalArgumentException("Invalid argument: the person is already registered.");
}
if (!passwordManager.validateNewPassword(clearPassword)) {
throw new IllegalArgumentException("The password is too weak");
throw new IllegalArgumentException("The password is too weak");
}
namesToUsers.put(person.getName(), person);
......@@ -117,6 +122,7 @@ final public class UserManager {
/**
* Remove a user from the manager
*
* @param person - User to remove
* @return True if everything went smoothly, False otherwise
*/
......
......@@ -7,7 +7,7 @@ import javafx.scene.Scene;
import javafx.stage.Stage;
public class GUI extends Application {
public class GUI extends Application {
private static final int MIN_WIDTH = 600;
private static final int MIN_HEIGHT = 400;
......
......@@ -16,17 +16,21 @@ import java.util.ResourceBundle;
public class HomeController implements Initializable {
@FXML AnchorPane homePane;
@FXML Label labelCurrentUserName;
@FXML Label labelCurrentUserRole;
@FXML Button btnLogOut;
@FXML
AnchorPane homePane;
@FXML
Label labelCurrentUserName;
@FXML
Label labelCurrentUserRole;
@FXML
Button btnLogOut;
@Override
public void initialize(URL url, ResourceBundle rb) {
/**
* On click -> disconnect the user
*/
btnLogOut.setOnMouseClicked( (MouseEvent event) -> logOut() );
btnLogOut.setOnMouseClicked((MouseEvent event) -> logOut());
UserManager userManager = UserManager.getInstance();
......
......@@ -6,10 +6,10 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.PasswordField;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
......@@ -19,31 +19,36 @@ import java.util.ResourceBundle;
public class LoginController implements Initializable {
@FXML Pane loginPane;
@FXML TextField fieldUsername;
@FXML PasswordField fieldPassword;
@FXML Button btnConnect;
@FXML Label labelError;
@FXML
Pane loginPane;
@FXML
TextField fieldUsername;
@FXML
PasswordField fieldPassword;
@FXML
Button btnConnect;
@FXML
Label labelError;
@Override
public void initialize(URL url, ResourceBundle rb) {
/**
* On click connect the user
*/
btnConnect.setOnAction( (ActionEvent event) -> tryToConnect() );
btnConnect.setOnAction((ActionEvent event) -> tryToConnect());
/**
* On click hide the previous errors from try to login
*/
fieldUsername.setOnMouseClicked( (MouseEvent event) -> hideError() );
fieldPassword.setOnMouseClicked( (MouseEvent event) -> hideError() );
fieldUsername.setOnMouseClicked((MouseEvent event) -> hideError());
fieldPassword.setOnMouseClicked((MouseEvent event) -> hideError());
}
/**
* Connect the user, if it's works the views change to home
*/
private void tryToConnect() {
if ( UserManager.getInstance().connectUser(fieldUsername.getText(), fieldPassword.getText()) ) {
if (UserManager.getInstance().connectUser(fieldUsername.getText(), fieldPassword.getText())) {
try {
Parent root = FXMLLoader.load(getClass().getResource("/home.fxml"));
loginPane.getScene().setRoot(root);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment