Massimiliano Assante 2017-12-04 18:19:43 +00:00
parent 6bbbdeca59
commit d5aedc3c63
3 changed files with 163 additions and 57 deletions

View File

@ -15,6 +15,8 @@
package org.gcube.portlets.user.acceptinvite; package org.gcube.portlets.user.acceptinvite;
import java.io.IOException; import java.io.IOException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.RenderRequest; import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse; import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest; import javax.portlet.ResourceRequest;
@ -36,7 +38,9 @@ import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.bind.annotation.ActionMapping;
import org.springframework.web.portlet.bind.annotation.RenderMapping; import org.springframework.web.portlet.bind.annotation.RenderMapping;
import org.springframework.web.portlet.bind.annotation.ResourceMapping; import org.springframework.web.portlet.bind.annotation.ResourceMapping;
@ -62,11 +66,11 @@ public class PortletViewController {
private static String PAGE_VRE_NOTFOUND = "vre-notfound"; private static String PAGE_VRE_NOTFOUND = "vre-notfound";
private static String PAGE_INVITE_EXPIRED = "invite-expired"; private static String PAGE_INVITE_EXPIRED = "invite-expired";
private static String PAGE_INVITE_PROCESS = "view"; private static String PAGE_INVITE_PROCESS = "view";
public static String INVITE_INSTANCE = "inviteInstance"; public static String INVITE_INSTANCE = "inviteInstance";
private static DatabookStore store; private static DatabookStore store;
/** /**
* *
* @return the unique instance of the store * @return the unique instance of the store
@ -77,13 +81,12 @@ public class PortletViewController {
} }
return store; return store;
} }
// .append(PortalContext.getConfiguration().getSiteLandingPagePath(request))
@RenderMapping @RenderMapping
public String handleRenderRequest(RenderRequest request,RenderResponse response, Model model) { public String handleRenderRequest(RenderRequest request,RenderResponse response, Model model) {
HttpServletRequest httpReq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request)); HttpServletRequest httpReq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request));
final String INVITE_ID_ENCODED = new String(Base64.encodeBase64(InvitesManager.INVITEID_ATTR.getBytes())); final String INVITE_ID_ENCODED = new String(Base64.encodeBase64(InvitesManager.INVITEID_ATTR.getBytes()));
final String SITE_ID_ENCODED = new String(Base64.encodeBase64(InvitesManager.SITEID_ATTR.getBytes())); final String SITE_ID_ENCODED = new String(Base64.encodeBase64(InvitesManager.SITEID_ATTR.getBytes()));
if (httpReq.getParameter(INVITE_ID_ENCODED) == null || SITE_ID_ENCODED == null) if (httpReq.getParameter(INVITE_ID_ENCODED) == null || SITE_ID_ENCODED == null)
@ -92,10 +95,10 @@ public class PortletViewController {
String siteIdEncoded = (String) httpReq.getParameter(SITE_ID_ENCODED); String siteIdEncoded = (String) httpReq.getParameter(SITE_ID_ENCODED);
String inviteId= new String(Base64.decodeBase64(inviteIdEncoded)); String inviteId= new String(Base64.decodeBase64(inviteIdEncoded));
String groupId = new String(Base64.decodeBase64(siteIdEncoded)); String groupId = new String(Base64.decodeBase64(siteIdEncoded));
_log.info("GOT inviteId=" + inviteId); _log.info("GOT inviteId=" + inviteId);
_log.info("siteId=" + groupId); _log.info("siteId=" + groupId);
Group site = null; Group site = null;
try { try {
site = GroupLocalServiceUtil.getGroup(Long.parseLong(groupId)); site = GroupLocalServiceUtil.getGroup(Long.parseLong(groupId));
@ -103,20 +106,20 @@ public class PortletViewController {
e1.printStackTrace(); e1.printStackTrace();
return PAGE_VRE_NOTFOUND; return PAGE_VRE_NOTFOUND;
} }
Invite invite = null; Invite invite = null;
try { try {
invite = getStore().readInvite(inviteId); invite = getStore().readInvite(inviteId);
} catch (InviteIDNotFoundException | InviteStatusNotFoundException e) { } catch (InviteIDNotFoundException | InviteStatusNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
return PAGE_INVITE_NOTFOUND; return PAGE_INVITE_NOTFOUND;
} }
if (invite.getStatus() == InviteStatus.ACCEPTED) if (invite.getStatus() == InviteStatus.ACCEPTED)
return PAGE_INVITE_EXPIRED; return PAGE_INVITE_EXPIRED;
GCubeUser invitedUser = null; GCubeUser invitedUser = null;
try { try {
invitedUser = new LiferayUserManager().getUserByEmail(invite.getInvitedEmail()); invitedUser = new LiferayUserManager().getUserByEmail(invite.getInvitedEmail());
@ -124,23 +127,24 @@ public class PortletViewController {
} catch (UserManagementSystemException | UserRetrievalFault e) { } catch (UserManagementSystemException | UserRetrievalFault e) {
_log.info("No user account exist with this email: " + invite.getInvitedEmail()); _log.info("No user account exist with this email: " + invite.getInvitedEmail());
} }
//we set the invite instance retrieved in the model //we set the invite instance retrieved in the model
model.addAttribute(INVITE_INSTANCE, invite); model.addAttribute(INVITE_INSTANCE, invite);
model.addAttribute("vreName", site.getName()); model.addAttribute("vreName", site.getName());
model.addAttribute("vreFriendlyURL", site.getFriendlyURL()); model.addAttribute("vreFriendlyURL", site.getFriendlyURL());
model.addAttribute("groupId", site.getGroupId()); model.addAttribute("groupId", site.getGroupId());
model.addAttribute("landingPage", PortalContext.getConfiguration().getSiteLandingPagePath(httpReq)); model.addAttribute("landingPage", PortalContext.getConfiguration().getSiteLandingPagePath(httpReq));
return PAGE_INVITE_PROCESS; return PAGE_INVITE_PROCESS;
} }
@ResourceMapping(value="findState") @ResourceMapping(value="findState")
public void findStateForCountry(ResourceRequest request, ResourceResponse response) throws IOException { public void findStateForCountry(ResourceRequest request, ResourceResponse response) throws IOException {
String countryName = ParamUtil.getString(request, "countryName"); String countryName = ParamUtil.getString(request, "countryName");
_log.info("countryName=" + countryName);
JSONArray stateArray = JSONFactoryUtil.createJSONArray(); JSONArray stateArray = JSONFactoryUtil.createJSONArray();
JSONObject stateObject,stateObject2; JSONObject stateObject,stateObject2;
if(countryName.equalsIgnoreCase("india")) if(countryName.equalsIgnoreCase("india"))

View File

@ -11,28 +11,101 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<portlet:resourceURL id="findState" var="findState"></portlet:resourceURL> <portlet:resourceURL id="findState" var="findState"></portlet:resourceURL>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function(){ $(document).ready(function(){
$( "#country" ).change(function() { $( "#createAccountButton" ).click(function() {
$.ajax({ var firstnameBox = $.trim( $('#firstname').val() )
url: "${findState}" , if (firstnameBox == "") {
type: 'POST', $('#labelFirstName').css("color","red");
datatype:'json', $('#labelFirstName').text("First Name (This field is required)");
data: { } else {
countryName: $("#country").val() $('#labelFirstName').css("color","#555");
}, $('#labelFirstName').text("First Name (Required)");
success: function(data){ }
var content= JSON.parse(data); var lastnameBox = $.trim( $('#lastname').val() )
$('#state').html('');// to clear the previous option if (lastnameBox == "") {
$.each(content, function(i, state) { $('#labelLastName').css("color","red");
$('#state').append($('<option>').text(state.name).attr('value', state.stateId)); $('#labelLastName').text("Last Name (This field is required)");
}); } else {
} $('#labelLastName').css("color","#555");
}); $('#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' );
return;
}
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' );
return;
}
else {
shortpwd.css("display","none");
}
});
$( "#country" ).change(function() {
$.ajax({
url: "${findState}" ,
type: 'POST',
datatype:'json',
data: {
countryName: $("#country").val()
},
success: function(data){
var content= JSON.parse(data);
$('#state').html('');// to clear the previous option
$.each(content, function(i, state) {
$('#state').append($('<option>').text(state.name).attr('value', state.stateId));
});
}
});
});
});
</script> </script>
<b>Change the Country State Change By Ajax</b> <br><br>
Country:
<select id="country" name="country">
<option value="select">Select Country</option>
<option value="india">India</option>
<option value="usa">USA</option>
</select>
<br><br>
State:
<select id="state" name="state">
</select>
<h1> <h1>
Hello Hello
<c:out escapeXml="true" value="${invitedUser.firstName}" />!<br> <c:out escapeXml="true" value="${invitedUser.firstName}" />!<br>
@ -47,8 +120,41 @@ $( "#country" ).change(function() {
Virtual Research Environment. Virtual Research Environment.
<c:choose> <c:choose>
<c:when test="${empty invitedUser}"> <c:when test="${empty invitedUser}">
var1 is empty or null.landingPage <br />
<span style="font-style: italic;">Please note</span>: the invite is valid for your email <a
href="mailto:<c:out escapeXml="true" value="${inviteInstance.invitedEmail}" />">
<c:out escapeXml="true" value="${inviteInstance.invitedEmail}" />
</a> only. To accept the invite, please fill in the information below:
<br /> <br />
<div class="container-fluid">
<div class="row-fluid">
<div class="span4">
<fieldset>
<label>Email (Not editable)</label> <input type="text" name="email"
value="${inviteInstance.invitedEmail}" readonly style="color: #999;"/>
<label id="labelFirstName">First Name (Required)</label>
<input type="text" id="firstname" />
<label id="labelLastName">Last Name (Required)</label>
<input type="text" id="lastname" />
</fieldset>
</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">Passwords must be at least 8 chars length</label>
<div style="margin-top: 20px;">
<button class="btn-primary btn-large" type="button" id="createAccountButton">Continue</button>
</div>
</fieldset>
</div>
</div>
</div>
</c:when> </c:when>
<c:otherwise> <c:otherwise>
This invite is valid for your email <a This invite is valid for your email <a
@ -56,9 +162,16 @@ $( "#country" ).change(function() {
<c:out escapeXml="true" value="${inviteInstance.invitedEmail}" /> <c:out escapeXml="true" value="${inviteInstance.invitedEmail}" />
</a> only, you will be asked to enter your password associated to it on this portal. </a> only, you will be asked to enter your password associated to it on this portal.
<% String exploreURL = request.getAttribute("landingPage") + "/explore?" + InvitesManager.SITEID_ATTR+"="+request.getAttribute("groupId");%> <%
<p class="lead"> String exploreURL = request.getAttribute("landingPage") + "/explore?" + InvitesManager.SITEID_ATTR
<button class="btn btn-large btn-primary" onclick="window.location.href='<%= exploreURL %>'" type="button">Go to <c:out escapeXml="true" value="${vreName}" /></button> + "=" + request.getAttribute("groupId");
%>
<p class="lead">
<button class="btn btn-large btn-primary"
onclick="window.location.href='<%=exploreURL%>'" type="button">
Accept invite on
<c:out escapeXml="true" value="${vreName}" />
</button>
</p> </p>
</c:otherwise> </c:otherwise>
</c:choose> </c:choose>
@ -66,21 +179,4 @@ $( "#country" ).change(function() {
</p> </p>
<br> <br>
<c:out escapeXml="true" value="${inviteInstance} " /> <c:out escapeXml="true" value="${inviteInstance} " />
<b>Change the Country State Change By Ajax</b>
<br>
<br>
Country:
<select id="country" name="country">
<option value="select">Select Country</option>
<option value="india">India</option>
<option value="usa">USA</option>
</select>
<br>
<br>
State:
<select id="state" name="state">
</select>

View File

@ -0,0 +1,6 @@
.has-error {
color: red !important;
}
.has-success {
color: green !important;
}