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 Locale getLocale() {
494                    return _locale;
495            }
496    
497            @Override
498            public String getLogin() throws PortalException {
499                    String login = null;
500    
501                    Company company = CompanyLocalServiceUtil.getCompanyById(
502                            getCompanyId());
503    
504                    if (company.getAuthType().equals(CompanyConstants.AUTH_TYPE_EA)) {
505                            login = getEmailAddress();
506                    }
507                    else if (company.getAuthType().equals(CompanyConstants.AUTH_TYPE_SN)) {
508                            login = getScreenName();
509                    }
510                    else if (company.getAuthType().equals(CompanyConstants.AUTH_TYPE_ID)) {
511                            login = String.valueOf(getUserId());
512                    }
513    
514                    return login;
515            }
516    
517            /**
518             * Returns <code>true</code> if the user is male.
519             *
520             * @return <code>true</code> if the user is male; <code>false</code>
521             *         otherwise
522             */
523            @Override
524            public boolean getMale() throws PortalException {
525                    return getContact().getMale();
526            }
527    
528            @Override
529            public List<Group> getMySiteGroups() throws PortalException {
530                    return getMySiteGroups(null, QueryUtil.ALL_POS);
531            }
532    
533            @Override
534            public List<Group> getMySiteGroups(int max) throws PortalException {
535                    return getMySiteGroups(null, max);
536            }
537    
538            @Override
539            public List<Group> getMySiteGroups(String[] classNames, int max)
540                    throws PortalException {
541    
542                    return GroupServiceUtil.getUserSitesGroups(
543                            getUserId(), classNames, max);
544            }
545    
546            /**
547             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups}
548             */
549            @Deprecated
550            @Override
551            public List<Group> getMySites() throws PortalException {
552                    return getMySiteGroups();
553            }
554    
555            /**
556             * @deprecated As of 6.2.0, replaced by {@link User#getMySiteGroups(int)}
557             */
558            @Deprecated
559            @Override
560            public List<Group> getMySites(boolean includeControlPanel, int max)
561                    throws PortalException {
562    
563                    return getMySiteGroups(max);
564            }
565    
566            /**
567             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups(int)}
568             */
569            @Deprecated
570            @Override
571            public List<Group> getMySites(int max) throws PortalException {
572                    return getMySiteGroups(max);
573            }
574    
575            /**
576             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups(String[],
577             *             int)}
578             */
579            @Deprecated
580            @Override
581            public List<Group> getMySites(
582                            String[] classNames, boolean includeControlPanel, int max)
583                    throws PortalException {
584    
585                    return getMySiteGroups(classNames, 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(String[] classNames, int max)
595                    throws PortalException {
596    
597                    return getMySiteGroups(classNames, max);
598            }
599    
600            @Override
601            public long[] getOrganizationIds() throws PortalException {
602                    return getOrganizationIds(false);
603            }
604    
605            @Override
606            public long[] getOrganizationIds(boolean includeAdministrative)
607                    throws PortalException {
608    
609                    return OrganizationLocalServiceUtil.getUserOrganizationIds(
610                            getUserId(), includeAdministrative);
611            }
612    
613            @Override
614            public List<Organization> getOrganizations() throws PortalException {
615                    return getOrganizations(false);
616            }
617    
618            @Override
619            public List<Organization> getOrganizations(boolean includeAdministrative)
620                    throws PortalException {
621    
622                    return OrganizationLocalServiceUtil.getUserOrganizations(
623                            getUserId(), includeAdministrative);
624            }
625    
626            @Override
627            public String getOriginalEmailAddress() {
628                    return super.getOriginalEmailAddress();
629            }
630    
631            @Override
632            public boolean getPasswordModified() {
633                    return _passwordModified;
634            }
635    
636            @Override
637            public PasswordPolicy getPasswordPolicy() throws PortalException {
638                    if (_passwordPolicy == null) {
639                            _passwordPolicy =
640                                    PasswordPolicyLocalServiceUtil.getPasswordPolicyByUserId(
641                                            getUserId());
642                    }
643    
644                    return _passwordPolicy;
645            }
646    
647            @Override
648            public String getPasswordUnencrypted() {
649                    return _passwordUnencrypted;
650            }
651    
652            @Override
653            public List<Phone> getPhones() {
654                    return PhoneLocalServiceUtil.getPhones(
655                            getCompanyId(), Contact.class.getName(), getContactId());
656            }
657    
658            @Override
659            public String getPortraitURL(ThemeDisplay themeDisplay)
660                    throws PortalException {
661    
662                    return UserConstants.getPortraitURL(
663                            themeDisplay.getPathImage(), isMale(), getPortraitId(),
664                            getUserUuid());
665            }
666    
667            @Override
668            public int getPrivateLayoutsPageCount() throws PortalException {
669                    return LayoutLocalServiceUtil.getLayoutsCount(this, true);
670            }
671    
672            @Override
673            public int getPublicLayoutsPageCount() throws PortalException {
674                    return LayoutLocalServiceUtil.getLayoutsCount(this, false);
675            }
676    
677            @Override
678            public Set<String> getReminderQueryQuestions() throws PortalException {
679                    Set<String> questions = new TreeSet<>();
680    
681                    List<Organization> organizations =
682                            OrganizationLocalServiceUtil.getUserOrganizations(getUserId());
683    
684                    for (Organization organization : organizations) {
685                            Set<String> organizationQuestions =
686                                    organization.getReminderQueryQuestions(getLanguageId());
687    
688                            if (organizationQuestions.isEmpty()) {
689                                    Organization parentOrganization =
690                                            organization.getParentOrganization();
691    
692                                    while (organizationQuestions.isEmpty() &&
693                                               (parentOrganization != null)) {
694    
695                                            organizationQuestions =
696                                                    parentOrganization.getReminderQueryQuestions(
697                                                            getLanguageId());
698    
699                                            parentOrganization =
700                                                    parentOrganization.getParentOrganization();
701                                    }
702                            }
703    
704                            questions.addAll(organizationQuestions);
705                    }
706    
707                    if (questions.isEmpty()) {
708                            Set<String> defaultQuestions = SetUtil.fromArray(
709                                    PropsUtil.getArray(PropsKeys.USERS_REMINDER_QUERIES_QUESTIONS));
710    
711                            questions.addAll(defaultQuestions);
712                    }
713    
714                    return questions;
715            }
716    
717            @Override
718            public RemotePreference getRemotePreference(String name) {
719                    return _remotePreferences.get(name);
720            }
721    
722            @Override
723            public Iterable<RemotePreference> getRemotePreferences() {
724                    Collection<RemotePreference> values = _remotePreferences.values();
725    
726                    return Collections.unmodifiableCollection(values);
727            }
728    
729            @Override
730            public long[] getRoleIds() {
731                    return UserLocalServiceUtil.getRolePrimaryKeys(getUserId());
732            }
733    
734            @Override
735            public List<Role> getRoles() {
736                    return RoleLocalServiceUtil.getUserRoles(getUserId());
737            }
738    
739            @Override
740            public List<Group> getSiteGroups() throws PortalException {
741                    return getSiteGroups(false);
742            }
743    
744            @Override
745            public List<Group> getSiteGroups(boolean includeAdministrative)
746                    throws PortalException {
747    
748                    return GroupLocalServiceUtil.getUserSitesGroups(
749                            getUserId(), includeAdministrative);
750            }
751    
752            @Override
753            public long[] getTeamIds() {
754                    return UserLocalServiceUtil.getTeamPrimaryKeys(getUserId());
755            }
756    
757            @Override
758            public List<Team> getTeams() {
759                    return TeamLocalServiceUtil.getUserTeams(getUserId());
760            }
761    
762            @Override
763            public TimeZone getTimeZone() {
764                    return _timeZone;
765            }
766    
767            @Override
768            public Date getUnlockDate() throws PortalException {
769                    return getUnlockDate(getPasswordPolicy());
770            }
771    
772            @Override
773            public Date getUnlockDate(PasswordPolicy passwordPolicy) {
774                    Date lockoutDate = getLockoutDate();
775    
776                    return new Date(
777                            lockoutDate.getTime() +
778                                    (passwordPolicy.getLockoutDuration() * 1000));
779            }
780    
781            @Override
782            public long[] getUserGroupIds() {
783                    return UserLocalServiceUtil.getUserGroupPrimaryKeys(getUserId());
784            }
785    
786            @Override
787            public List<UserGroup> getUserGroups() {
788                    return UserGroupLocalServiceUtil.getUserUserGroups(getUserId());
789            }
790    
791            @Override
792            public List<Website> getWebsites() {
793                    return WebsiteLocalServiceUtil.getWebsites(
794                            getCompanyId(), Contact.class.getName(), getContactId());
795            }
796    
797            @Override
798            public boolean hasCompanyMx() throws PortalException {
799                    return hasCompanyMx(getEmailAddress());
800            }
801    
802            @Override
803            public boolean hasCompanyMx(String emailAddress) throws PortalException {
804                    if (Validator.isNull(emailAddress)) {
805                            return false;
806                    }
807    
808                    Company company = CompanyLocalServiceUtil.getCompanyById(
809                            getCompanyId());
810    
811                    return company.hasCompanyMx(emailAddress);
812            }
813    
814            @Override
815            public boolean hasMySites() throws PortalException {
816                    if (isDefaultUser()) {
817                            return false;
818                    }
819    
820                    List<Group> groups = getMySiteGroups(1);
821    
822                    return !groups.isEmpty();
823            }
824    
825            @Override
826            public boolean hasOrganization() {
827                    return OrganizationLocalServiceUtil.hasUserOrganizations(getUserId());
828            }
829    
830            @Override
831            public boolean hasPrivateLayouts() throws PortalException {
832                    return LayoutLocalServiceUtil.hasLayouts(this, true);
833            }
834    
835            @Override
836            public boolean hasPublicLayouts() throws PortalException {
837                    return LayoutLocalServiceUtil.hasLayouts(this, false);
838            }
839    
840            @Override
841            public boolean hasReminderQuery() {
842                    if (Validator.isNotNull(getReminderQueryQuestion()) &&
843                            Validator.isNotNull(getReminderQueryAnswer())) {
844    
845                            return true;
846                    }
847                    else {
848                            return false;
849                    }
850            }
851    
852            @Override
853            public boolean isActive() {
854                    if (getStatus() == WorkflowConstants.STATUS_APPROVED) {
855                            return true;
856                    }
857                    else {
858                            return false;
859                    }
860            }
861    
862            @Override
863            public boolean isEmailAddressComplete() {
864                    if (Validator.isNull(getEmailAddress()) ||
865                            (PropsValues.USERS_EMAIL_ADDRESS_REQUIRED &&
866                             Validator.isNull(getDisplayEmailAddress()))) {
867    
868                            return false;
869                    }
870    
871                    return true;
872            }
873    
874            @Override
875            public boolean isEmailAddressVerificationComplete() {
876                    boolean emailAddressVerificationRequired = false;
877    
878                    try {
879                            Company company = CompanyLocalServiceUtil.getCompany(
880                                    getCompanyId());
881    
882                            emailAddressVerificationRequired = company.isStrangersVerify();
883                    }
884                    catch (PortalException pe) {
885                            _log.error(pe, pe);
886                    }
887    
888                    if (emailAddressVerificationRequired) {
889                            return super.isEmailAddressVerified();
890                    }
891    
892                    return true;
893            }
894    
895            @Override
896            public boolean isFemale() throws PortalException {
897                    return getFemale();
898            }
899    
900            @Override
901            public boolean isMale() throws PortalException {
902                    return getMale();
903            }
904    
905            @Override
906            public boolean isPasswordModified() {
907                    return _passwordModified;
908            }
909    
910            @Override
911            public boolean isReminderQueryComplete() {
912                    if (isDefaultUser()) {
913                            return true;
914                    }
915    
916                    if (PropsValues.USERS_REMINDER_QUERIES_ENABLED) {
917                            if (Validator.isNull(getReminderQueryQuestion()) ||
918                                    Validator.isNull(getReminderQueryAnswer())) {
919    
920                                    return false;
921                            }
922                    }
923    
924                    return true;
925            }
926    
927            @Override
928            public boolean isSetupComplete() {
929                    if (isEmailAddressComplete() && isEmailAddressVerificationComplete() &&
930                            !isPasswordReset() && isReminderQueryComplete() &&
931                            isTermsOfUseComplete()) {
932    
933                            return true;
934                    }
935    
936                    return false;
937            }
938    
939            @Override
940            public boolean isTermsOfUseComplete() {
941                    boolean termsOfUseRequired = PrefsPropsUtil.getBoolean(
942                            getCompanyId(), PropsKeys.TERMS_OF_USE_REQUIRED,
943                            PropsValues.TERMS_OF_USE_REQUIRED);
944    
945                    if (termsOfUseRequired) {
946                            return super.isAgreedToTermsOfUse();
947                    }
948    
949                    return true;
950            }
951    
952            @Override
953            public void setLanguageId(String languageId) {
954                    _locale = LocaleUtil.fromLanguageId(languageId);
955    
956                    super.setLanguageId(LocaleUtil.toLanguageId(_locale));
957            }
958    
959            @Override
960            public void setPasswordModified(boolean passwordModified) {
961                    _passwordModified = passwordModified;
962            }
963    
964            @Override
965            public void setPasswordUnencrypted(String passwordUnencrypted) {
966                    _passwordUnencrypted = passwordUnencrypted;
967            }
968    
969            @Override
970            public void setTimeZoneId(String timeZoneId) {
971                    if (Validator.isNull(timeZoneId)) {
972                            timeZoneId = TimeZoneUtil.getDefault().getID();
973                    }
974    
975                    _timeZone = TimeZoneUtil.getTimeZone(timeZoneId);
976    
977                    super.setTimeZoneId(timeZoneId);
978            }
979    
980            protected String getProfileFriendlyURL() {
981                    if (Validator.isNull(PropsValues.USERS_PROFILE_FRIENDLY_URL)) {
982                            return null;
983                    }
984    
985                    return StringUtil.replace(
986                            PropsValues.USERS_PROFILE_FRIENDLY_URL,
987                            new String[] {"${liferay:screenName}", "${liferay:userId}"},
988                            new String[] {
989                                    HtmlUtil.escapeURL(getScreenName()), String.valueOf(getUserId())
990                            });
991            }
992    
993            private static final Log _log = LogFactoryUtil.getLog(UserImpl.class);
994    
995            private Locale _locale;
996            private boolean _passwordModified;
997            private PasswordPolicy _passwordPolicy;
998            private String _passwordUnencrypted;
999            private final transient Map<String, RemotePreference> _remotePreferences =
1000                    new HashMap<>();
1001            private TimeZone _timeZone;
1002    
1003    }