Create user function changed a bit: it now allows to force or not the user to change password at first login

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vo-management/usermanagement-core@125891 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-03-21 15:47:44 +00:00
parent 26dc38123d
commit dfa3fdfad8
2 changed files with 63 additions and 16 deletions

View File

@ -13,6 +13,9 @@ import org.gcube.vomanagement.usermanagement.model.GCubeRole;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.gcube.vomanagement.usermanagement.model.MembershipRequestStatus;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
/**
*
@ -22,7 +25,7 @@ import org.gcube.vomanagement.usermanagement.model.MembershipRequestStatus;
*/
public interface UserManager {
/**
* Create the user without sending notification mail.
* Create the user without sending notification mail and without forcing him to change the password at first login.
* @param autoScreenName set true if you want liferay to auto generate a screename for this user, false otherwise
* @param username the username of the user you want
* @param email a valid email address
@ -35,9 +38,10 @@ public interface UserManager {
* @return an instance of the yet created user
* @throws UserManagementSystemException
*/
GCubeUser createUser(boolean autoScreenName, String username, String email, String firstName, String middleName, String lastName, String jobTitle, String backgroundSummary, boolean male, String reminderQuestion, String reminderAnswer) throws UserManagementSystemException;
/**
* Create the user and let you choose if you want to send him/her a mail notification.
* Create the user and let you choose if you want to send him/her a mail notification and force or not the user to change his/her password.
* @param autoScreenName set true if you want liferay to auto generate a screename for this user, false otherwise
* @param username the username of the user you want
* @param email a valid email address
@ -50,7 +54,7 @@ public interface UserManager {
* @return an instance of the yet created user
* @throws UserManagementSystemException
*/
GCubeUser createUser(boolean autoScreenName, String username, String email, String firstName, String middleName, String lastName, String jobTitle, String backgroundSummary, boolean male, String reminderQuestion, String reminderAnswer, boolean sendEmail) throws UserManagementSystemException;
GCubeUser createUser(boolean autoScreenName, String username, String email, String firstName, String middleName, String lastName, String jobTitle, String backgroundSummary, boolean male, String reminderQuestion, String reminderAnswer, boolean sendEmail, boolean forcePasswordReset) throws UserManagementSystemException;
/**
*
* @param username the username of the user you want to get
@ -234,4 +238,17 @@ public interface UserManager {
* @return true on success, false otherwise
*/
public boolean userExistsByEmail(String email);
/**
* Returns the user's full name given his email
* @param email
* @return null on failure
*/
public String getFullNameFromEmail(String email);
/**
* Delete a user given his mail
* @param email
*/
public void deleteUserByEMail(String email) throws UserManagementSystemException, UserManagementPortalException, PortalException, SystemException;
}

View File

@ -157,6 +157,7 @@ public class LiferayUserManager implements UserManager {
male,
reminderQuestion,
reminderAnswer,
false,
false);
}
@ -164,7 +165,7 @@ public class LiferayUserManager implements UserManager {
* {@inheritDoc}
*/
@Override
public GCubeUser createUser(boolean autoScreenName, String username, String email, String firstName, String middleName, String lastName, String jobTitle, String backgroundSummary, boolean male, String reminderQuestion, String reminderAnswer, boolean sendEmail)
public GCubeUser createUser(boolean autoScreenName, String username, String email, String firstName, String middleName, String lastName, String jobTitle, String backgroundSummary, boolean male, String reminderQuestion, String reminderAnswer, boolean sendEmail, boolean forcePasswordReset)
throws UserManagementSystemException {
return createUserBody(
autoScreenName,
@ -178,14 +179,15 @@ public class LiferayUserManager implements UserManager {
male,
reminderQuestion,
reminderAnswer,
sendEmail);
sendEmail,
forcePasswordReset);
}
private GCubeUser createUserBody(boolean autoScreenName, String username,
String email, String firstName, String middleName, String lastName,
String jobTitle, String backgroundSummary, boolean male,
String reminderQuestion, String reminderAnswer, boolean sendEmail){
String reminderQuestion, String reminderAnswer, boolean sendEmail, boolean forcePasswordReset){
GCubeUser toReturn = null;
try {
_log.debug("Trying createuser " + email);
@ -233,7 +235,7 @@ public class LiferayUserManager implements UserManager {
UserLocalServiceUtil.updateUser(added);
_log.debug("CreateUser " + lastName + " SUCCESS");
UserLocalServiceUtil.updateAgreedToTermsOfUse(added.getUserId(), true);
UserLocalServiceUtil.updatePasswordReset(added.getUserId(), false);
UserLocalServiceUtil.updatePasswordReset(added.getUserId(), forcePasswordReset);
if (reminderQuestion == null || reminderQuestion.compareTo("") == 0)
reminderQuestion = "Unknown question";
if (reminderAnswer == null || reminderAnswer.compareTo("") == 0)
@ -248,9 +250,9 @@ public class LiferayUserManager implements UserManager {
e.printStackTrace();
}
return toReturn;
}
/**
* {@inheritDoc}
*/
@ -636,26 +638,26 @@ public class LiferayUserManager implements UserManager {
toProcess.removeAll(listUsersByGroup(groupId));
return toProcess;
}
@Override
public boolean isPasswordChanged(String emailAddress) {
_log.debug("Trying to fetch user by email = " + emailAddress);
User user;
try {
user = UserLocalServiceUtil.getUserByEmailAddress(ManagementUtils.getCompany().getCompanyId(), emailAddress);
// date are saved according GMT
long creationTime = user.getCreateDate().getTime();
long changedTime = user.getPasswordModifiedDate().getTime();
return changedTime > creationTime;
} catch (Exception e) {
_log.error("Error while retrieving user with mail=" + emailAddress, e);
}
return false;
}
@Override
public boolean userExistsByEmail(String emailAddress) {
try {
@ -665,5 +667,33 @@ public class LiferayUserManager implements UserManager {
_log.error("Error while retrieving user with mail=" + emailAddress, e);
}
return false;
}
@Override
public String getFullNameFromEmail(String email) {
try{
User user;
if((user = UserLocalServiceUtil.getUserByEmailAddress(ManagementUtils.getCompany().getCompanyId(), email))!= null){
return user.getFullName();
}
}catch(Exception e){
_log.error("Unable to find user with email " + email);
}
return null;
}
@Override
public void deleteUserByEMail(String email)
throws UserManagementSystemException,
UserManagementPortalException, PortalException, SystemException {
User user;
if((user = UserLocalServiceUtil.getUserByEmailAddress(ManagementUtils.getCompany().getCompanyId(), email))!= null){
_log.debug("Deleting user with email " + email);
UserLocalServiceUtil.deleteUser(user);
_log.debug("Delete user with email " + email);
}
}
}