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>
<packaging>war</packaging>
<name>accept-invite-portlet Portlet</name>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<description>
accept-invite-portlet manage the sent invitations
</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.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;
}
}

View File

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

View File

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

View File

@ -17,43 +17,7 @@ $(document).ready(function(){
$('#labelLastName').text("Last Name (Required)");
}
var passwd1 = $('#password');
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 != "") {
if (lastnameBox != "" && firstnameBox != "") {
doCallback();
}