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