Updated Tests
[staff/due1/sed-hs15-srs-purple.git] / src / main / java / ch / bfh / ti / srs / controller / SessionController.java
index 9e5e4b9..91eb7e0 100644 (file)
@@ -43,12 +43,12 @@ public class SessionController {
         *             no <code>DataHandler</code> set\r
         */\r
        public Set<Controller> logIn(String userName, String password) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
                if (currentUser != null)\r
                        throw new Exception("A user is already logged in");\r
                User tempUser = dh.findUser(userName);\r
-               if (tempUser != null || tempUser.checkPassword(password)){\r
+               if (tempUser == null || !tempUser.checkPassword(password))\r
+                       throw new Exception("Username or password wrong");\r
+               else{\r
                        currentUser = tempUser;\r
                        controllers.clear();\r
                        \r
@@ -58,14 +58,11 @@ public class SessionController {
                                                controllers.add(new UserController(dh, this));\r
                                        case ResourceManager:\r
                                                controllers.add(new ResourceManagerController(dh, this));\r
-                                       case Admin:\r
-                                               //Add AdminController to controllers\r
+//                                     case Admin:\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
@@ -154,4 +151,13 @@ public class SessionController {
                return currentUser;\r
        }\r
 \r
+       public void registUser(String userName, String password, String email, String name, String lastname) throws Exception {\r
+               if (dh == null)\r
+                       throw new Exception("No DataHandler set");\r
+               User newUser = new User(userName, password);\r
+               newUser.setMail(email);\r
+               newUser.setName(name);\r
+               newUser.setLastname(lastname);\r
+               dh.addUser(newUser);\r
+       }\r
 }\r