diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index 3494cd1..02f4dd0 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -212,6 +212,30 @@ public class System { } + public boolean change_user_password(String old_password, String new_password, String new_password_authentication){ + if(!this.current_user.getPassword().equals(old_password)) + return false; + + if(!new_password.equals(new_password_authentication)) + return false; + + for(int i = 0; i< this.all_user.size(); i++) + if(this.all_user.get(i).getUsername().equals(current_user.getUsername())) + this.all_user.remove(i); + + write_to_file(all_user_toString(), "src/main/resources/user_data.csv"); + write_to_file(all_user_toString(), "src/test/resources/user_data.csv"); + + this.current_user.setPassword(new_password); + this.all_user.add(current_user); + + write_to_file(all_user_toString(), "src/main/resources/user_data.csv"); + write_to_file(all_user_toString(), "src/test/resources/user_data.csv"); + + return true; + + } + public void write_to_file(ArrayList lines, String file) { try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { for (int i = 0; i < lines.size() - 1; i++) { diff --git a/src/main/java/de/hs_mannheim/facade/Application.java b/src/main/java/de/hs_mannheim/facade/Application.java index f93622d..015597b 100644 --- a/src/main/java/de/hs_mannheim/facade/Application.java +++ b/src/main/java/de/hs_mannheim/facade/Application.java @@ -30,6 +30,10 @@ public class Application { return running_system.change_user_details(username, password, hometown, zip, car_name, car_co2_km, car_avg_kmh, bike_avg_kmh); } + public boolean change_user_password(String old_password, String new_password, String new_password_authentication){ + return running_system.change_user_password(old_password, new_password, new_password_authentication); + } + public ArrayList search(String hometown_or_zip){ return running_system.search(hometown_or_zip); } diff --git a/src/test/java/de/hs_mannheim/domain/SystemTest.java b/src/test/java/de/hs_mannheim/domain/SystemTest.java index 8a47749..24344b0 100644 --- a/src/test/java/de/hs_mannheim/domain/SystemTest.java +++ b/src/test/java/de/hs_mannheim/domain/SystemTest.java @@ -139,11 +139,24 @@ public class SystemTest { public void change_user_details(){ current_system.sign_in_user("David", "123Esel"); - current_system.change_user_details("Enes", "Penis123", "Mannheim", "68161", "", "", "", ""); + current_system.change_user_details("Enes", "123Esel", "Mannheim", "68161", "", "", "", ""); assertEquals("Enes", current_system.getDetails()[0]); current_system.change_user_details("David", "123Esel", "Mannheim", "68161", "AMG", "10", "100", "20"); } + + @Test + public void change_user_password(){ + + current_system.sign_in_user("David", "123Esel"); + assertEquals(true, current_system.change_user_password("123Esel", "Pizza69", "Pizza69")); + assertEquals(true, current_system.change_user_password("Pizza69", "123Esel", "123Esel")); + assertEquals(true, current_system.change_user_details("Enes", "123Esel", "Mannheim", "68161", "", "", "", "")); + current_system.change_user_details("David", "123Esel", "Mannheim", "68161", "AMG", "10", "100", "20"); + + ; + + } /* Tests auf Basis von user_data.csv: Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2