ServiceContext instanciated now, it is needed when the Email verification is sent

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/accept-invite-portlet@164550 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2018-02-23 13:11:11 +00:00
parent c4820529ed
commit 33c2996e04
1 changed files with 16 additions and 7 deletions

View File

@ -149,7 +149,7 @@ public class PortletViewController {
@ResourceMapping(value="createAccount")
public void createAccountForUser(ResourceRequest request, ResourceResponse response) throws IOException {
public void createAccountForUser(ResourceRequest request, ResourceResponse response) throws Exception {
String email = ParamUtil.getString(request, "email");
String firstName = ParamUtil.getString(request, "firstname");
String lastName = ParamUtil.getString(request, "lastname");
@ -165,6 +165,8 @@ public class PortletViewController {
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.");
@ -188,8 +190,10 @@ public class PortletViewController {
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);
User theUser = register(firstName, lastName, email, password, PortalUtil.getScopeGroupId(httpReq), portalURL);
if (theUser != null)
response.getWriter().println("OK");
else
@ -202,13 +206,18 @@ public class PortletViewController {
return matcher.find();
}
private User register(String firstName, String lastName, String email, String password1) {
private User register(String firstName, String lastName, String email, String password1, long groupId, String portalURL) {
User toReturn = null;
try{
_log.debug("Trying createuser " + email);
_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;
@ -243,8 +252,8 @@ public class PortletViewController {
null,
null,
null,
true,
new ServiceContext());
false,
serviceContext);
_log.debug("CreateUser " + lastName + " SUCCESS");
UserLocalServiceUtil.updateEmailAddressVerified(toReturn.getUserId(), true);
UserLocalServiceUtil.updateAgreedToTermsOfUse(toReturn.getUserId(), false);