SessionController added/updated
[staff/due1/sed-hs15-srs-purple.git] / src / main / java / ch / bfh / ti / srs / controller / SessionController.java
index 04484d0..9e5e4b9 100644 (file)
@@ -20,8 +20,13 @@ public class SessionController {
        private DataHandler dh;\r
        private User currentUser;       \r
 \r
+       public SessionController(DataHandler dh){\r
+               this.dh = dh;\r
+               controllers = new HashSet<Controller>();\r
+       }\r
+       \r
        public SessionController(){\r
-               dh = new DataHandlerForTests();\r
+               this.dh = new DataHandlerForTests();\r
                controllers = new HashSet<Controller>();\r
        }\r
        \r
@@ -45,19 +50,22 @@ public class SessionController {
                User tempUser = dh.findUser(userName);\r
                if (tempUser != null || tempUser.checkPassword(password)){\r
                        currentUser = tempUser;\r
+                       controllers.clear();\r
                        \r
-                       Set<Controller> retSet = new HashSet<Controller>();\r
                        for (Role role : currentUser.getRoles()) {\r
                                switch(role){\r
                                        case User:\r
-                                               retSet.add(new UserController(dh, this));\r
+                                               controllers.add(new UserController(dh, this));\r
                                        case ResourceManager:\r
-                                               retSet.add(new ResourceManagerController(dh, this));\r
+                                               controllers.add(new ResourceManagerController(dh, this));\r
                                        case Admin:\r
-                                               \r
+                                               //Add AdminController to controllers\r
                                }\r
                        }\r
                }\r
+               else{\r
+                       throw new Exception("Username or password wrong");\r
+               }\r
                return controllers;\r
        }\r
 \r