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;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.util.DigesterUtil;
022    import com.liferay.portal.kernel.util.GetterUtil;
023    import com.liferay.portal.kernel.util.HttpUtil;
024    import com.liferay.portal.kernel.util.PropsKeys;
025    import com.liferay.portal.kernel.util.PropsUtil;
026    import com.liferay.portal.kernel.util.StringBundler;
027    import com.liferay.portal.kernel.util.StringPool;
028    import com.liferay.portal.kernel.webserver.WebServerServletTokenUtil;
029    import com.liferay.portal.service.UserLocalServiceUtil;
030    
031    /**
032     * @author Amos Fong
033     */
034    @ProviderType
035    public class UserConstants {
036    
037            public static final int FULL_NAME_MAX_LENGTH = 75;
038    
039            public static final String LIST_VIEW_FLAT_ORGANIZATIONS =
040                    "flat-organizations";
041    
042            public static final String LIST_VIEW_FLAT_USER_GROUPS = "flat-user-groups";
043    
044            public static final String LIST_VIEW_FLAT_USERS = "flat-users";
045    
046            public static final String LIST_VIEW_TREE = "tree";
047    
048            public static final long USER_ID_DEFAULT = 0;
049    
050            public static final String USERS_EMAIL_ADDRESS_AUTO_SUFFIX = PropsUtil.get(
051                    PropsKeys.USERS_EMAIL_ADDRESS_AUTO_SUFFIX);
052    
053            /**
054             * @deprecated As of 7.0.0 replaced by {@link #getPortraitURL(String,
055             *             boolean, long, String)}
056             */
057            @Deprecated
058            public static String getPortraitURL(
059                    String imagePath, boolean male, long portraitId) {
060    
061                    if (!GetterUtil.getBoolean(
062                                    PropsUtil.get(PropsKeys.USERS_IMAGE_CHECK_TOKEN))) {
063    
064                            return getPortraitURL(imagePath, male, portraitId, null);
065                    }
066    
067                    if (portraitId <= 0) {
068                            return getPortraitURL(imagePath, male, 0, StringPool.BLANK);
069                    }
070    
071                    try {
072                            User user = UserLocalServiceUtil.fetchUserByPortraitId(portraitId);
073    
074                            if (user == null) {
075                                    return getPortraitURL(imagePath, male, 0, StringPool.BLANK);
076                            }
077    
078                            return getPortraitURL(
079                                    imagePath, male, portraitId, user.getUserUuid());
080                    }
081                    catch (Exception e) {
082                            if (_log.isWarnEnabled()) {
083                                    _log.warn(e, e);
084                            }
085                    }
086    
087                    return StringPool.BLANK;
088            }
089    
090            public static String getPortraitURL(
091                    String imagePath, boolean male, long portraitId, String userUuid) {
092    
093                    StringBundler sb = new StringBundler(9);
094    
095                    sb.append(imagePath);
096                    sb.append("/user_");
097    
098                    if (male) {
099                            sb.append("male");
100                    }
101                    else {
102                            sb.append("female");
103                    }
104    
105                    sb.append("_portrait?img_id=");
106                    sb.append(portraitId);
107    
108                    if (GetterUtil.getBoolean(
109                                    PropsUtil.get(PropsKeys.USERS_IMAGE_CHECK_TOKEN))) {
110    
111                            sb.append("&img_id_token=");
112                            sb.append(HttpUtil.encodeURL(DigesterUtil.digest(userUuid)));
113                    }
114    
115                    sb.append("&t=");
116                    sb.append(WebServerServletTokenUtil.getToken(portraitId));
117    
118                    return sb.toString();
119            }
120    
121            private static final Log _log = LogFactoryUtil.getLog(UserConstants.class);
122    
123    }