Example usage for com.liferay.portal.kernel.service UserLocalServiceUtil fetchUserByEmailAddress

List of usage examples for com.liferay.portal.kernel.service UserLocalServiceUtil fetchUserByEmailAddress

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service UserLocalServiceUtil fetchUserByEmailAddress.

Prototype

public static com.liferay.portal.kernel.model.User fetchUserByEmailAddress(long companyId,
        String emailAddress) 

Source Link

Document

Returns the user with the email address.

Usage

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularUserServiceImpl.java

License:Open Source License

@Override
public User addNewUser(String screenName, String emailAddress, long companyId, String locale, long[] groupIds,
        long[] organizationIds, long[] roleIds, long[] userGroupIds) throws PortalException {
    User newUser = null;/* ww  w .j a  va 2 s  .  c o  m*/
    long creatorId = 0;

    _log.info("Adding new user ...");

    _log.debug("    ... security check ...");

    PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_USER);

    _log.debug("    .... processing ...");

    try {

        try {
            creatorId = this.getGuestOrUserId();
        } catch (PrincipalException pe) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to get current user ID", pe);
            }
        }

        boolean autoScreenName = false;

        if (StringUtils.isEmpty(screenName)) {
            _log.warn("No screen name given! Switching to auto screen name!");
            autoScreenName = true;
            screenName = "";
        }

        if (StringUtils.isEmpty(emailAddress)) {
            _log.warn("No email address given!");
            throw new PortalException("A email address is needed for new users!");
        }

        this.validateEmail(emailAddress, null);

        User existingUser = UserLocalServiceUtil.fetchUserByEmailAddress(companyId, emailAddress);

        if (existingUser == null) {

            ServiceContext serviceContext = new ServiceContext();

            this.checkAddUserPermission(creatorId, companyId, emailAddress, groupIds, organizationIds, roleIds,
                    userGroupIds, serviceContext);

            // Null safe actions
            if (groupIds == null) {
                groupIds = new long[0];
            }

            if (organizationIds == null) {
                organizationIds = new long[0];
            }

            if (roleIds == null) {
                roleIds = new long[0];
            }

            if (userGroupIds == null) {
                userGroupIds = new long[0];
            }

            _log.info("Creating new user with email address: " + emailAddress);

            boolean autoPassword = true;
            String password1 = "";
            String password2 = "";
            long facebookId = 0;
            String openId = "";
            Locale loc = ServiceUtils.getLocaleFromString(locale);
            String firstName = INVISIBLE_PLACEHOLDER;
            String middleName = "";
            String lastName = INVISIBLE_PLACEHOLDER;
            int prefixId = 0;
            int suffixId = 0;
            boolean male = false;

            int birthdayMonth = 1;
            int birthdayDay = 1;
            int birthdayYear = 1970;
            String jobTitle = "";

            boolean sendEmail = true;

            boolean workflowEnabled = WorkflowThreadLocal.isEnabled();

            try {

                newUser = UserLocalServiceUtil.addUserWithWorkflow(creatorId, companyId, autoPassword,
                        password1, password2, autoScreenName, screenName, emailAddress, facebookId, openId, loc,
                        firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay,
                        birthdayYear, jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail,
                        null);

                _log.debug("New user record: " + newUser.toString());

            } finally {
                WorkflowThreadLocal.setEnabled(workflowEnabled);
            }

        } else {
            _log.error(
                    "User cannot be created! Found already the following account: " + existingUser.toString());
            throw new PortalException("Fatal! User already exists");
        }
        // Send validation mail

    } catch (PortalException pe) {
        _log.error(pe);
        throw pe;
    }

    return newUser;
}

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularUserServiceImpl.java

License:Open Source License

@Override
public User deleteUserByEmail(String emailAddress) throws PortalException {

    _log.info("Deleteing user by email address ...");

    _log.debug("    ... security check ... ");

    PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.DELETE_USER);

    _log.debug("    ... deleting ...");

    User user = getGuestOrUser();/*  w  ww.  j av  a  2s.  co  m*/
    User existingUser = UserLocalServiceUtil.fetchUserByEmailAddress(user.getCompanyId(), emailAddress);

    return this.deleteUser(user, existingUser);
}