From 80f9801db3d337cf6d492f0534737277a3e32d0f Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Fri, 24 Jul 2020 16:56:32 +0200 Subject: [PATCH] works like a charm --- pom.xml | 2 +- .../InvitationAcceptEventPublisher.java | 9 ++ .../acceptinvite/PortletViewController.java | 90 ++----------------- src/main/webapp/WEB-INF/jsp/view.jsp | 35 ++++---- .../WEB-INF/liferay-plugin-package.properties | 4 +- src/main/webapp/js/main.js | 38 +------- 6 files changed, 38 insertions(+), 140 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/acceptinvite/InvitationAcceptEventPublisher.java diff --git a/pom.xml b/pom.xml index 849834e..b904dc4 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ accept-invite-portlet war accept-invite-portlet Portlet - 1.2.0-SNAPSHOT + 2.0.0-SNAPSHOT accept-invite-portlet manage the sent invitations diff --git a/src/main/java/org/gcube/portlets/user/acceptinvite/InvitationAcceptEventPublisher.java b/src/main/java/org/gcube/portlets/user/acceptinvite/InvitationAcceptEventPublisher.java new file mode 100644 index 0000000..36c9732 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/acceptinvite/InvitationAcceptEventPublisher.java @@ -0,0 +1,9 @@ +package org.gcube.portlets.user.acceptinvite; + +import org.gcube.portal.event.publisher.lr62.AbstractLR62EventPublisher; + +public class InvitationAcceptEventPublisher extends AbstractLR62EventPublisher { + public InvitationAcceptEventPublisher() { + super(); + } +} diff --git a/src/main/java/org/gcube/portlets/user/acceptinvite/PortletViewController.java b/src/main/java/org/gcube/portlets/user/acceptinvite/PortletViewController.java index c439785..7abe55b 100644 --- a/src/main/java/org/gcube/portlets/user/acceptinvite/PortletViewController.java +++ b/src/main/java/org/gcube/portlets/user/acceptinvite/PortletViewController.java @@ -27,6 +27,7 @@ import javax.servlet.http.HttpSession; import org.apache.commons.codec.binary.Base64; import org.gcube.common.portal.PortalContext; +import org.gcube.event.publisher.Event; import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl; import org.gcube.portal.databook.server.DatabookStore; import org.gcube.portal.databook.shared.Invite; @@ -153,21 +154,15 @@ public class PortletViewController { String email = ParamUtil.getString(request, "email"); String firstName = ParamUtil.getString(request, "firstname"); String lastName = ParamUtil.getString(request, "lastname"); - String password = ParamUtil.getString(request, "password"); - String repassword = ParamUtil.getString(request, "repassword"); +// _log.info("firstName=" + firstName); _log.info("lastName=" + lastName); _log.info("email=" + email); - _log.info("password=" + password); - _log.info("repassword=" + repassword); - HttpServletRequest httpReq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request)); Model model = (Model) httpReq.getSession().getAttribute(MODEL_ATTR); Invite invite = (Invite) model.asMap().get(INVITE_INSTANCE); - - if (invite.getInvitedEmail().compareTo(email) != 0) { response.getWriter().println("The email address invited does not match or is empty."); return; @@ -178,10 +173,7 @@ public class PortletViewController { || firstName.equals("") || lastName == null || lastName.equals("") - || email.equals("") - || password.equals("") - || repassword.equals("") - || password.length() < 8) { + || email.equals("")) { response.getWriter().println("Not all the required fields have been filled."); return; } @@ -189,15 +181,12 @@ public class PortletViewController { response.getWriter().println("The email address invited does not look like a valid email address."); return; } - - String portalURL = PortalUtil.getPortalURL(httpReq, true); - - //checking if the user has been already registered or is already in the portal - User theUser = register(firstName, lastName, email, password, PortalUtil.getScopeGroupId(httpReq), portalURL); - if (theUser != null) - response.getWriter().println("OK"); - else - response.getWriter().println("Something went wrong when creating your account during server communication, please check your connection."); + _log.debug("trying to send the event to create the account for this user to the orchestrator"); + InvitationAcceptedEvent toSend = new InvitationAcceptedEvent(firstName, lastName, email, invite.getControlCode()); + new InvitationAcceptEventPublisher().publish(toSend); + _log.info("Done send event " + toSend.getName() + " for " + toSend.getUser()); + Thread.sleep(1000); + response.getWriter().println("OK"); return; } @@ -206,65 +195,4 @@ public class PortletViewController { return matcher.find(); } - private User register(String firstName, String lastName, String email, String password1, long groupId, String portalURL) { - User toReturn = null; - try{ - _log.debug("Trying createuser (service context instanciated), email: " + email); - Long defaultCompanyId = PortalUtil.getDefaultCompanyId(); - Long defaultUserId = UserLocalServiceUtil.getDefaultUserId(defaultCompanyId); - //ServiceContext instanciated as follows is needed when the Email verification is sent - ServiceContext serviceContext = new ServiceContext(); - serviceContext.setScopeGroupId(groupId); - serviceContext.setPortalURL(portalURL); - serviceContext.setPathMain("/c"); - - boolean autoPassword = false; - Locale locale = new Locale("en_US"); - int prefixId = 0; - int suffixId = 0; - int birthdayMonth = 1; - int birthdayDay = 1; - int birthdayYear = 1970; - String password2 = password1; - toReturn = UserLocalServiceUtil.addUser( - defaultUserId, - defaultCompanyId, - autoPassword, - password1, - password2, - true, - "", - email, - 0L, - "", - locale, - firstName, - "", - lastName, - prefixId, - suffixId, - true, - birthdayMonth, - birthdayDay, - birthdayYear, - "", - null, - null, - null, - null, - false, - serviceContext); - _log.debug("CreateUser " + lastName + " SUCCESS"); - UserLocalServiceUtil.updateEmailAddressVerified(toReturn.getUserId(), true); - UserLocalServiceUtil.updateAgreedToTermsOfUse(toReturn.getUserId(), false); - UserLocalServiceUtil.updatePasswordReset(toReturn.getUserId(), false); - - } - catch(Exception e){ - // unable to create.. we need to delete it from the list of users - _log.error("Unable to create the user " + email + " in liferay.", e); - - } - return toReturn; - } } diff --git a/src/main/webapp/WEB-INF/jsp/view.jsp b/src/main/webapp/WEB-INF/jsp/view.jsp index c7137d6..c40f6f5 100644 --- a/src/main/webapp/WEB-INF/jsp/view.jsp +++ b/src/main/webapp/WEB-INF/jsp/view.jsp @@ -25,9 +25,7 @@ data : { email : $("#email").val(), firstname : $("#firstname").val(), - lastname : $("#lastname").val(), - password : $("#password").val(), - repassword : $("#repassword").val() + lastname : $("#lastname").val() }, success : function(data) { $('#loadingAjaxCallback').css("display", "none"); @@ -61,9 +59,9 @@