Commit 09e11527 authored by Liang Ding's avatar Liang Ding

Fix #12036

parent c24a0b8e
<?xml version="1.0" encoding="UTF-8"?>
<!--
Description: Solo POM.
Version: 2.4.1.7, Oct 1, 2015
Version: 2.5.1.7, Oct 17, 2015
Author: Liang Ding
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
......@@ -125,7 +125,7 @@
<testng.version>6.1.1</testng.version>
<gae.version>1.8.1.1</gae.version>
<!-- JDBC Drivers -->
<mysql-connector-java.version>5.1.18</mysql-connector-java.version>
<mysql-connector-java.version>5.1.36</mysql-connector-java.version>
</properties>
<dependencies>
......
......@@ -53,7 +53,7 @@ import org.json.JSONObject;
* Solo Servlet listener.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.5.0.7, Oct 1, 2015
* @version 1.5.0.8, Oct 17, 2015
* @since 0.3.1
*/
public final class SoloServletListener extends AbstractServletListener {
......
......@@ -20,7 +20,7 @@ package org.b3log.solo.model;
* This class defines ext of user model relevant keys.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Feb 21, 2012
* @version 1.1.0.0, Oct 17, 2015
* @since 0.4.1
* @see org.b3log.latke.model.User
*/
......@@ -36,6 +36,11 @@ public final class UserExt {
*/
public static final String USER_PUBLISHED_ARTICLE_COUNT = "userPublishedArticleCount";
/**
* Key of user avatar.
*/
public static final String USER_AVATAR = "userAvatar";
/**
* Private constructor.
*/
......
......@@ -930,8 +930,13 @@ public class ArticleProcessor {
article.put(Common.AUTHOR_ID, authorId);
article.put(Common.AUTHOR_ROLE, author.getString(User.USER_ROLE));
final String userAvatar = author.optString(UserExt.USER_AVATAR);
if (!Strings.isEmptyOrNull(userAvatar)) {
article.put(Common.AUTHOR_THUMBNAIL_URL, userAvatar);
} else {
final String thumbnailURL = Thumbnails.getGravatarURL(author.optString(User.USER_EMAIL), "60");
article.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL);
}
final Map<String, Object> dataModel = renderer.getDataModel();
......@@ -1190,9 +1195,14 @@ public class ArticleProcessor {
dataModel.put(Keys.OBJECT_ID, authorId);
dataModel.put(Common.AUTHOR_NAME, author.optString(User.USER_NAME));
final String thumbnailURL = Thumbnails.getGravatarURL(author.optString(User.USER_EMAIL), "60");
final String userAvatar = author.optString(UserExt.USER_AVATAR);
if (!Strings.isEmptyOrNull(userAvatar)) {
dataModel.put(Common.AUTHOR_THUMBNAIL_URL, userAvatar);
} else {
final String thumbnailURL = Thumbnails.getGravatarURL(author.optString(User.USER_EMAIL), "60");
dataModel.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL);
}
dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, currentPageNum);
}
......
......@@ -40,17 +40,19 @@ import org.b3log.latke.util.Sessions;
import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.Common;
import org.b3log.solo.model.UserExt;
import org.b3log.solo.processor.renderer.ConsoleRenderer;
import org.b3log.solo.processor.util.Filler;
import org.b3log.solo.service.InitService;
import org.b3log.solo.util.QueryResults;
import org.b3log.solo.util.Thumbnails;
import org.json.JSONObject;
/**
* Solo initialization service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.8, Aug 8, 2015
* @version 1.2.0.8, Oct 17, 2015
* @since 0.4.0
*/
@RequestProcessor
......@@ -185,11 +187,11 @@ public class InitProcessor {
// If initialized, login the admin
final JSONObject admin = new JSONObject();
admin.put(User.USER_NAME, requestJSONObject.getString(User.USER_NAME));
admin.put(User.USER_EMAIL, requestJSONObject.getString(User.USER_EMAIL));
admin.put(User.USER_NAME, userName);
admin.put(User.USER_EMAIL, userEmail);
admin.put(User.USER_ROLE, Role.ADMIN_ROLE);
admin.put(User.USER_PASSWORD, requestJSONObject.getString(User.USER_PASSWORD));
admin.put(User.USER_PASSWORD, userPassword);
admin.put(UserExt.USER_AVATAR, Thumbnails.getGravatarURL(userEmail, "60"));
Sessions.login(request, response, admin);
......
......@@ -18,7 +18,6 @@ package org.b3log.solo.processor;
import java.io.IOException;
import javax.inject.Inject;
import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.mail.MailService;
......@@ -36,6 +35,7 @@ import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.*;
import org.b3log.solo.repository.*;
import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.Thumbnails;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
......@@ -45,7 +45,7 @@ import org.json.JSONObject;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:dongxu.wang@acm.org">Dongxu Wang</a>
* @version 1.4.1.14, Oct 1, 2015
* @version 1.5.1.14, Oct 17, 2015
* @since 0.3.1
*/
@RequestProcessor
......@@ -178,6 +178,8 @@ public class UpgradeProcessor {
try {
transaction = userRepository.beginTransaction();
upgradeUsers();
// Upgrades preference model
final JSONObject preference = preferenceRepository.get(Preference.PREFERENCE);
......@@ -213,11 +215,13 @@ public class UpgradeProcessor {
for (int i = 0; i < users.length(); i++) {
final JSONObject user = users.getJSONObject(i);
user.put(User.USER_URL, Latkes.getServePath());
final String email = user.optString(User.USER_EMAIL);
user.put(UserExt.USER_AVATAR, Thumbnails.getGravatarURL(email, "60"));
userRepository.update(user.optString(Keys.OBJECT_ID), user);
LOGGER.log(Level.INFO, "Hashed user[name={0}] password.", user.optString(User.USER_NAME));
LOGGER.log(Level.INFO, "Updated user[name={0}]");
}
}
......
......@@ -46,6 +46,7 @@ import org.b3log.solo.model.Common;
import org.b3log.solo.model.Option;
import org.b3log.solo.model.Preference;
import org.b3log.solo.model.Skin;
import org.b3log.solo.model.UserExt;
import org.b3log.solo.processor.renderer.ConsoleRenderer;
import org.b3log.solo.processor.util.Filler;
import org.b3log.solo.service.OptionQueryService;
......@@ -135,9 +136,14 @@ public class AdminConsole {
dataModel.put(User.USER_ROLE, roleName);
final String email = currentUser.optString(User.USER_EMAIL);
final String gravatar = Thumbnails.getGravatarURL(email, "60");
final String userAvatar = currentUser.optString(UserExt.USER_AVATAR);
if (!Strings.isEmptyOrNull(userAvatar)) {
dataModel.put(Common.GRAVATAR, userAvatar);
} else {
final String gravatar = Thumbnails.getGravatarURL(email, "60");
dataModel.put(Common.GRAVATAR, gravatar);
}
try {
final JSONObject qiniu = optionQueryService.getOptions(Option.CATEGORY_C_QINIU);
......
......@@ -44,7 +44,7 @@ import org.json.JSONObject;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:385321165@qq.com">DASHU</a>
* @version 1.0.0.4, Apr 2, 2013
* @version 1.1.0.4, Oct 17, 2015
* @since 0.4.0
*/
@RequestProcessor
......@@ -95,6 +95,7 @@ public class UserConsole {
* "userPassword": "", // Unhashed
* "userRole": "", // optional
* "userURL": "", // optional
* "userAvatar": "" // optional
* }
* </pre>
* @param context the specified http request context
......@@ -155,7 +156,8 @@ public class UserConsole {
* "userEmail": "",
* "userPassword": "",
* "userURL": "", // optional, uses 'servePath' instead if not specified
* "userRole": "" // optional, uses {@value org.b3log.latke.model.Role#DEFAULT_ROLE} instead if not speciffied
* "userRole": "", // optional, uses {@value org.b3log.latke.model.Role#DEFAULT_ROLE} instead if not specified
* "userAvatar": "" // optional
* }
* </pre>
* @param response the specified http servlet response
......@@ -327,7 +329,8 @@ public class UserConsole {
* "oId": "",
* "userName": "",
* "userEmail": "",
* "userPassword": ""
* "userPassword": "",
* "userAvatar": ""
* }
* }
* </pre>
......
......@@ -575,9 +575,14 @@ public class Filler {
dataModel.put(User.USER_NAME, "");
final JSONObject currentUser = userQueryService.getCurrentUser(request);
if (null != currentUser) {
final String userAvatar = currentUser.optString(UserExt.USER_AVATAR);
if (!Strings.isEmptyOrNull(userAvatar)) {
dataModel.put(Common.GRAVATAR, userAvatar);
} else {
final String email = currentUser.optString(User.USER_EMAIL);
final String gravatar = Thumbnails.getGravatarURL(email, "60");
dataModel.put(Common.GRAVATAR, gravatar);
}
dataModel.put(User.USER_NAME, currentUser.optString(User.USER_NAME));
}
......@@ -909,8 +914,13 @@ public class Filler {
article.put(Common.AUTHOR_ID, authorId);
final String userAvatar = author.optString(UserExt.USER_AVATAR);
if (!Strings.isEmptyOrNull(userAvatar)) {
article.put(Common.AUTHOR_THUMBNAIL_URL, userAvatar);
} else {
final String thumbnailURL = Thumbnails.getGravatarURL(author.optString(User.USER_EMAIL), "60");
article.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL);
}
if (preference.getBoolean(Preference.ENABLE_ARTICLE_UPDATE_HINT)) {
article.put(Common.HAS_UPDATED, articleQueryService.hasUpdated(article));
......@@ -966,8 +976,13 @@ public class Filler {
article.put(Common.AUTHOR_ID, authorId);
final String userAvatar = author.optString(UserExt.USER_AVATAR);
if (!Strings.isEmptyOrNull(userAvatar)) {
article.put(Common.AUTHOR_THUMBNAIL_URL, userAvatar);
} else {
final String thumbnailURL = Thumbnails.getGravatarURL(author.optString(User.USER_EMAIL), "60");
article.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL);
}
if (preference.getBoolean(Preference.ENABLE_ARTICLE_UPDATE_HINT)) {
article.put(Common.HAS_UPDATED, articleQueryService.hasUpdated(article));
......
......@@ -63,7 +63,7 @@ import org.json.JSONObject;
* Solo initialization service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.2.8, Jul 14, 2015
* @version 1.2.2.8, Oct 17, 2015
* @since 0.4.0
*/
@Service
......@@ -491,6 +491,7 @@ public class InitService {
admin.put(User.USER_PASSWORD, MD5.hash(requestJSONObject.getString(User.USER_PASSWORD)));
admin.put(UserExt.USER_ARTICLE_COUNT, 0);
admin.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0);
admin.put(UserExt.USER_AVATAR, Thumbnails.getGravatarURL(requestJSONObject.getString(User.USER_EMAIL), "60"));
userRepository.add(admin);
......
......@@ -15,11 +15,11 @@
*/
package org.b3log.solo.service;
import javax.inject.Inject;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.ioc.LatkeBeanManager;
......@@ -38,15 +38,15 @@ import org.b3log.latke.util.Sessions;
import org.b3log.latke.util.Strings;
import org.b3log.solo.model.UserExt;
import org.b3log.solo.repository.UserRepository;
import org.b3log.solo.util.Thumbnails;
import org.json.JSONObject;
/**
* User management service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:385321165@qq.com">DASHU</a>
* @version 1.0.0.6, May 27, 2013
* @version 1.1.0.6, Oct 17, 2015
* @since 0.4.0
*/
@Service
......@@ -135,8 +135,7 @@ public class UserMgmtService {
/**
* Updates a user by the specified request json object.
*
* @param requestJSONObject the specified request json object, for example,
* <pre>
* @param requestJSONObject the specified request json object, for example, <pre>
* {
* "oId": "",
* "userName": "",
......@@ -146,6 +145,7 @@ public class UserMgmtService {
* "userURL": "", // optional
* }
* </pre>
*
* @throws ServiceException service exception
*/
public void updateUser(final JSONObject requestJSONObject) throws ServiceException {
......@@ -186,17 +186,20 @@ public class UserMgmtService {
}
final String userRole = requestJSONObject.optString(User.USER_ROLE);
if (!Strings.isEmptyOrNull(userRole)) {
oldUser.put(User.USER_ROLE, userRole);
}
final String userURL = requestJSONObject.optString(User.USER_URL);
if (!Strings.isEmptyOrNull(userURL)) {
oldUser.put(User.USER_URL, userURL);
}
final String userAvatar = requestJSONObject.optString(UserExt.USER_AVATAR);
if (!StringUtils.equals(userAvatar, oldUser.optString(UserExt.USER_AVATAR))) {
oldUser.put(UserExt.USER_AVATAR, userAvatar);
}
userRepository.update(oldUserId, oldUser);
transaction.commit();
} catch (final RepositoryException e) {
......@@ -249,16 +252,17 @@ public class UserMgmtService {
/**
* Adds a user with the specified request json object.
*
* @param requestJSONObject the specified request json object, for example,
* <pre>
* @param requestJSONObject the specified request json object, for example, <pre>
* {
* "userName": "",
* "userEmail": "",
* "userPassword": "", // Unhashed
* "userURL": "", // optional, uses 'servePath' instead if not specified
* "userRole": "" // optional, uses {@value Role#DEFAULT_ROLE} instead, if not speciffied
* "userRole": "", // optional, uses {@value Role#DEFAULT_ROLE} instead if not specified
* "userAvatar": "" // optional, users generated gravatar url instead if not specified
* }
* </pre>,see {@link User} for more details
*
* @return generated user id
* @throws ServiceException service exception
*/
......@@ -281,15 +285,12 @@ public class UserMgmtService {
user.put(User.USER_EMAIL, userEmail);
final String userName = requestJSONObject.optString(User.USER_NAME);
user.put(User.USER_NAME, userName);
final String userPassword = requestJSONObject.optString(User.USER_PASSWORD);
user.put(User.USER_PASSWORD, MD5.hash(userPassword));
String userURL = requestJSONObject.optString(User.USER_URL);
if (Strings.isEmptyOrNull(userURL)) {
userURL = Latkes.getServePath();
}
......@@ -301,12 +302,17 @@ public class UserMgmtService {
user.put(User.USER_URL, userURL);
final String roleName = requestJSONObject.optString(User.USER_ROLE, Role.DEFAULT_ROLE);
user.put(User.USER_ROLE, roleName);
user.put(UserExt.USER_ARTICLE_COUNT, 0);
user.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0);
String userAvatar = requestJSONObject.optString(UserExt.USER_AVATAR);
if (Strings.isEmptyOrNull(userAvatar)) {
userAvatar = Thumbnails.getGravatarURL(userEmail, "60");
}
user.put(UserExt.USER_AVATAR, userAvatar);
userRepository.add(user);
transaction.commit();
......
......@@ -16,12 +16,13 @@
#
# Description: Solo language configurations(en_US).
# Version: 2.5.2.4, Sep 17, 2015
# Version: 2.5.2.5, Oct 17, 2015
# Author: Liang Ding
# Author: Liyuan Li
# Author: Dongxu Wang
#
userAvatar1Label=Avatar:
uploadFileLabel=Upload <a href="http://hacpai.com/article/1442418791213" target="_blank">(?)</a>
accessKey1Label=Access Key:
secretKey1Label=Secret Key:
......
......@@ -16,12 +16,13 @@
#
# Description: Solo default language configurations(zh_CN).
# Version: 2.5.4.12, Sep 17, 2015
# Version: 2.5.4.13, Oct 17, 2015
# Author: Liang Ding
# Author: Liyuan Li
# Author: Dongxu Wang
#
userAvatar1Label=\u5934\u50cf\uff1a
uploadFileLabel=\u6587\u4ef6\u4e0a\u4f20 <a href="http://hacpai.com/article/1442418791213" target="_blank">(?)</a>
accessKey1Label=Access Key\uff1a
secretKey1Label=Secret Key\uff1a
......
......@@ -16,7 +16,7 @@
#
# Description: B3log Latke configurations. Configures the section "Server" carefully.
# Version: 1.2.1.6, Oct 1, 2015
# Version: 1.2.2.6, Oct 17, 2015
# Author: Liang Ding
#
......@@ -41,8 +41,8 @@ scanPath=org.b3log.solo
runtimeEnv=LOCAL
#### Runtime Mode ####
runtimeMode=DEVELOPMENT
#runtimeMode=DEVELOPMENT
runtimeMode=PRODUCTION
#### Cache Implementation ####
# Note: If the runtime environment is LOCAL, the cache will be 'LOCAL' always
......
{
"description": "Description of repository structures, for generation (DDL: http://en.wikipedia.org/wiki/Data_Definition_Language) of the relational database table and persistence validation.",
"version": "1.0.1.1, May 17, 2013",
"version": "1.1.1.1, Oct 17, 2015",
"authors": ["Liang Ding"],
"since": "0.4.0",
"repositories": [
......@@ -553,6 +553,11 @@
{
"name": "userPublishedArticleCount",
"type": "int"
},
{
"name": "userAvatar",
"type": "String",
"length": 255
}
]
},
......
......@@ -42,6 +42,14 @@
<input id="userPassword" type="password"/>
</td>
</tr>
<tr>
<th>
<label for="userAvatar">${userAvatar1Label}</label>
</th>
<td>
<input id="userAvatar" type="text"/>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<button onclick="admin.userList.add();">${saveLabel}</button>
......@@ -91,6 +99,14 @@
<input id="userPasswordUpdate" type="password"/>
</td>
</tr>
<tr>
<th>
<label for="userAvatarUpdate">${userAvatar1Label}</label>
</th>
<td>
<input id="userAvatarUpdate" type="text"/>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<button onclick="admin.userList.update();">${updateLabel}</button>
......
......@@ -18,7 +18,7 @@
*
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.1.7, May 28, 2013
* @version 1.1.1.7, Oct 17, 2015
*/
/* user-list 相关操作 */
......@@ -59,7 +59,7 @@ admin.userList = {
$("#userUpdate").dialog({
width: 700,
height: 230,
height: 250,
"modal": true,
"hideFooter": true
});
......@@ -136,7 +136,8 @@ admin.userList = {
"userName": $("#userName").val(),
"userEmail": $("#userEmail").val(),
"userURL": $("#userURL").val(),
"userPassword": $("#userPassword").val()
"userPassword": $("#userPassword").val(),
"userAvatar": $("#userAvatar").val()
};
$.ajax({
......@@ -155,6 +156,7 @@ admin.userList = {
$("#userEmail").val("");
$("#userURL").val("");
$("#userPassword").val("");
$("#userAvatar").val("");
if (admin.userList.pageInfo.currentCount === Label.PAGE_SIZE &&
admin.userList.pageInfo.currentPage === admin.userList.pageInfo.pageCount) {
admin.userList.pageInfo.pageCount++;
......@@ -205,6 +207,7 @@ admin.userList = {
$("#userURLUpdate").val(result.user.userURL);
$("#userPasswordUpdate").val(result.user.userPassword);
$("#userAvatarUpdate").val(result.user.userAvatar);
$("#loadMsg").text("");
}
......@@ -225,7 +228,8 @@ admin.userList = {
"userEmail": $("#userEmailUpdate").val(),
"userURL": $("#userURLUpdate").val(),
"userRole": userInfo.userRole,
"userPassword": $("#userPasswordUpdate").val()
"userPassword": $("#userPasswordUpdate").val(),
"userAvatar": $("#userAvatarUpdate").val()
};
$.ajax({
......
......@@ -34,7 +34,7 @@ import org.testng.annotations.Test;
* {@link UserRepositoryImpl} test case.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.2, Apr 2, 2013
* @version 1.1.0.2, Oct 17, 2015
*/
@Test(suiteName = "repository")
public final class UserRepositoryImplTestCase extends AbstractTestCase {
......@@ -56,6 +56,7 @@ public final class UserRepositoryImplTestCase extends AbstractTestCase {
another.put(User.USER_ROLE, Role.DEFAULT_ROLE);
another.put(UserExt.USER_ARTICLE_COUNT, 0);
another.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0);
another.put(UserExt.USER_AVATAR, "");
Transaction transaction = userRepository.beginTransaction();
userRepository.add(another);
......@@ -71,6 +72,7 @@ public final class UserRepositoryImplTestCase extends AbstractTestCase {
admin.put(User.USER_ROLE, Role.ADMIN_ROLE);
admin.put(UserExt.USER_ARTICLE_COUNT, 0);
admin.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0);
admin.put(UserExt.USER_AVATAR, "");
transaction = userRepository.beginTransaction();
userRepository.add(admin);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment