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/admin/create-users@164556 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
39f0448615
commit
bcb5716ca0
|
@ -8,6 +8,7 @@ import java.sql.Timestamp;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.gcube.common.portal.PortalContext;
|
||||
import org.gcube.portal.mailing.message.Recipient;
|
||||
|
@ -32,8 +33,11 @@ import com.liferay.portal.kernel.exception.SystemException;
|
|||
import com.liferay.portal.kernel.util.GetterUtil;
|
||||
import com.liferay.portal.kernel.util.PropsUtil;
|
||||
import com.liferay.portal.model.Company;
|
||||
import com.liferay.portal.model.User;
|
||||
import com.liferay.portal.service.CompanyLocalServiceUtil;
|
||||
import com.liferay.portal.service.ServiceContext;
|
||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||
import com.liferay.portal.util.PortalUtil;
|
||||
|
||||
/**
|
||||
* The server side implementation of the RPC service.
|
||||
|
@ -231,26 +235,10 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
|
|||
logger.debug("User added in " + REGISTERED_USERS_TABLE);
|
||||
// add in liferay too
|
||||
try{
|
||||
GCubeUser user = userManager.createUser(
|
||||
true,
|
||||
"",
|
||||
email,
|
||||
name,
|
||||
"",
|
||||
surname,
|
||||
institution,
|
||||
"",
|
||||
"",
|
||||
isMale,
|
||||
"What was your initial password?",
|
||||
"training1",
|
||||
false, // determine if we need to send him/her an email
|
||||
true); // force the password reset
|
||||
|
||||
User user = register(name, surname, email, institution, sendEmail);
|
||||
// adding to the current VRE
|
||||
long userId = userManager.getUserId(user.getUsername());
|
||||
long userId = userManager.getUserId(user.getScreenName());
|
||||
userManager.assignUserToGroup(getCurrentGroupID(), userId);
|
||||
UserLocalServiceUtil.updateEmailAddressVerified(userId, true);
|
||||
if (sendEmail)
|
||||
sendEmailToUser(email);
|
||||
|
||||
|
@ -284,6 +272,75 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private User register(String firstName, String lastName, String email, String institution, boolean sendEmail) {
|
||||
User toReturn = null;
|
||||
try{
|
||||
logger.debug("Trying createuser and instatiate serviceContext" + email);
|
||||
Long defaultCompanyId = PortalUtil.getDefaultCompanyId();
|
||||
Long defaultUserId = UserLocalServiceUtil.getDefaultUserId(defaultCompanyId);
|
||||
PortalContext pContext = PortalContext.getConfiguration();
|
||||
//ServiceContext instanciated as follows is needed when the Email verification is sent
|
||||
ServiceContext serviceContext = new ServiceContext();
|
||||
serviceContext.setScopeGroupId(pContext.getCurrentGroupId(getThreadLocalRequest()));
|
||||
serviceContext.setPortalURL(pContext.getGatewayURL(getThreadLocalRequest()));
|
||||
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 password1 = "training1";
|
||||
String password2 = password1;
|
||||
toReturn = UserLocalServiceUtil.addUser(
|
||||
defaultUserId,
|
||||
defaultCompanyId,
|
||||
autoPassword,
|
||||
password1,
|
||||
password2,
|
||||
true,
|
||||
"",
|
||||
email,
|
||||
0L,
|
||||
"",
|
||||
locale,
|
||||
firstName,
|
||||
"",
|
||||
lastName,
|
||||
prefixId,
|
||||
suffixId,
|
||||
true,
|
||||
birthdayMonth,
|
||||
birthdayDay,
|
||||
birthdayYear,
|
||||
institution,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
serviceContext);
|
||||
logger.debug("CreateUser " + lastName + " SUCCESS");
|
||||
UserLocalServiceUtil.updateEmailAddressVerified(toReturn.getUserId(), true);
|
||||
UserLocalServiceUtil.updateAgreedToTermsOfUse(toReturn.getUserId(), false);
|
||||
UserLocalServiceUtil.updatePasswordReset(toReturn.getUserId(), true);
|
||||
UserLocalServiceUtil.updateReminderQuery(toReturn.getUserId(), "What was your initial password?", "training1");
|
||||
logger.debug("User " + lastName + " has agreed to ToU");
|
||||
logger.debug("User " + lastName + " has verified the Email");
|
||||
logger.debug("User " + lastName + " updatePasswordReset & updateReminderQuery");
|
||||
|
||||
|
||||
}
|
||||
catch(Exception e){
|
||||
// unable to create.. we need to delete it from the list of users
|
||||
logger.error("Unable to create the user " + email + " in liferay.", e);
|
||||
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VreUserBean> getAlreadyRegisterdUsers() {
|
||||
|
|
Loading…
Reference in New Issue