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