diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/Management.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/Management.java index c29e342fd201643bf579d525e84df57c147b0ae3..2d41e74a99974cc8dd7d3a96c6dd3ae7e5f3f262 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/Management.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/Management.java @@ -7,7 +7,7 @@ import unipotsdam.gf.core.management.user.UserInterests; import unipotsdam.gf.core.management.user.UserProfile; import unipotsdam.gf.modules.assessment.controller.StudentIdentifier; -import java.util.*; +import java.util.List; /** * Created by dehne on 31.05.2018. @@ -43,6 +43,13 @@ public interface Management { */ void delete(Project project); + /** + * Update a User in the database + * + * @param user + */ + void update(User user); + /** * Add an entry in the M:N table linking users and projects * @@ -66,7 +73,7 @@ public interface Management { * @param project * @return */ - java.util.List<User> getUsers(Project project); + List<User> getUsers(Project project); /** * get the token for the user diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/ManagementImpl.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/ManagementImpl.java index 01135265a1249eb9ae7b481e0224e9a8a1c85a9d..0a0ad3461923a411b9ec8f81c6413e4600099d32 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/ManagementImpl.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/ManagementImpl.java @@ -37,9 +37,10 @@ public class ManagementImpl implements Management { MysqlConnect connect = new MysqlConnect(); connect.connect(); - String mysqlRequest = "INSERT INTO users (`name`, `password`, `email`, `token`,`isStudent`) values (?,?,?,?,?)"; + String mysqlRequest = "INSERT INTO users (`name`, `password`, `email`, `token`,`isStudent`," + + "`rocketChatId`,`rocketChatAuthToken`) values (?,?,?,?,?,?,?)"; connect.issueInsertOrDeleteStatement(mysqlRequest, user.getName(), user.getPassword(), user.getEmail(), - token, user.getStudent()); + token, user.getStudent(), user.getRocketChatId(), user.getRocketChatAuthToken()); connect.close(); // TODO implmement UserProfile @Mar @@ -53,7 +54,8 @@ public class ManagementImpl implements Management { MysqlConnect connect = new MysqlConnect(); connect.connect(); String mysqlRequest = - "INSERT INTO projects (`id`, `password`, `activ`, `timecreated`, `author`, " + "`adminpassword`, `token`) values (?,?,?,?,?,?,?)"; + "INSERT INTO projects (`id`, `password`, `activ`, `timecreated`, `author`, " + + "`adminpassword`, `token`) values (?,?,?,?,?,?,?)"; connect.issueInsertOrDeleteStatement(mysqlRequest, project.getId(), project.getPassword(), project.getActiv(), project.getTimecreated(), project.getAuthor(), project.getAdminpassword(), token); connect.close(); @@ -77,9 +79,20 @@ public class ManagementImpl implements Management { connect.close(); } + @Override + public void update(User user) { + MysqlConnect connect = new MysqlConnect(); + connect.connect(); + String mysqlRequest = "UPDATE `users` SET `name`=?,`password`=?,`email`=?,`token`=?,`isStudent`=?, `rocketChatId`=?,`rocketChatAuthToken`=? WHERE email=? LIMIT 1"; + //TODO: maybe add handling if a line is actually updated + connect.issueUpdateStatement(mysqlRequest, user.getName(), user.getPassword(), user.getEmail(), + user.getToken(), user.getStudent(), user.getRocketChatId(), user.getRocketChatAuthToken(), user.getEmail()); + connect.close(); + } + @Override public Boolean exists(User user) { - Boolean result = false; + Boolean result; MysqlConnect connect = new MysqlConnect(); connect.connect(); String mysqlRequest = "SELECT * FROM users where email = ? and password = ?"; @@ -101,7 +114,7 @@ public class ManagementImpl implements Management { + " JOIN projects p ON pu.projectId = p.id" + " WHERE pu.projectId = ?"; - ArrayList<User> result = new ArrayList<User>(); + ArrayList<User> result = new ArrayList<>(); MysqlConnect connect = new MysqlConnect(); connect.connect(); VereinfachtesResultSet vereinfachtesResultSet = connect.issueSelectStatement(query, project.getId()); diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/User.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/User.java index 18376324134d68a1520717640b2fa0ea90c574a4..53cda450b590124610e5729565b660889586a67b 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/User.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/User.java @@ -24,6 +24,8 @@ public class User { this.password = password; this.email = email; this.isStudent = isStudent; + this.rocketChatAuthToken = ""; + this.rocketChatId = ""; } public User(String name, String password, String email, String rocketChatId, Boolean isStudent) { diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/UserService.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/UserService.java index 124a207aa523d5f6dedb5602e6acea7bee8b3e12..1b7ae7cfecd44930d30346b9bad7c6b926b31bd2 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/UserService.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/UserService.java @@ -4,6 +4,8 @@ import unipotsdam.gf.core.management.ManagementImpl; import unipotsdam.gf.interfaces.ICommunication; import unipotsdam.gf.modules.communication.service.CommunicationDummyService; +import javax.annotation.ManagedBean; +import javax.inject.Inject; import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -14,8 +16,12 @@ import java.net.URI; import java.net.URISyntaxException; @Path("/user") +@ManagedBean public class UserService { + @Inject + private ICommunication communicationService; + /** * creates a user with given credentials * @@ -36,13 +42,8 @@ public class UserService { ManagementImpl management = new ManagementImpl(); User user = new User(name, password, email, isStudent == null); - ICommunication iCommunication = new CommunicationDummyService(); - boolean chatUserCreated = iCommunication.registerUser(user); - if (chatUserCreated) { - return login(true, user); - } else { - return registrationError(); - } + return login(true, user); + } /** @@ -87,12 +88,21 @@ public class UserService { ManagementImpl management = new ManagementImpl(); if (management.exists(user)) { if (!createUser) { + boolean successfulLogin = communicationService.loginUser(user); + management.update(user); + if (!successfulLogin) { + return loginError(); + } return redirectToProjectPage(user, management); } String existsUrl = "../register.jsp?userExists=true"; return forwardToLocation(existsUrl); } else { if (createUser) { + boolean isRegisteredAndLoggedIn = communicationService.registerAndLoginUser(user); + if (!isRegisteredAndLoggedIn) { + return registrationError(); + } management.create(user, null); } else { String existsUrl = "../index.jsp?userExists=false"; diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/interfaces/ICommunication.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/interfaces/ICommunication.java index f95b9c69cafc27e863f91709d9303fc7101fe20e..12d3d71183ae34966d1e88a04596095c22eadd42 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/interfaces/ICommunication.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/interfaces/ICommunication.java @@ -81,6 +81,8 @@ public interface ICommunication { */ boolean registerUser(User user); + boolean registerAndLoginUser(User user); + String getChatRoomLink(String userToken, String projectToken, String groupToken); } diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/communication/service/CommunicationDummyService.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/communication/service/CommunicationDummyService.java index 2a07f3420527454f08af715dc9804b98876e79c3..218047ad32d4c5d70df382505ac0f8da4efe0437 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/communication/service/CommunicationDummyService.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/communication/service/CommunicationDummyService.java @@ -72,7 +72,6 @@ public class CommunicationDummyService implements ICommunication { @Override public boolean loginUser(User user) { - user.setRocketChatId("1"); user.setRocketChatAuthToken("abc"); return true; } @@ -83,13 +82,21 @@ public class CommunicationDummyService implements ICommunication { return true; } + @Override + public boolean registerAndLoginUser(User user) { + if (!registerUser(user)) { + return false; + } + return loginUser(user); + + } + public String getChatRoomLink(String userToken, String projectToken, String groupToken) { //User user = managementService.getUser(userToken); // TODO: Implement getProjectbyToken and getGroupByToken //Project project = managementService.getProject(projectToken String channelName = "general"; - String fullUrl = Constants.ROCKET_CHAT_URL + "/channel/" + channelName + "?layout=embedded"; - return fullUrl; + return Constants.ROCKET_CHAT_URL + "/channel/" + channelName + "?layout=embedded"; } // TODO: remove after done implementing