works like a charm

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/join-vre@126288 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-03-25 10:47:56 +00:00
parent 747be36ea8
commit e0674f99c3
9 changed files with 80 additions and 194 deletions

View File

@ -4,6 +4,9 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="invites-common-library-1.2.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/invites-common-library/invites-common-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/> <property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
<property name="context-root" value="join-vre"/> <property name="context-root" value="join-vre"/>
</wb-module> </wb-module>

View File

@ -30,10 +30,7 @@ public class JoinVRE implements EntryPoint {
private void checkIsReferral() { private void checkIsReferral() {
logger.log(Level.INFO,"checkIsReferral()"); logger.log(Level.INFO,"checkIsReferral()");
if (getSiteLiferayId() == null) { if (getSiteLiferayId() == null) {
ResponsivePanel rp = null; displayVREs();
rp = displayVREs();
// //TODO: REMOVE
// checkInvitation(new VRE(), 1, rp);
} }
else { else {
Long vreId = -1L; Long vreId = -1L;

View File

@ -20,6 +20,7 @@ import com.google.gwt.user.client.ui.Widget;
public class AccessVREDialog extends Composite { public class AccessVREDialog extends Composite {
private final JoinServiceAsync joinService = GWT.create(JoinService.class); private final JoinServiceAsync joinService = GWT.create(JoinService.class);
private final static boolean IS_INVITATION = false;
private static AccessVREDialogUiBinder uiBinder = GWT private static AccessVREDialogUiBinder uiBinder = GWT
.create(AccessVREDialogUiBinder.class); .create(AccessVREDialogUiBinder.class);
@ -30,7 +31,7 @@ public class AccessVREDialog extends Composite {
@UiField Button confirmRequest; @UiField Button confirmRequest;
@UiField HelpBlock helpBlock; @UiField HelpBlock helpBlock;
@UiField Icon loading; @UiField Icon loading;
private boolean isInvitation = false;
VRE myVRE = null; VRE myVRE = null;
public AccessVREDialog(final VRE vre) { public AccessVREDialog(final VRE vre) {
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
@ -43,7 +44,7 @@ public class AccessVREDialog extends Composite {
} }
public void show() { public void show() {
String headerText = isInvitation ? "Invitation to " + myVRE.getName() : "Join request for " + myVRE.getName(); String headerText = "Join VRE request for " + myVRE.getName();
m.setTitle(headerText); m.setTitle(headerText);
m.show(); m.show();
} }
@ -56,7 +57,7 @@ public class AccessVREDialog extends Composite {
void confirm(ClickEvent e) { void confirm(ClickEvent e) {
helpBlock.setText("Registering to " + myVRE.getName() + " please wait ... "); helpBlock.setText("Registering to " + myVRE.getName() + " please wait ... ");
loading.setVisible(true); loading.setVisible(true);
joinService.registerUser(myVRE.getinfraScope(), myVRE.getId(), isInvitation, new AsyncCallback<Boolean>() { joinService.registerUser(myVRE.getinfraScope(), myVRE.getId(), IS_INVITATION, new AsyncCallback<Boolean>() {
@Override @Override
public void onSuccess(Boolean result) { public void onSuccess(Boolean result) {

View File

@ -1,26 +1,29 @@
package org.gcube.portlets.user.joinvre.client.ui; package org.gcube.portlets.user.joinvre.client.ui;
import org.gcube.portal.databook.shared.Invite;
import org.gcube.portal.databook.shared.UserInfo; import org.gcube.portal.databook.shared.UserInfo;
import org.gcube.portlets.user.joinvre.client.JoinService; import org.gcube.portlets.user.joinvre.client.JoinService;
import org.gcube.portlets.user.joinvre.client.JoinServiceAsync; import org.gcube.portlets.user.joinvre.client.JoinServiceAsync;
import org.gcube.portlets.user.joinvre.shared.VRE; import org.gcube.portlets.user.joinvre.shared.VRE;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.HelpBlock; import com.github.gwtbootstrap.client.ui.HelpBlock;
import com.github.gwtbootstrap.client.ui.Icon; import com.github.gwtbootstrap.client.ui.Icon;
import com.github.gwtbootstrap.client.ui.Image; import com.github.gwtbootstrap.client.ui.Image;
import com.github.gwtbootstrap.client.ui.Modal; import com.github.gwtbootstrap.client.ui.Modal;
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiField;
import com.github.gwtbootstrap.client.ui.Button; import com.google.gwt.uibinder.client.UiHandler;
import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.google.gwt.user.client.Window.Location;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
public class AccessViaInviteDialog extends Composite { public class AccessViaInviteDialog extends Composite {
private final JoinServiceAsync joinService = GWT.create(JoinService.class); private final JoinServiceAsync joinService = GWT.create(JoinService.class);
private final static boolean IS_INVITATION = true;
private static AccessViaInviteDialogUiBinder uiBinder = GWT.create(AccessViaInviteDialogUiBinder.class); private static AccessViaInviteDialogUiBinder uiBinder = GWT.create(AccessViaInviteDialogUiBinder.class);
interface AccessViaInviteDialogUiBinder extends interface AccessViaInviteDialogUiBinder extends
@ -45,8 +48,9 @@ public class AccessViaInviteDialog extends Composite {
joinService.readInvite(inviteId, new AsyncCallback<UserInfo>() { joinService.readInvite(inviteId, new AsyncCallback<UserInfo>() {
@Override @Override
public void onSuccess(UserInfo invitingUser) { public void onSuccess(UserInfo invitingUser) {
helpBlock.setText("You have been invited by " +invitingUser.getFullName()); helpBlock.setText("You have been invited by " +invitingUser.getFullName() + ", to accept the invite, please click on the accept invite button below.");
avatarImage.setUrl(invitingUser.getAvatarId()); avatarImage.setUrl(invitingUser.getAvatarId());
avatarImage.setVisible(true);
confirmRequest.setType(ButtonType.PRIMARY); confirmRequest.setType(ButtonType.PRIMARY);
confirmRequest.setEnabled(true); confirmRequest.setEnabled(true);
loading.removeFromParent(); loading.removeFromParent();
@ -65,6 +69,28 @@ public class AccessViaInviteDialog extends Composite {
m.setTitle(headerText); m.setTitle(headerText);
m.show(); m.show();
} }
@UiHandler("close")
void handleClick(ClickEvent e) {
m.hide();
}
@UiHandler("confirmRequest")
void confirm(ClickEvent e) {
helpBlock.setText("Registering to " + myVRE.getName() + " please wait ... ");
loading.setVisible(true);
joinService.registerUser(myVRE.getinfraScope(), myVRE.getId(), IS_INVITATION, new AsyncCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
Location.assign(myVRE.getFriendlyURL());
}
@Override
public void onFailure(Throwable caught) {
confirmRequest.removeFromParent();
m.setTitle("An error occurred! Your request has not been sent");
helpBlock.setText("An email with the cause of the error has been sent to the support team, we'll be back to you shortly.");
}
});
}
} }

View File

@ -1,106 +0,0 @@
package org.gcube.portlets.user.joinvre.server;
import java.util.Date;
import java.util.Properties;
import javax.mail.Address;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.gcube.common.portal.PortalContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A class for sending email
*
* @author M. Assante
*
*/
public class EmailNotification {
private static final String SENDER_EMAIL = "notificationSenderEmail";
private static final String GATEWAY_NAME = "portalinstancename";
/**
* The sender of the email
*/
private String emailSender;
/**
* The recipients of the email
*/
private String emailrecipients[];
/**
* Email's subject
*/
private String emailSubject;
/**
* Email's body message
*/
private String emailBody;
private String portalName;
/** Logger */
private static Logger _log = LoggerFactory.getLogger(EmailNotification.class);
/**
* Class's constructor
*
* @param sender
* @param recipients
* @param subject
* @param body
*/
public EmailNotification(String sender, String recipients[], String subject, String body) {
this.emailSender = PortalContext.getConfiguration().getSenderEmail();
this.emailrecipients = recipients;
this.emailSubject = subject;
this.emailBody = body;
this.portalName = PortalContext.getConfiguration().getGatewayName();
}
public void sendEmail() {
Properties props = System.getProperties();
String mailServiceHost = "localhost";
props.put("mail.smtp.host", mailServiceHost);
String mailServicePort = "25";
props.put("mail.smtp.port", mailServicePort);
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
Message mimeMessage = new MimeMessage(session);
try {
// EMAIL SENDER
Address from = new InternetAddress(emailSender, portalName);
mimeMessage.setHeader("Content-Type", "text/html; charset=UTF-8");
mimeMessage.setFrom(from);
// EMAIL RECIPIENTS
for (int i=0; i<emailrecipients.length; i++) {
Address address = new InternetAddress(emailrecipients[i]);
mimeMessage.addRecipient(Message.RecipientType.TO, address);
}
mimeMessage.setSubject(emailSubject);
// mimeMessage.setText(emailBody);
mimeMessage.setContent(emailBody, "text/html; charset=UTF-8");
mimeMessage.setSentDate(new Date());
Transport.send(mimeMessage);
} catch (Exception e) {
e.printStackTrace();
_log.error("Failed to send the email message.", e);
}
}
}

View File

@ -6,8 +6,6 @@ import java.util.Date;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager; import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.portal.CustomAttributeKeys; import org.gcube.common.portal.CustomAttributeKeys;
@ -19,8 +17,6 @@ import org.gcube.portal.databook.server.DatabookStore;
import org.gcube.portal.databook.shared.Invite; import org.gcube.portal.databook.shared.Invite;
import org.gcube.portal.databook.shared.InviteStatus; import org.gcube.portal.databook.shared.InviteStatus;
import org.gcube.portal.databook.shared.UserInfo; import org.gcube.portal.databook.shared.UserInfo;
import org.gcube.portal.databook.shared.ex.InviteIDNotFoundException;
import org.gcube.portal.databook.shared.ex.InviteStatusNotFoundException;
import org.gcube.portlets.user.joinvre.client.JoinService; import org.gcube.portlets.user.joinvre.client.JoinService;
import org.gcube.portlets.user.joinvre.shared.UserBelonging; import org.gcube.portlets.user.joinvre.shared.UserBelonging;
import org.gcube.portlets.user.joinvre.shared.VRE; import org.gcube.portlets.user.joinvre.shared.VRE;
@ -81,7 +77,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
*/ */
public String getDevelopmentUser() { public String getDevelopmentUser() {
String user = TEST_USER; String user = TEST_USER;
// user = "andrea.rossi"; // user = "andrea.rossi";
return user; return user;
} }
@ -399,7 +395,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
try { try {
ASLSession session = getASLSession(); ASLSession session = getASLSession();
String username = session.getUsername(); String username = session.getUsername();
String gatewayURL = PortalContext.getConfiguration().getGatewayURL(getThreadLocalRequest());
_log.debug("registerUser " +username + " to "+ scope); _log.debug("registerUser " +username + " to "+ scope);
GCubeUser currUser = um.getUserByUsername(username); GCubeUser currUser = um.getUserByUsername(username);
GroupManager gm = new LiferayGroupManager(); GroupManager gm = new LiferayGroupManager();
@ -417,11 +413,11 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
if (inviteId != null) { if (inviteId != null) {
Invite invite = store.readInvite(inviteId); Invite invite = store.readInvite(inviteId);
store.setInviteStatus(scope, session.getUserEmailAddress(), InviteStatus.ACCEPTED); store.setInviteStatus(scope, session.getUserEmailAddress(), InviteStatus.ACCEPTED);
LoginServiceUtil.notifyUserAcceptedInvite(username, scope, getPortalBasicUrl(), gatewayName, invite); LoginServiceUtil.notifyUserAcceptedInvite(username, scope, gatewayURL, gatewayName, invite);
} }
} }
else { else {
LoginServiceUtil.notifyUserSelfRegistration(username, scope, getPortalBasicUrl(), gatewayName); LoginServiceUtil.notifyUserSelfRegistration(username, scope, gatewayURL, gatewayName);
_log.info("notifyUserSelfRegistration sent"); _log.info("notifyUserSelfRegistration sent");
} }
} }
@ -443,23 +439,6 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
} }
return store; return store;
} }
/**
*
* @return the portal basic url, e.g. http://www.foo.com
*/
private String getPortalBasicUrl() {
HttpServletRequest request = this.getThreadLocalRequest();
String toReturn = "";
//protocol
String protocol = (request.isSecure()) ? "https://" : "http://" ;
toReturn += protocol;
//server name
toReturn += request.getServerName();
//port
toReturn += (request.getServerPort() == 80) ? "" : ":"+request.getServerPort() ;
//_log.trace("getPortalBasicUrl: " +toReturn + "request.getServerPort: " + request.getServerPort());
return toReturn;
}
@Override @Override
public String isExistingInvite(long groupId) { public String isExistingInvite(long groupId) {
@ -482,7 +461,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
} }
} }
_log.debug("checking if invite exists for " + email + " on " +infraScope); _log.debug("checking if invite exists for " + email + " on " +infraScope);
return store.isExistingInvite(infraScope, email); return store.isExistingInvite(infraScope, email);
} }
@ -495,8 +474,8 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
return new UserInfo( return new UserInfo(
inviter.getUsername(), inviter.getUsername(),
inviter.getFullname(), inviter.getFullname(),
"/image/user_male_portrait?img_id="+inviter.getUserAvatarId(), inviter.getUserAvatarURL(),
"", "", true, false, null); //TODO: review this method the image don't work "", "", true, false, null);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -5,7 +5,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.gcube.common.portal.PortalContext; import org.gcube.common.portal.mailing.EmailNotification;
import org.gcube.portal.databook.shared.Invite; import org.gcube.portal.databook.shared.Invite;
import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.UserManager; import org.gcube.vomanagement.usermanagement.UserManager;
@ -134,7 +134,7 @@ public class LoginServiceUtil {
adminEmails.toArray(allMails); adminEmails.toArray(allMails);
EmailNotification mailToAdmin = new EmailNotification(PortalContext.getConfiguration().getSenderEmail(), allMails , "[" + gatewayName + "] - Join Request", body.toString()); EmailNotification mailToAdmin = new EmailNotification(allMails , "[" + gatewayName + "] - Join Request", body.toString());
mailToAdmin.sendEmail(); mailToAdmin.sendEmail();
} }
@ -155,31 +155,25 @@ public class LoginServiceUtil {
StringBuffer body = new StringBuffer(); StringBuffer body = new StringBuffer();
body.append("<p>Dear manager of "+ scope +",<br />this email message was automatically generated by " + portalbasicurl +" to inform you that "); body.append("<p>Dear manager of "+ scope +",<br />this email message was automatically generated by " + portalbasicurl +" to inform you that ");
body.append("</p>"); body.append("</p>").append("<p>")
body.append("<p>"); .append("<b>"+name + " " + lastname +"</b> has self registered to the following environment: ")
body.append("<b>"+name + " " + lastname +"</b> has self registered to the following environment: "); .append("<br /><br />")
body.append("<br /><br />"); .append("<b>" + scope+"</b>")
body.append("<b>" + scope+"</b>"); .append("<br />")
body.append("<br />"); .append("<br />")
body.append("<br />"); .append("<b>Username: </b>" + username)
body.append("<b>Username: </b>" + username); .append("<br />")
body.append("<br />"); .append("<b>e-mail: </b>" + currUser.getEmail())
body.append("<b>e-mail: </b>" + currUser.getEmail()); .append("</p>")
body.append("</p>"); .append("<p>")
body.append("<p>"); .append("<br />" + portalbasicurl)
body.append("<br />" + portalbasicurl); .append("</p>");
body.append("</p>");
body.append("<p>");
body.append("WARNING / LEGAL TEXT: This message is intended only for the use of the individual or entity to which it is addressed and may contain"+
" information which is privileged, confidential, proprietary, or exempt from disclosure under applicable law. " +
"If you are not the intended recipient or the person responsible for delivering the message to the intended recipient, you are strictly prohibited from disclosing, distributing, copying, or in any way using this message.");
body.append("</p>");
String[] allMails = new String[adminEmails.size()]; String[] allMails = new String[adminEmails.size()];
adminEmails.toArray(allMails); adminEmails.toArray(allMails);
EmailNotification mailToAdmin = new EmailNotification("no-reply@d4science.org", allMails , "[" + gatewayName + "] - Self Registration", body.toString()); EmailNotification mailToAdmin = new EmailNotification(allMails , "[" + gatewayName + "] - Self Registration", body.toString());
mailToAdmin.sendEmail(); mailToAdmin.sendEmail();
} }
@ -202,31 +196,27 @@ public class LoginServiceUtil {
StringBuffer body = new StringBuffer(); StringBuffer body = new StringBuffer();
body.append("<p>Dear manager of "+ scope +",<br />this email message was automatically generated by " + portalbasicurl +" to inform you that "); body.append("<p>Dear manager of "+ scope +",<br />this email message was automatically generated by " + portalbasicurl +" to inform you that ");
body.append("</p>"); body.append("</p>")
body.append("<p>"); .append("<p>")
body.append("<b>"+name + " " + lastname +"</b> has accepted an invitation to the following environment: "); .append("<b>"+name + " " + lastname +"</b> has accepted an invitation to the following environment: ")
body.append("<br /><br />"); .append("<br /><br />")
body.append("<b>" + scope+"</b>"); .append("<b>" + scope+"</b>")
body.append("<br />"); .append("<br />")
body.append("<br />"); .append("<br />")
body.append("<b>Username: </b>" + username); .append("<b>Username: </b>" + username)
body.append("<br />"); .append("<br />")
body.append("<b>e-mail: </b>" + currUser.getEmail()); .append("<b>e-mail: </b>" + currUser.getEmail())
body.append("</p>"); .append("</p>")
body.append("<p>"); .append("<p>")
body.append("<b>The invitation was sent by " + invite.getSenderFullName() +" (" + invite.getSenderUserId()+") on " + invite.getTime()+"</b>"); .append("<b>The invitation was sent by " + invite.getSenderFullName() +" (" + invite.getSenderUserId()+") on " + invite.getTime()+"</b>")
body.append("</p>"); .append("</p>");
body.append("<p>");
body.append("WARNING / LEGAL TEXT: This message is intended only for the use of the individual or entity to which it is addressed and may contain"+
" information which is privileged, confidential, proprietary, or exempt from disclosure under applicable law. " +
"If you are not the intended recipient or the person responsible for delivering the message to the intended recipient, you are strictly prohibited from disclosing, distributing, copying, or in any way using this message.");
body.append("</p>");
String[] allMails = new String[adminEmails.size()]; String[] allMails = new String[adminEmails.size()];
adminEmails.toArray(allMails); adminEmails.toArray(allMails);
EmailNotification mailToAdmin = new EmailNotification("no-reply@d4science.org", allMails , "[" + gatewayName + "] - Accepted Invitation", body.toString()); EmailNotification mailToAdmin = new EmailNotification(allMails , "[" + gatewayName + "] - Accepted Invitation", body.toString());
mailToAdmin.sendEmail(); mailToAdmin.sendEmail();
} }

View File

@ -20,16 +20,12 @@ import com.liferay.portal.theme.ThemeDisplay;
/** /**
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it * @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/ */
public class JoinVREPortlet extends GenericPortlet { public class JoinVREPortlet extends GenericPortlet {
private static Log _log = LogFactoryUtil.getLog(JoinVREPortlet.class); private static Log _log = LogFactoryUtil.getLog(JoinVREPortlet.class);
public void doView(RenderRequest request, RenderResponse response) public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
throws PortletException, IOException {
_log.info("************************* Rendering JoinVRE Portlet");
response.setContentType("text/html"); response.setContentType("text/html");
try { try {
ScopeHelper.setContext(request); ScopeHelper.setContext(request);

View File

@ -6,7 +6,7 @@
<inherits name='com.google.gwt.activity.Activity' /> <inherits name='com.google.gwt.activity.Activity' />
<inherits name="com.github.gwtbootstrap.Bootstrap" /> <inherits name="com.github.gwtbootstrap.Bootstrap" />
<inherits name='org.gcube.portal.databook.GCubeSocialNetworking' /> <inherits name='org.gcube.portal.databook.GCubeSocialNetworking' />
<!-- <set-property name="user.agent" value="gecko1_8,safari" /> --> <!-- <set-property name="user.agent" value="gecko1_8" /> -->
<!-- Specify the app entry point class. --> <!-- Specify the app entry point class. -->
<entry-point class='org.gcube.portlets.user.joinvre.client.JoinVRE' /> <entry-point class='org.gcube.portlets.user.joinvre.client.JoinVRE' />