renamed DataController -> DataHandler
[staff/due1/sed-hs15-srs-purple.git] / src / main / java / ch / bfh / ti / srs / core / UserController.java
CommitLineData
5555b609
M
1/*\r
2 * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
3 *\r
4 * Project Smart Reservation System.\r
5 *\r
6 * Distributable under GPL license. See terms of license at gnu.org.\r
7 */\r
8package ch.bfh.ti.srs.core;\r
9\r
1ec0e01f
M
10import java.rmi.AlreadyBoundException;\r
11import java.util.concurrent.ExecutionException;\r
12\r
13/**\r
14 * @author Michael Grossen\r
15 */\r
5555b609 16public class UserController {\r
1ec0e01f
M
17 final String filePath = "test.xls";\r
18 User currentUser;\r
06726c50 19 DataHandler dc;\r
5555b609 20 \r
1ec0e01f 21 public UserController() throws Exception {\r
06726c50 22 dc = new DataHandlerForExcel(filePath);\r
5555b609
M
23 }\r
24 \r
1ec0e01f
M
25 /**\r
26 * Tries to logIn a user with the given credentials\r
27 * \r
28 * @param userName username\r
29 * @param password the stored password for the given username\r
30 * @return <code>true</code> if the user could log in successfully;\r
31 * <code>false</code> eighter the username or the password was not correct.\r
32 * @throws Exception\r
33 */\r
5555b609 34 public boolean logIn(String userName, String password) throws Exception{\r
1ec0e01f 35 if(currentUser != null) throw new AlreadyBoundException("A user is already logged in");\r
5555b609
M
36 User tempUser = dc.findUser(userName);\r
37 if(tempUser == null) return false;\r
38 if(tempUser.checkPassword(password)){\r
1ec0e01f 39 currentUser = tempUser;\r
5555b609
M
40 return true;\r
41 }\r
42 else return false;\r
43 }\r
44 \r
1ec0e01f
M
45 /**\r
46 * Logs out the current user, throws exception if no user is logged in\r
47 * \r
48 * @throws Exception \r
49 */\r
50 public void logOut() throws Exception{\r
51 if(currentUser == null) throw new Exception("No user is logged in");\r
52 currentUser = null;\r
53 }\r
5555b609 54 \r
1ec0e01f
M
55 public void addUser(String userName, String password, String email, String name, String lastname) throws Exception{\r
56 User newUser = new User(userName,password);\r
57 newUser.setMail(email);\r
58 newUser.setName(name);\r
59 newUser.setLastname(lastname);\r
60 dc.addUser(newUser);\r
61 }\r
5555b609 62}\r