revised invite method to avoid double step in case of registration

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portal/invites-common-library@158899 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2017-11-29 15:55:50 +00:00
parent 894d7cad0a
commit 51d4eda578
2 changed files with 31 additions and 12 deletions

View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portal</groupId>
<artifactId>invites-common-library</artifactId>
<version>1.4.0-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>
<packaging>jar</packaging>
<description>
gCube Invites Common Library is a common library containing shared code for Inviting external users to portal VREs.

View File

@ -10,7 +10,9 @@ import java.util.UUID;
import javax.mail.internet.AddressException;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.codec.binary.Base64;
import org.gcube.common.portal.PortalContext;
import org.gcube.portal.databook.client.GCubeSocialNetworking;
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
import org.gcube.portal.databook.server.DatabookStore;
import org.gcube.portal.databook.shared.Invite;
@ -39,6 +41,10 @@ import org.slf4j.LoggerFactory;
*/
public class InvitesManager {
private static final Logger _log = LoggerFactory.getLogger(InvitesManager.class);
private static final String SITEID_ATTR ="siteId";
private static final String INVITEID_ATTR ="inviteId";
private static final String INVITE_PAGE_ENDPOINT = "manage-invite";
private static InvitesManager instance;
private static DatabookStore store;
@ -82,7 +88,7 @@ public class InvitesManager {
try {
String vreName = PortalContext.getConfiguration().getCurrentGroupName(request);
result = store.saveInvite(invite);
emailResult = sendInviteEmail(request, currUser, vreName, name, email, vreDescription);
emailResult = sendInviteEmail(request, invite, currUser, vreName, name, email, vreDescription);
notifyInviteSent(request, currUser, currScope, invite, vreName);
} catch (AddressException e) {
@ -96,6 +102,7 @@ public class InvitesManager {
private Boolean sendInviteEmail(
HttpServletRequest request,
Invite invite,
GCubeUser currUser,
String vreName,
String name,
@ -111,12 +118,24 @@ public class InvitesManager {
String subject = "Join me on " + vreName + " VRE";
long groupId = PortalContext.getConfiguration().getCurrentGroupId(request);
final String linkToAcceptInvite = gatewayURL + PortalContext.getConfiguration().getSiteLandingPagePath(request)+"/explore?siteId="+groupId;
final String linkToCreateAccount = gatewayURL + "/?p_p_id=58&p_p_lifecycle=0&p_p_state=maximized&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&saveLastPath=false&_58_struts_action=%2Flogin%2Fcreate_account";
StringBuilder getParamsEncoded = new StringBuilder(new String(Base64.encodeBase64(INVITEID_ATTR.getBytes())))
.append("=")
.append(new String(Base64.encodeBase64(invite.getKey().getBytes())))
.append("&")
.append(new String(Base64.encodeBase64(SITEID_ATTR.getBytes())))
.append("=")
.append(new String(Base64.encodeBase64((""+groupId).getBytes())));
StringBuilder linkToAcceptInvite = new StringBuilder(gatewayURL)
.append(PortalContext.getConfiguration().getSiteLandingPagePath(request))
.append(INVITE_PAGE_ENDPOINT)
.append("?")
.append(getParamsEncoded);
EmailTemplateService.send(
subject,
new TemplatedJoinMeInvite(gatewayName, gatewayURL, currUser, name, vreName, vreDescription, linkToAcceptInvite, linkToCreateAccount),
new TemplatedJoinMeInvite(gatewayName, gatewayURL, currUser, name, vreName, vreDescription, linkToAcceptInvite.toString()),
request,
new Recipient(email), new Recipient(new EmailAddress(currUser.getEmail()), RecipientType.CC));