Skip to content
Snippets Groups Projects
Commit 45475372 authored by Nicolas Fley's avatar Nicolas Fley
Browse files

uncommited modif

parent e45112df
No related branches found
No related tags found
No related merge requests found
package Core;
import User.User;
public class ActiveUserContext {
User activeUser;
public ActiveUserContext(MyFoodora foodora) {
// TODO Auto-generated constructor stub
}
public User getUser(){
return activeUser;
}
public void setActiveUser(User u){
activeUser = u;
}
}
......@@ -55,16 +55,20 @@ public class MyFoodora {
}
/** CUSTOM **/
public int getTypeOfUser(String usernameTest, String passwordTest){
if(this.getListCustomer().isContainingCorrectLogin(usernameTest, passwordTest))
return User.CUSTOMER;
if(this.getListCourier().isContainingCorrectLogin(usernameTest, passwordTest))
return User.COURIER;
if(this.getListRestaurant().isContainingCorrectLogin(usernameTest, passwordTest))
return User.RESTAURANT;
if(this.getListManager().isContainingCorrectLogin(usernameTest, passwordTest))
return User.MANAGER;
return User.UNKNOWN;
public User getUserByLogin(String usernameTest, String passwordTest){
User u = this.getListCustomer().getUserByLogin(usernameTest, passwordTest);
if(u != null)
return u;
u = this.getListCourier().getUserByLogin(usernameTest, passwordTest);
if(u != null)
return u;
u = this.getListRestaurant().getUserByLogin(usernameTest, passwordTest);
if(u != null)
return u;
u = this.getListManager().getUserByLogin(usernameTest, passwordTest);
if(u != null)
return u;
return null;
}
/** CUSTOM GETTER AND SETTER **/
......@@ -124,15 +128,8 @@ public class MyFoodora {
public static void main(String[] args) throws ExceptionUnknownMealType, ExceptionUnknownDishType, ExceptionUnknownStartegyType {
// TODO Auto-generated method stub
MyFoodora myFoodora = new MyFoodora();
FactoryDish dishFactory = new FactoryDish();
FactoryMeal mealFactory = new FactoryMeal();
Dish d1 = dishFactory.createDish("MainDish", "French Fries", "Vegan", 3.0);
Dish d2 = dishFactory.createDish("MainDish", "French Fries", "Vegan", 3.0);
Meal m1 = mealFactory.createMeal("HalfMeal");
Meal m2 = mealFactory.createMeal("HalfMeal");
//myFoodora.listRestaurant.add();
System.out.println(d1.equals(d2));
System.out.println(m1.equals(m2));
ActiveUserContext activeUser = new ActiveUserContext(myFoodora);
activeUser.setActiveUser(User.login(myFoodora));
}
public double getLastMonthIncome() {
// TODO Auto-generated method stub
......
......@@ -9,12 +9,12 @@ public class ListUser<T extends User>{
/** CUSTOM **/
public boolean isContainingCorrectLogin(String username, String password){
public User getUserByLogin(String username, String password){
for(User u : listUser){
if(u.isLoginCorrect(username,password))
return true;
return u;
}
return false;
return null;
}
public void addUser(T e){
listUser.add(e);
......
......@@ -44,19 +44,15 @@ public abstract class User implements Comparable<User> {
this.password = password;
this.adress = adress;
this.activated = activated;
}
/** CUSTOM **/
public void register(MyFoodora foodora){
public static User login(MyFoodora foodora){
String usernameTest = Input.string("Please writte your username");
String passwordTest = Input.string("Please writte your password");
this.typeOfUser = foodora.getTypeOfUser(usernameTest, passwordTest);
if(this.typeOfUser == User.UNKNOWN){
this.isLogged=false;
}else{
this.isLogged=true;
}
return foodora.getUserByLogin(usernameTest, passwordTest);
}
public boolean isLoginCorrect(String username, String password) {
if(this.username == username && this.password == password)
......@@ -71,6 +67,17 @@ public abstract class User implements Comparable<User> {
return username.compareTo(u.getUsername());
}
@Override
public boolean equals(Object other){
if(other instanceof User){
User u = (User) other;
if(this.id == u.getId()){
return true;
}
}
return false;
}
@Override
public String toString() {
return "User [id=" + id + ", phoneNumber=" + phoneNumber + ", name=" + name + ", username=" + username
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment