Added methods:

- isPasswordChanged;
- userExistsByMail;
- createUser (new version with more parameters)

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vo-management/usermanagement-core@125584 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-03-17 11:20:52 +00:00
parent f76d63bc89
commit 5a6d648905
2 changed files with 289 additions and 189 deletions

View File

@ -22,6 +22,7 @@ import org.gcube.vomanagement.usermanagement.model.MembershipRequestStatus;
*/
public interface UserManager {
/**
* Create the user without sending notification mail.
* @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,6 +36,21 @@ import org.gcube.vomanagement.usermanagement.model.MembershipRequestStatus;
* @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.
* @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
* @param firstName
* @param middleName
* @param lastName
* @param jobTitle
* @param backgroundSummary
* @param male
* @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;
/**
*
* @param username the username of the user you want to get
@ -204,4 +220,18 @@ import org.gcube.vomanagement.usermanagement.model.MembershipRequestStatus;
* @throws UserRetrievalFault
*/
List<GCubeUser> listUnregisteredUsersByGroup(long groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault;
/**
* Check if the user changed his/her password from the initial one.
* @param email the email of the user to consider
* @return true if the password has been changed, false if it has been not or the user doesn't exist.
*/
boolean isPasswordChanged(String email);
/**
* Check if a user with such email exists.
* @param email
* @return true on success, false otherwise
*/
public boolean userExistsByEmail(String email);
}

View File

@ -140,11 +140,50 @@ public class LiferayUserManager implements UserManager {
requestStatus);
return toReturn;
}
/**
* {@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) throws UserManagementSystemException {
return createUserBody(
autoScreenName,
username,
email,
firstName,
middleName,
lastName,
jobTitle,
backgroundSummary,
male,
reminderQuestion,
reminderAnswer,
false);
}
@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)
throws UserManagementSystemException {
return createUserBody(
autoScreenName,
username,
email,
firstName,
middleName,
lastName,
jobTitle,
backgroundSummary,
male,
reminderQuestion,
reminderAnswer,
sendEmail);
}
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){
GCubeUser toReturn = null;
try {
_log.debug("Trying createuser " + email);
@ -158,7 +197,6 @@ public class LiferayUserManager implements UserManager {
int birthdayMonth = 1;
int birthdayDay = 1;
int birthdayYear = 1970;
boolean sendEmail = false;
String password1 = "training1";
String password2 = password1;
User added = UserLocalServiceUtil.addUser(
@ -208,7 +246,9 @@ public class LiferayUserManager implements UserManager {
e.printStackTrace();
}
return toReturn;
}
/**
* {@inheritDoc}
*/
@ -594,4 +634,34 @@ 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 {
if(UserLocalServiceUtil.getUserByEmailAddress(ManagementUtils.getCompany().getCompanyId(), emailAddress) != null)
return true;
} catch (Exception e){
_log.error("Error while retrieving user with mail=" + emailAddress, e);
}
return false;
}
}