001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.model.impl;
016    
017    import com.liferay.portal.kernel.bean.AutoEscape;
018    import com.liferay.portal.kernel.dao.orm.QueryUtil;
019    import com.liferay.portal.kernel.exception.PortalException;
020    import com.liferay.portal.kernel.log.Log;
021    import com.liferay.portal.kernel.log.LogFactoryUtil;
022    import com.liferay.portal.kernel.util.Digester;
023    import com.liferay.portal.kernel.util.DigesterUtil;
024    import com.liferay.portal.kernel.util.HtmlUtil;
025    import com.liferay.portal.kernel.util.LocaleUtil;
026    import com.liferay.portal.kernel.util.PropsKeys;
027    import com.liferay.portal.kernel.util.RemotePreference;
028    import com.liferay.portal.kernel.util.SetUtil;
029    import com.liferay.portal.kernel.util.StringBundler;
030    import com.liferay.portal.kernel.util.StringPool;
031    import com.liferay.portal.kernel.util.StringUtil;
032    import com.liferay.portal.kernel.util.TimeZoneUtil;
033    import com.liferay.portal.kernel.util.Validator;
034    import com.liferay.portal.kernel.workflow.WorkflowConstants;
035    import com.liferay.portal.model.Address;
036    import com.liferay.portal.model.Company;
037    import com.liferay.portal.model.CompanyConstants;
038    import com.liferay.portal.model.Contact;
039    import com.liferay.portal.model.EmailAddress;
040    import com.liferay.portal.model.Group;
041    import com.liferay.portal.model.Organization;
042    import com.liferay.portal.model.PasswordPolicy;
043    import com.liferay.portal.model.Phone;
044    import com.liferay.portal.model.Role;
045    import com.liferay.portal.model.Team;
046    import com.liferay.portal.model.UserConstants;
047    import com.liferay.portal.model.UserGroup;
048    import com.liferay.portal.model.Website;
049    import com.liferay.portal.security.auth.EmailAddressGenerator;
050    import com.liferay.portal.security.auth.EmailAddressGeneratorFactory;
051    import com.liferay.portal.security.auth.FullNameGenerator;
052    import com.liferay.portal.security.auth.FullNameGeneratorFactory;
053    import com.liferay.portal.service.AddressLocalServiceUtil;
054    import com.liferay.portal.service.CompanyLocalServiceUtil;
055    import com.liferay.portal.service.ContactLocalServiceUtil;
056    import com.liferay.portal.service.EmailAddressLocalServiceUtil;
057    import com.liferay.portal.service.GroupLocalServiceUtil;
058    import com.liferay.portal.service.GroupServiceUtil;
059    import com.liferay.portal.service.LayoutLocalServiceUtil;
060    import com.liferay.portal.service.OrganizationLocalServiceUtil;
061    import com.liferay.portal.service.PasswordPolicyLocalServiceUtil;
062    import com.liferay.portal.service.PhoneLocalServiceUtil;
063    import com.liferay.portal.service.RoleLocalServiceUtil;
064    import com.liferay.portal.service.TeamLocalServiceUtil;
065    import com.liferay.portal.service.UserGroupLocalServiceUtil;
066    import com.liferay.portal.service.UserLocalServiceUtil;
067    import com.liferay.portal.service.WebsiteLocalServiceUtil;
068    import com.liferay.portal.theme.ThemeDisplay;
069    import com.liferay.portal.util.Portal;
070    import com.liferay.portal.util.PortalUtil;
071    import com.liferay.portal.util.PrefsPropsUtil;
072    import com.liferay.portal.util.PropsUtil;
073    import com.liferay.portal.util.PropsValues;
074    
075    import java.util.Collection;
076    import java.util.Collections;
077    import java.util.Date;
078    import java.util.HashMap;
079    import java.util.List;
080    import java.util.Locale;
081    import java.util.Map;
082    import java.util.Set;
083    import java.util.TimeZone;
084    import java.util.TreeSet;
085    
086    /**
087     * Represents a portal user, providing access to the user's contact information,
088     * groups, organizations, teams, user groups, roles, locale, timezone, and more.
089     *
090     * @author Brian Wing Shun Chan
091     * @author Jorge Ferrer
092     * @author Wesley Gong
093     */
094    public class UserImpl extends UserBaseImpl {
095    
096            @Override
097            public void addRemotePreference(RemotePreference remotePreference) {
098                    _remotePreferences.put(remotePreference.getName(), remotePreference);
099            }
100    
101            @Override
102            public Contact fetchContact() {
103                    return ContactLocalServiceUtil.fetchContact(getContactId());
104            }
105    
106            /**
107             * Returns the user's addresses.
108             *
109             * @return the user's addresses
110             */
111            @Override
112            public List<Address> getAddresses() {
113                    return AddressLocalServiceUtil.getAddresses(
114                            getCompanyId(), Contact.class.getName(), getContactId());
115            }
116    
117            /**
118             * Returns the user's birth date.
119             *
120             * @return the user's birth date
121             */
122            @Override
123            public Date getBirthday() throws PortalException {
124                    return getContact().getBirthday();
125            }
126    
127            /**
128             * Returns the user's company's mail domain.
129             *
130             * @return the user's company's mail domain
131             */
132            @Override
133            public String getCompanyMx() throws PortalException {
134                    Company company = CompanyLocalServiceUtil.getCompanyById(
135                            getCompanyId());
136    
137                    return company.getMx();
138            }
139    
140            /**
141             * Returns the user's associated contact.
142             *
143             * @return the user's associated contact
144             * @see    Contact
145             */
146            @Override
147            public Contact getContact() throws PortalException {
148                    return ContactLocalServiceUtil.getContact(getContactId());
149            }
150    
151            /**
152             * Returns the user's digest.
153             *
154             * @return the user's digest
155             */
156            @Override
157            public String getDigest() {
158                    String digest = super.getDigest();
159    
160                    if (Validator.isNull(digest) && !isPasswordEncrypted()) {
161                            digest = getDigest(getPassword());
162                    }
163    
164                    return digest;
165            }
166    
167            /**
168             * Returns a digest for the user, incorporating the password.
169             *
170             * @param  password a password to incorporate with the digest
171             * @return a digest for the user, incorporating the password
172             */
173            @Override
174            public String getDigest(String password) {
175                    if (Validator.isNull(getScreenName())) {
176                            throw new IllegalStateException("Screen name is null");
177                    }
178                    else if (Validator.isNull(getEmailAddress())) {
179                            throw new IllegalStateException("Email address is null");
180                    }
181    
182                    StringBundler sb = new StringBundler(5);
183    
184                    String digest1 = DigesterUtil.digestHex(
185                            Digester.MD5, getEmailAddress(), Portal.PORTAL_REALM, password);
186    
187                    sb.append(digest1);
188                    sb.append(StringPool.COMMA);
189    
190                    String digest2 = DigesterUtil.digestHex(
191                            Digester.MD5, getScreenName(), Portal.PORTAL_REALM, password);
192    
193                    sb.append(digest2);
194                    sb.append(StringPool.COMMA);
195    
196                    String digest3 = DigesterUtil.digestHex(
197                            Digester.MD5, String.valueOf(getUserId()), Portal.PORTAL_REALM,
198                            password);
199    
200                    sb.append(digest3);
201    
202                    return sb.toString();
203            }
204    
205            /**
206             * Returns the user's primary email address, or a blank string if the
207             * address is fake.
208             *
209             * @return the user's primary email address, or a blank string if the
210             *         address is fake
211             */
212            @Override
213            public String getDisplayEmailAddress() {
214                    String emailAddress = super.getEmailAddress();
215    
216                    EmailAddressGenerator emailAddressGenerator =
217                            EmailAddressGeneratorFactory.getInstance();
218    
219                    if (emailAddressGenerator.isFake(emailAddress)) {
220                            emailAddress = StringPool.BLANK;
221                    }
222    
223                    return emailAddress;
224            }
225    
226            /**
227             * Returns the user's display URL, discounting the URL of the user's default
228             * intranet site home page.
229             *
230             * <p>
231             * The logic for the display URL to return is as follows:
232             * </p>
233             *
234             * <ol>
235             * <li>
236             * If the user is the guest user, return an empty string.
237             * </li>
238             * <li>
239             * Else, if a friendly URL is available for the user's profile, return that
240             * friendly URL.
241             * </li>
242             * <li>
243             * Otherwise, return the URL of the user's default extranet site home page.
244             * </li>
245             * </ol>
246             *
247             * @param      portalURL the portal's URL
248             * @param      mainPath the main path
249             * @return     the user's display URL
250             * @deprecated As of 7.0.0, replaced by {@link #getDisplayURL(ThemeDisplay)}
251             */
252            @Deprecated
253            @Override
254            public String getDisplayURL(String portalURL, String mainPath)
255                    throws PortalException {
256    
257                    return getDisplayURL(portalURL, mainPath, false);
258            }
259    
260            /**
261             * Returns the user's display URL.
262             *
263             * <p>
264             * The logic for the display URL to return is as follows:
265             * </p>
266             *
267             * <ol>
268             * <li>
269             * If the user is the guest user, return an empty string.
270             * </li>
271             * <li>
272             * Else, if a friendly URL is available for the user's profile, return that
273             * friendly URL.
274             * </li>
275             * <li>
276             * Else, if <code>privateLayout</code> is <code>true</code>, return the URL
277             * of the user's default intranet site home page.
278             * </li>
279             * <li>
280             * Otherwise, return the URL of the user's default extranet site home page.
281             * </li>
282             * </ol>
283             *
284             * @param      portalURL the portal's URL
285             * @param      mainPath the main path
286             * @param      privateLayout whether to use the URL of the user's default
287             *             intranet(versus extranet)  site home page, if no friendly URL
288             *             is available for the user's profile
289             * @return     the user's display URL
290             * @throws     PortalException
291             * @deprecated As of 7.0.0, replaced by {@link #getDisplayURL(ThemeDisplay)}
292             */
293            @Deprecated
294            @Override
295            public String getDisplayURL(
296                            String portalURL, String mainPath, boolean privateLayout)
297                    throws PortalException {
298    
299                    if (isDefaultUser()) {
300                            return StringPool.BLANK;
301                    }
302    
303                    String profileFriendlyURL = getProfileFriendlyURL();
304    
305                    if (Validator.isNotNull(profileFriendlyURL)) {
306                            return portalURL.concat(PortalUtil.getPathContext()).concat(
307                                    profileFriendlyURL);
308                    }
309    
310                    return StringPool.BLANK;
311            }
312    
313            /**
314             * Returns the user's display URL based on the theme display, discounting
315             * the URL of the user's default intranet site home page.
316             *
317             * <p>
318             * The logic for the display URL to return is as follows:
319             * </p>
320             *
321             * <ol>
322             * <li>
323             * If the user is the guest user, return an empty string.
324             * </li>
325             * <li>
326             * Else, if a friendly URL is available for the user's profile, return that
327             * friendly URL.
328             * </li>
329             * <li>
330             * Otherwise, return the URL of the user's default extranet site home page.
331             * </li>
332             * </ol>
333             *
334             * @param  themeDisplay the theme display
335             * @return the user's display URL
336             */
337            @Override
338            public String getDisplayURL(ThemeDisplay themeDisplay)
339                    throws PortalException {
340    
341                    return getDisplayURL(themeDisplay, false);
342            }
343    
344            /**
345             * Returns the user's display URL based on the theme display.
346             *
347             * <p>
348             * The logic for the display URL to return is as follows:
349             * </p>
350             *
351             * <ol>
352             * <li>
353             * If the user is the guest user, return an empty string.
354             * </li>
355             * <li>
356             * Else, if a friendly URL is available for the user's profile, return that
357             * friendly URL.
358             * </li>
359             * <li>
360             * Else, if <code>privateLayout</code> is <code>true</code>, return the URL
361             * of the user's default intranet site home page.
362             * </li>
363             * <li>
364             * Otherwise, return the URL of the user's default extranet site home page.
365             * </li>
366             * </ol>
367             *
368             * @param  themeDisplay the theme display
369             * @param  privateLayout whether to use the URL of the user's default
370             *         intranet (versus extranet) site home page, if no friendly URL is
371             *         available for the user's profile
372             * @return the user's display URL
373             * @throws PortalException
374             */
375            @Override
376            public String getDisplayURL(
377                            ThemeDisplay themeDisplay, boolean privateLayout)
378                    throws PortalException {
379    
380                    if (isDefaultUser()) {
381                            return StringPool.BLANK;
382                    }
383    
384                    String portalURL = themeDisplay.getPortalURL();
385    
386                    String profileFriendlyURL = getProfileFriendlyURL();
387    
388                    if (Validator.isNotNull(profileFriendlyURL)) {
389                            return PortalUtil.addPreservedParameters(
390                                    themeDisplay,
391                                    portalURL.concat(
392                                            PortalUtil.getPathContext()).concat(profileFriendlyURL));
393                    }
394    
395                    Group group = getGroup();
396    
397                    return group.getDisplayURL(themeDisplay, privateLayout);
398            }
399    
400            /**
401             * Returns the user's email addresses.
402             *
403             * @return the user's email addresses
404             */
405            @Override
406            public List<EmailAddress> getEmailAddresses() {
407                    return EmailAddressLocalServiceUtil.getEmailAddresses(
408                            getCompanyId(), Contact.class.getName(), getContactId());
409            }
410    
411            /**
412             * Returns <code>true</code> if the user is female.
413             *
414             * @return <code>true</code> if the user is female; <code>false</code>
415             *         otherwise
416             */
417            @Override
418            public boolean getFemale() throws PortalException {
419                    return !getMale();
420            }
421    
422            /**
423             * Returns the user's full name.
424             *
425             * @return the user's full name
426             */
427            @AutoEscape
428            @Override
429            public String getFullName() {
430                    return getFullName(false, false);
431            }
432    
433            /**
434             * Returns the user's full name.
435             *
436             * @return the user's full name
437             */
438            @AutoEscape
439            @Override
440            public String getFullName(boolean usePrefix, boolean useSuffix) {
441                    FullNameGenerator fullNameGenerator =
442                            FullNameGeneratorFactory.getInstance();
443    
444                    long prefixId = 0;
445    
446                    if (usePrefix) {
447                            Contact contact = fetchContact();
448    
449                            if (contact != null) {
450                                    prefixId = contact.getPrefixId();
451                            }
452                    }
453    
454                    long suffixId = 0;
455    
456                    if (useSuffix) {
457                            Contact contact = fetchContact();
458    
459                            if (contact != null) {
460                                    suffixId = contact.getSuffixId();
461                            }
462                    }
463    
464                    return fullNameGenerator.getLocalizedFullName(
465                            getFirstName(), getMiddleName(), getLastName(), getLocale(),
466                            prefixId, suffixId);
467            }
468    
469            @Override
470            public Group getGroup() {
471                    return GroupLocalServiceUtil.fetchUserGroup(
472                            getCompanyId(), getUserId());
473            }
474    
475            @Override
476            public long getGroupId() {
477                    Group group = getGroup();
478    
479                    return group.getGroupId();
480            }
481    
482            @Override
483            public long[] getGroupIds() {
484                    return UserLocalServiceUtil.getGroupPrimaryKeys(getUserId());
485            }
486    
487            @Override
488            public List<Group> getGroups() {
489                    return GroupLocalServiceUtil.getUserGroups(getUserId());
490            }
491    
492            @Override
493            public String getInitials() {
494                    String[] names = StringUtil.split(getFullName(), StringPool.SPACE);
495    
496                    StringBundler sb = new StringBundler(names.length);
497    
498                    for (String name : names) {
499                            sb.append(StringUtil.toUpperCase(StringUtil.shorten(name, 1)));
500                    }
501    
502                    return sb.toString();
503            }
504    
505            @Override
506            public Locale getLocale() {
507                    return _locale;
508            }
509    
510            @Override
511            public String getLogin() throws PortalException {
512                    String login = null;
513    
514                    Company company = CompanyLocalServiceUtil.getCompanyById(
515                            getCompanyId());
516    
517                    if (company.getAuthType().equals(CompanyConstants.AUTH_TYPE_EA)) {
518                            login = getEmailAddress();
519                    }
520                    else if (company.getAuthType().equals(CompanyConstants.AUTH_TYPE_SN)) {
521                            login = getScreenName();
522                    }
523                    else if (company.getAuthType().equals(CompanyConstants.AUTH_TYPE_ID)) {
524                            login = String.valueOf(getUserId());
525                    }
526    
527                    return login;
528            }
529    
530            /**
531             * Returns <code>true</code> if the user is male.
532             *
533             * @return <code>true</code> if the user is male; <code>false</code>
534             *         otherwise
535             */
536            @Override
537            public boolean getMale() throws PortalException {
538                    return getContact().getMale();
539            }
540    
541            @Override
542            public List<Group> getMySiteGroups() throws PortalException {
543                    return getMySiteGroups(null, QueryUtil.ALL_POS);
544            }
545    
546            @Override
547            public List<Group> getMySiteGroups(int max) throws PortalException {
548                    return getMySiteGroups(null, max);
549            }
550    
551            @Override
552            public List<Group> getMySiteGroups(String[] classNames, int max)
553                    throws PortalException {
554    
555                    return GroupServiceUtil.getUserSitesGroups(
556                            getUserId(), classNames, max);
557            }
558    
559            /**
560             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups}
561             */
562            @Deprecated
563            @Override
564            public List<Group> getMySites() throws PortalException {
565                    return getMySiteGroups();
566            }
567    
568            /**
569             * @deprecated As of 6.2.0, replaced by {@link User#getMySiteGroups(int)}
570             */
571            @Deprecated
572            @Override
573            public List<Group> getMySites(boolean includeControlPanel, int max)
574                    throws PortalException {
575    
576                    return getMySiteGroups(max);
577            }
578    
579            /**
580             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups(int)}
581             */
582            @Deprecated
583            @Override
584            public List<Group> getMySites(int max) throws PortalException {
585                    return getMySiteGroups(max);
586            }
587    
588            /**
589             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups(String[],
590             *             int)}
591             */
592            @Deprecated
593            @Override
594            public List<Group> getMySites(
595                            String[] classNames, boolean includeControlPanel, int max)
596                    throws PortalException {
597    
598                    return getMySiteGroups(classNames, max);
599            }
600    
601            /**
602             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups(String[],
603             *             int)}
604             */
605            @Deprecated
606            @Override
607            public List<Group> getMySites(String[] classNames, int max)
608                    throws PortalException {
609    
610                    return getMySiteGroups(classNames, max);
611            }
612    
613            @Override
614            public long[] getOrganizationIds() throws PortalException {
615                    return getOrganizationIds(false);
616            }
617    
618            @Override
619            public long[] getOrganizationIds(boolean includeAdministrative)
620                    throws PortalException {
621    
622                    return OrganizationLocalServiceUtil.getUserOrganizationIds(
623                            getUserId(), includeAdministrative);
624            }
625    
626            @Override
627            public List<Organization> getOrganizations() throws PortalException {
628                    return getOrganizations(false);
629            }
630    
631            @Override
632            public List<Organization> getOrganizations(boolean includeAdministrative)
633                    throws PortalException {
634    
635                    return OrganizationLocalServiceUtil.getUserOrganizations(
636                            getUserId(), includeAdministrative);
637            }
638    
639            @Override
640            public String getOriginalEmailAddress() {
641                    return super.getOriginalEmailAddress();
642            }
643    
644            @Override
645            public boolean getPasswordModified() {
646                    return _passwordModified;
647            }
648    
649            @Override
650            public PasswordPolicy getPasswordPolicy() throws PortalException {
651                    if (_passwordPolicy == null) {
652                            _passwordPolicy =
653                                    PasswordPolicyLocalServiceUtil.getPasswordPolicyByUserId(
654                                            getUserId());
655                    }
656    
657                    return _passwordPolicy;
658            }
659    
660            @Override
661            public String getPasswordUnencrypted() {
662                    return _passwordUnencrypted;
663            }
664    
665            @Override
666            public List<Phone> getPhones() {
667                    return PhoneLocalServiceUtil.getPhones(
668                            getCompanyId(), Contact.class.getName(), getContactId());
669            }
670    
671            @Override
672            public String getPortraitURL(ThemeDisplay themeDisplay)
673                    throws PortalException {
674    
675                    return UserConstants.getPortraitURL(
676                            themeDisplay.getPathImage(), isMale(), getPortraitId(),
677                            getUserUuid());
678            }
679    
680            @Override
681            public int getPrivateLayoutsPageCount() throws PortalException {
682                    return LayoutLocalServiceUtil.getLayoutsCount(this, true);
683            }
684    
685            @Override
686            public int getPublicLayoutsPageCount() throws PortalException {
687                    return LayoutLocalServiceUtil.getLayoutsCount(this, false);
688            }
689    
690            @Override
691            public Set<String> getReminderQueryQuestions() throws PortalException {
692                    Set<String> questions = new TreeSet<>();
693    
694                    List<Organization> organizations =
695                            OrganizationLocalServiceUtil.getUserOrganizations(getUserId());
696    
697                    for (Organization organization : organizations) {
698                            Set<String> organizationQuestions =
699                                    organization.getReminderQueryQuestions(getLanguageId());
700    
701                            if (organizationQuestions.isEmpty()) {
702                                    Organization parentOrganization =
703                                            organization.getParentOrganization();
704    
705                                    while (organizationQuestions.isEmpty() &&
706                                               (parentOrganization != null)) {
707    
708                                            organizationQuestions =
709                                                    parentOrganization.getReminderQueryQuestions(
710                                                            getLanguageId());
711    
712                                            parentOrganization =
713                                                    parentOrganization.getParentOrganization();
714                                    }
715                            }
716    
717                            questions.addAll(organizationQuestions);
718                    }
719    
720                    if (questions.isEmpty()) {
721                            Set<String> defaultQuestions = SetUtil.fromArray(
722                                    PropsUtil.getArray(PropsKeys.USERS_REMINDER_QUERIES_QUESTIONS));
723    
724                            questions.addAll(defaultQuestions);
725                    }
726    
727                    return questions;
728            }
729    
730            @Override
731            public RemotePreference getRemotePreference(String name) {
732                    return _remotePreferences.get(name);
733            }
734    
735            @Override
736            public Iterable<RemotePreference> getRemotePreferences() {
737                    Collection<RemotePreference> values = _remotePreferences.values();
738    
739                    return Collections.unmodifiableCollection(values);
740            }
741    
742            @Override
743            public long[] getRoleIds() {
744                    return UserLocalServiceUtil.getRolePrimaryKeys(getUserId());
745            }
746    
747            @Override
748            public List<Role> getRoles() {
749                    return RoleLocalServiceUtil.getUserRoles(getUserId());
750            }
751    
752            @Override
753            public List<Group> getSiteGroups() throws PortalException {
754                    return getSiteGroups(false);
755            }
756    
757            @Override
758            public List<Group> getSiteGroups(boolean includeAdministrative)
759                    throws PortalException {
760    
761                    return GroupLocalServiceUtil.getUserSitesGroups(
762                            getUserId(), includeAdministrative);
763            }
764    
765            @Override
766            public long[] getTeamIds() {
767                    return UserLocalServiceUtil.getTeamPrimaryKeys(getUserId());
768            }
769    
770            @Override
771            public List<Team> getTeams() {
772                    return TeamLocalServiceUtil.getUserTeams(getUserId());
773            }
774    
775            @Override
776            public TimeZone getTimeZone() {
777                    return _timeZone;
778            }
779    
780            @Override
781            public Date getUnlockDate() throws PortalException {
782                    return getUnlockDate(getPasswordPolicy());
783            }
784    
785            @Override
786            public Date getUnlockDate(PasswordPolicy passwordPolicy) {
787                    Date lockoutDate = getLockoutDate();
788    
789                    return new Date(
790                            lockoutDate.getTime() +
791                                    (passwordPolicy.getLockoutDuration() * 1000));
792            }
793    
794            @Override
795            public long[] getUserGroupIds() {
796                    return UserLocalServiceUtil.getUserGroupPrimaryKeys(getUserId());
797            }
798    
799            @Override
800            public List<UserGroup> getUserGroups() {
801                    return UserGroupLocalServiceUtil.getUserUserGroups(getUserId());
802            }
803    
804            @Override
805            public List<Website> getWebsites() {
806                    return WebsiteLocalServiceUtil.getWebsites(
807                            getCompanyId(), Contact.class.getName(), getContactId());
808            }
809    
810            @Override
811            public boolean hasCompanyMx() throws PortalException {
812                    return hasCompanyMx(getEmailAddress());
813            }
814    
815            @Override
816            public boolean hasCompanyMx(String emailAddress) throws PortalException {
817                    if (Validator.isNull(emailAddress)) {
818                            return false;
819                    }
820    
821                    Company company = CompanyLocalServiceUtil.getCompanyById(
822                            getCompanyId());
823    
824                    return company.hasCompanyMx(emailAddress);
825            }
826    
827            @Override
828            public boolean hasMySites() throws PortalException {
829                    if (isDefaultUser()) {
830                            return false;
831                    }
832    
833                    List<Group> groups = getMySiteGroups(1);
834    
835                    return !groups.isEmpty();
836            }
837    
838            @Override
839            public boolean hasOrganization() {
840                    return OrganizationLocalServiceUtil.hasUserOrganizations(getUserId());
841            }
842    
843            @Override
844            public boolean hasPrivateLayouts() throws PortalException {
845                    return LayoutLocalServiceUtil.hasLayouts(this, true);
846            }
847    
848            @Override
849            public boolean hasPublicLayouts() throws PortalException {
850                    return LayoutLocalServiceUtil.hasLayouts(this, false);
851            }
852    
853            @Override
854            public boolean hasReminderQuery() {
855                    if (Validator.isNotNull(getReminderQueryQuestion()) &&
856                            Validator.isNotNull(getReminderQueryAnswer())) {
857    
858                            return true;
859                    }
860                    else {
861                            return false;
862                    }
863            }
864    
865            @Override
866            public boolean isActive() {
867                    if (getStatus() == WorkflowConstants.STATUS_APPROVED) {
868                            return true;
869                    }
870                    else {
871                            return false;
872                    }
873            }
874    
875            @Override
876            public boolean isEmailAddressComplete() {
877                    if (Validator.isNull(getEmailAddress()) ||
878                            (PropsValues.USERS_EMAIL_ADDRESS_REQUIRED &&
879                             Validator.isNull(getDisplayEmailAddress()))) {
880    
881                            return false;
882                    }
883    
884                    return true;
885            }
886    
887            @Override
888            public boolean isEmailAddressVerificationComplete() {
889                    boolean emailAddressVerificationRequired = false;
890    
891                    try {
892                            Company company = CompanyLocalServiceUtil.getCompany(
893                                    getCompanyId());
894    
895                            emailAddressVerificationRequired = company.isStrangersVerify();
896                    }
897                    catch (PortalException pe) {
898                            _log.error(pe, pe);
899                    }
900    
901                    if (emailAddressVerificationRequired) {
902                            return super.isEmailAddressVerified();
903                    }
904    
905                    return true;
906            }
907    
908            @Override
909            public boolean isFemale() throws PortalException {
910                    return getFemale();
911            }
912    
913            @Override
914            public boolean isMale() throws PortalException {
915                    return getMale();
916            }
917    
918            @Override
919            public boolean isPasswordModified() {
920                    return _passwordModified;
921            }
922    
923            @Override
924            public boolean isReminderQueryComplete() {
925                    if (isDefaultUser()) {
926                            return true;
927                    }
928    
929                    if (PropsValues.USERS_REMINDER_QUERIES_ENABLED) {
930                            if (Validator.isNull(getReminderQueryQuestion()) ||
931                                    Validator.isNull(getReminderQueryAnswer())) {
932    
933                                    return false;
934                            }
935                    }
936    
937                    return true;
938            }
939    
940            @Override
941            public boolean isSetupComplete() {
942                    if (isEmailAddressComplete() && isEmailAddressVerificationComplete() &&
943                            !isPasswordReset() && isReminderQueryComplete() &&
944                            isTermsOfUseComplete()) {
945    
946                            return true;
947                    }
948    
949                    return false;
950            }
951    
952            @Override
953            public boolean isTermsOfUseComplete() {
954                    boolean termsOfUseRequired = PrefsPropsUtil.getBoolean(
955                            getCompanyId(), PropsKeys.TERMS_OF_USE_REQUIRED,
956                            PropsValues.TERMS_OF_USE_REQUIRED);
957    
958                    if (termsOfUseRequired) {
959                            return super.isAgreedToTermsOfUse();
960                    }
961    
962                    return true;
963            }
964    
965            @Override
966            public void setLanguageId(String languageId) {
967                    _locale = LocaleUtil.fromLanguageId(languageId);
968    
969                    super.setLanguageId(LocaleUtil.toLanguageId(_locale));
970            }
971    
972            @Override
973            public void setPasswordModified(boolean passwordModified) {
974                    _passwordModified = passwordModified;
975            }
976    
977            @Override
978            public void setPasswordUnencrypted(String passwordUnencrypted) {
979                    _passwordUnencrypted = passwordUnencrypted;
980            }
981    
982            @Override
983            public void setTimeZoneId(String timeZoneId) {
984                    if (Validator.isNull(timeZoneId)) {
985                            timeZoneId = TimeZoneUtil.getDefault().getID();
986                    }
987    
988                    _timeZone = TimeZoneUtil.getTimeZone(timeZoneId);
989    
990                    super.setTimeZoneId(timeZoneId);
991            }
992    
993            protected String getProfileFriendlyURL() {
994                    if (Validator.isNull(PropsValues.USERS_PROFILE_FRIENDLY_URL)) {
995                            return null;
996                    }
997    
998                    return StringUtil.replace(
999                            PropsValues.USERS_PROFILE_FRIENDLY_URL,
1000                            new String[] {"${liferay:screenName}", "${liferay:userId}"},
1001                            new String[] {
1002                                    HtmlUtil.escapeURL(getScreenName()), String.valueOf(getUserId())
1003                            });
1004            }
1005    
1006            private static final Log _log = LogFactoryUtil.getLog(UserImpl.class);
1007    
1008            private Locale _locale;
1009            private boolean _passwordModified;
1010            private PasswordPolicy _passwordPolicy;
1011            private String _passwordUnencrypted;
1012            private final transient Map<String, RemotePreference> _remotePreferences =
1013                    new HashMap<>();
1014            private TimeZone _timeZone;
1015    
1016    }