works like a charm

This commit is contained in:
Massimiliano Assante 2020-07-24 16:56:32 +02:00
parent 6ffee51961
commit 80f9801db3
6 changed files with 38 additions and 140 deletions

View File

@ -12,7 +12,7 @@
<artifactId>accept-invite-portlet</artifactId> <artifactId>accept-invite-portlet</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<name>accept-invite-portlet Portlet</name> <name>accept-invite-portlet Portlet</name>
<version>1.2.0-SNAPSHOT</version> <version>2.0.0-SNAPSHOT</version>
<description> <description>
accept-invite-portlet manage the sent invitations accept-invite-portlet manage the sent invitations
</description> </description>

View File

@ -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();
}
}

View File

@ -27,6 +27,7 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.gcube.common.portal.PortalContext; 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.DBCassandraAstyanaxImpl;
import org.gcube.portal.databook.server.DatabookStore; import org.gcube.portal.databook.server.DatabookStore;
import org.gcube.portal.databook.shared.Invite; import org.gcube.portal.databook.shared.Invite;
@ -153,21 +154,15 @@ public class PortletViewController {
String email = ParamUtil.getString(request, "email"); String email = ParamUtil.getString(request, "email");
String firstName = ParamUtil.getString(request, "firstname"); String firstName = ParamUtil.getString(request, "firstname");
String lastName = ParamUtil.getString(request, "lastname"); String lastName = ParamUtil.getString(request, "lastname");
String password = ParamUtil.getString(request, "password"); //
String repassword = ParamUtil.getString(request, "repassword");
_log.info("firstName=" + firstName); _log.info("firstName=" + firstName);
_log.info("lastName=" + lastName); _log.info("lastName=" + lastName);
_log.info("email=" + email); _log.info("email=" + email);
_log.info("password=" + password);
_log.info("repassword=" + repassword);
HttpServletRequest httpReq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request)); HttpServletRequest httpReq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request));
Model model = (Model) httpReq.getSession().getAttribute(MODEL_ATTR); Model model = (Model) httpReq.getSession().getAttribute(MODEL_ATTR);
Invite invite = (Invite) model.asMap().get(INVITE_INSTANCE); Invite invite = (Invite) model.asMap().get(INVITE_INSTANCE);
if (invite.getInvitedEmail().compareTo(email) != 0) { if (invite.getInvitedEmail().compareTo(email) != 0) {
response.getWriter().println("The email address invited does not match or is empty."); response.getWriter().println("The email address invited does not match or is empty.");
return; return;
@ -178,10 +173,7 @@ public class PortletViewController {
|| firstName.equals("") || firstName.equals("")
|| lastName == null || lastName == null
|| lastName.equals("") || lastName.equals("")
|| email.equals("") || email.equals("")) {
|| password.equals("")
|| repassword.equals("")
|| password.length() < 8) {
response.getWriter().println("Not all the required fields have been filled."); response.getWriter().println("Not all the required fields have been filled.");
return; return;
} }
@ -189,15 +181,12 @@ public class PortletViewController {
response.getWriter().println("The email address invited does not look like a valid email address."); response.getWriter().println("The email address invited does not look like a valid email address.");
return; return;
} }
_log.debug("trying to send the event to create the account for this user to the orchestrator");
String portalURL = PortalUtil.getPortalURL(httpReq, true); InvitationAcceptedEvent toSend = new InvitationAcceptedEvent(firstName, lastName, email, invite.getControlCode());
new InvitationAcceptEventPublisher().publish(toSend);
//checking if the user has been already registered or is already in the portal _log.info("Done send event " + toSend.getName() + " for " + toSend.getUser());
User theUser = register(firstName, lastName, email, password, PortalUtil.getScopeGroupId(httpReq), portalURL); Thread.sleep(1000);
if (theUser != null) response.getWriter().println("OK");
response.getWriter().println("OK");
else
response.getWriter().println("Something went wrong when creating your account during server communication, please check your connection.");
return; return;
} }
@ -206,65 +195,4 @@ public class PortletViewController {
return matcher.find(); 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;
}
} }

View File

@ -25,9 +25,7 @@
data : { data : {
email : $("#email").val(), email : $("#email").val(),
firstname : $("#firstname").val(), firstname : $("#firstname").val(),
lastname : $("#lastname").val(), lastname : $("#lastname").val()
password : $("#password").val(),
repassword : $("#repassword").val()
}, },
success : function(data) { success : function(data) {
$('#loadingAjaxCallback').css("display", "none"); $('#loadingAjaxCallback').css("display", "none");
@ -61,9 +59,9 @@
<div id="successDiv" style="display: none;" class="alert alert-success"> <div id="successDiv" style="display: none;" class="alert alert-success">
<h1>Well done!</h1> <h1>Well done!</h1>
Your account has been successfully created! You will now be asked to Your account is being created! You will be now asked to
sign in using your yet created account. Please, click on the button sign in: use your email and the temporary password received in the invite email, then choose your password. Please, click on the button
below to continue. below to sign in.
<% <%
String acceptInviteURL = request.getAttribute("landingPage") + "/explore?" + InvitesManager.SITEID_ATTR String acceptInviteURL = request.getAttribute("landingPage") + "/explore?" + InvitesManager.SITEID_ATTR
+ "=" + request.getAttribute("groupId"); + "=" + request.getAttribute("groupId");
@ -91,9 +89,7 @@
src="<%=renderRequest.getContextPath()%>/images/loader.gif" /> src="<%=renderRequest.getContextPath()%>/images/loader.gif" />
<c:choose> <c:choose>
<c:when test="${empty invitedUser}"> <c:when test="${empty invitedUser}">
<c:out escapeXml="true" To accept the invite, you can either create a new account entering your data below or
value="${inviteInstance.controlCode}" />
To accept the invite, you can choose to create a new account by filling in the information below or
<a href="${academicRedirectURL}">sign up with your <a href="${academicRedirectURL}">sign up with your
academic/social account</a>. academic/social account</a>.
<br /> <br />
@ -102,9 +98,7 @@
<div class="row-fluid"> <div class="row-fluid">
<div class="span4"> <div class="span4">
<fieldset> <fieldset>
<label>Email (Not editable)</label> <input type="text" <label id="labelFirstName">First
name="email" value="${inviteInstance.invitedEmail}" readonly
id="email" style="color: #999;" /> <label id="labelFirstName">First
Name (Required)</label> <input type="text" id="firstname" /> <label Name (Required)</label> <input type="text" id="firstname" /> <label
id="labelLastName">Last Name (Required)</label> <input id="labelLastName">Last Name (Required)</label> <input
type="text" id="lastname" /> type="text" id="lastname" />
@ -112,13 +106,16 @@
</div> </div>
<div class="span4"> <div class="span4">
<fieldset> <fieldset>
<label id="labelPwd1">Password</label> <input type="password" <!-- <label id="labelPwd1">Password</label> <input type="password" -->
id="password" /> <label id="labelPwd2">Confirm <!-- id="password" /> <label id="labelPwd2">Confirm -->
Password</label> <input type="password" id="repassword" /> <label <!-- Password</label> <input type="password" id="repassword" /> <label -->
style="display: none" id="labelPasswordDontMatch">Passwords <!-- style="display: none" id="labelPasswordDontMatch">Passwords -->
don't match</label> <label style="display: none" <!-- don't match</label> <label style="display: none" -->
id="labelPasswordTooShort">Password must be at least 8 <!-- id="labelPasswordTooShort">Password must be at least 8 -->
chars length</label> <!-- chars length</label> -->
<label>Email (Not editable)</label> <input type="text"
name="email" value="${inviteInstance.invitedEmail}" readonly
id="email" style="color: #999;" />
<div style="margin-top: 20px;"> <div style="margin-top: 20px;">
<button class="btn-primary btn-large" type="button" <button class="btn-primary btn-large" type="button"
id="createAccountButton">Continue</button> id="createAccountButton">Continue</button>

View File

@ -1,9 +1,9 @@
name=accept-invite-portlet name=accept-invite-portlet
module-group-id=liferay module-group-id=liferay
module-incremental-version=1 module-incremental-version=2
tags= tags=
short-description= short-description=
change-log= change-log=
page-url=http://www.gcube-system.org page-url=http://www.gcube-system.org
author=M. Assante author=M. Assante
licenses=EUPL licenses=EUPL

View File

@ -17,43 +17,7 @@ $(document).ready(function(){
$('#labelLastName').text("Last Name (Required)"); $('#labelLastName').text("Last Name (Required)");
} }
var passwd1 = $('#password'); if (lastnameBox != "" && firstnameBox != "") {
var labelPwd1 = $('#labelPwd1');
var passwd2 = $('#repassword');
var labelPwd2 = $('#labelPwd2');
labelPwd1.addClass( passwd1.val().length === 0 ? 'has-error' : 'has-success' );
labelPwd2.addClass( passwd2.val().length === 0 ? 'has-error' : 'has-success' );
var nomatch = $('#labelPasswordDontMatch');
if (passwd1.val() !== passwd2.val()) {
nomatch.css("display","block");
nomatch.css("color","red");
labelPwd1.addClass( passwd1.val() !== passwd2.val() ? 'has-error' : 'has-success' )
.removeClass( passwd1.val() === passwd2.val() ? 'has-error' : 'has-success' );
labelPwd2.addClass( passwd1.val() !== passwd2.val() ? 'has-error' : 'has-success' )
.removeClass( passwd1.val() === passwd2.val() ? 'has-error' : 'has-success' );
}
else {
nomatch.css("display","none");
}
var shortpwd = $('#labelPasswordTooShort');
if (passwd1.val().length > 0 && passwd1.val().length < 8) {
shortpwd.css("display","block");
shortpwd.css("color","red");
labelPwd1.addClass(passwd1.val().length < 8 ? 'has-error' : 'has-success' )
.removeClass(passwd1.val().length < 8 ? 'has-error' : 'has-success' );
labelPwd2.addClass(passwd2.val().length < 8 ? 'has-error' : 'has-success' )
.removeClass(passwd2.val().length < 8 ? 'has-error' : 'has-success' );
}
else {
shortpwd.css("display","none");
}
if (passwd1.val() == passwd2.val() && passwd1.val().length >= 8 && lastnameBox != "" && firstnameBox != "") {
doCallback(); doCallback();
} }