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

Fix #12036

parent c24a0b8e
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
Description: Solo POM. Description: Solo POM.
Version: 2.4.1.7, Oct 1, 2015 Version: 2.5.1.7, Oct 17, 2015
Author: Liang Ding Author: Liang Ding
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
...@@ -125,7 +125,7 @@ ...@@ -125,7 +125,7 @@
<testng.version>6.1.1</testng.version> <testng.version>6.1.1</testng.version>
<gae.version>1.8.1.1</gae.version> <gae.version>1.8.1.1</gae.version>
<!-- JDBC Drivers --> <!-- 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> </properties>
<dependencies> <dependencies>
......
...@@ -53,7 +53,7 @@ import org.json.JSONObject; ...@@ -53,7 +53,7 @@ import org.json.JSONObject;
* Solo Servlet listener. * Solo Servlet listener.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @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 * @since 0.3.1
*/ */
public final class SoloServletListener extends AbstractServletListener { public final class SoloServletListener extends AbstractServletListener {
......
...@@ -20,7 +20,7 @@ package org.b3log.solo.model; ...@@ -20,7 +20,7 @@ package org.b3log.solo.model;
* This class defines ext of user model relevant keys. * This class defines ext of user model relevant keys.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @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 * @since 0.4.1
* @see org.b3log.latke.model.User * @see org.b3log.latke.model.User
*/ */
...@@ -35,6 +35,11 @@ public final class UserExt { ...@@ -35,6 +35,11 @@ public final class UserExt {
* Key of user article count. * Key of user article count.
*/ */
public static final String USER_PUBLISHED_ARTICLE_COUNT = "userPublishedArticleCount"; public static final String USER_PUBLISHED_ARTICLE_COUNT = "userPublishedArticleCount";
/**
* Key of user avatar.
*/
public static final String USER_AVATAR = "userAvatar";
/** /**
* Private constructor. * Private constructor.
......
...@@ -930,8 +930,13 @@ public class ArticleProcessor { ...@@ -930,8 +930,13 @@ public class ArticleProcessor {
article.put(Common.AUTHOR_ID, authorId); article.put(Common.AUTHOR_ID, authorId);
article.put(Common.AUTHOR_ROLE, author.getString(User.USER_ROLE)); article.put(Common.AUTHOR_ROLE, author.getString(User.USER_ROLE));
final String thumbnailURL = Thumbnails.getGravatarURL(author.optString(User.USER_EMAIL), "60"); final String userAvatar = author.optString(UserExt.USER_AVATAR);
article.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL); 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(); final Map<String, Object> dataModel = renderer.getDataModel();
...@@ -1190,9 +1195,14 @@ public class ArticleProcessor { ...@@ -1190,9 +1195,14 @@ public class ArticleProcessor {
dataModel.put(Keys.OBJECT_ID, authorId); dataModel.put(Keys.OBJECT_ID, authorId);
dataModel.put(Common.AUTHOR_NAME, author.optString(User.USER_NAME)); dataModel.put(Common.AUTHOR_NAME, author.optString(User.USER_NAME));
final String thumbnailURL = Thumbnails.getGravatarURL(author.optString(User.USER_EMAIL), "60");
dataModel.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL); 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); dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, currentPageNum);
} }
......
...@@ -40,17 +40,19 @@ import org.b3log.latke.util.Sessions; ...@@ -40,17 +40,19 @@ import org.b3log.latke.util.Sessions;
import org.b3log.latke.util.Strings; import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener; import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.Common; import org.b3log.solo.model.Common;
import org.b3log.solo.model.UserExt;
import org.b3log.solo.processor.renderer.ConsoleRenderer; import org.b3log.solo.processor.renderer.ConsoleRenderer;
import org.b3log.solo.processor.util.Filler; import org.b3log.solo.processor.util.Filler;
import org.b3log.solo.service.InitService; import org.b3log.solo.service.InitService;
import org.b3log.solo.util.QueryResults; import org.b3log.solo.util.QueryResults;
import org.b3log.solo.util.Thumbnails;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Solo initialization service. * Solo initialization service.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @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 * @since 0.4.0
*/ */
@RequestProcessor @RequestProcessor
...@@ -185,11 +187,11 @@ public class InitProcessor { ...@@ -185,11 +187,11 @@ public class InitProcessor {
// If initialized, login the admin // If initialized, login the admin
final JSONObject admin = new JSONObject(); final JSONObject admin = new JSONObject();
admin.put(User.USER_NAME, userName);
admin.put(User.USER_NAME, requestJSONObject.getString(User.USER_NAME)); admin.put(User.USER_EMAIL, userEmail);
admin.put(User.USER_EMAIL, requestJSONObject.getString(User.USER_EMAIL));
admin.put(User.USER_ROLE, Role.ADMIN_ROLE); 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); Sessions.login(request, response, admin);
......
...@@ -18,7 +18,6 @@ package org.b3log.solo.processor; ...@@ -18,7 +18,6 @@ package org.b3log.solo.processor;
import java.io.IOException; import java.io.IOException;
import javax.inject.Inject; import javax.inject.Inject;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
import org.b3log.latke.mail.MailService; import org.b3log.latke.mail.MailService;
...@@ -36,6 +35,7 @@ import org.b3log.solo.SoloServletListener; ...@@ -36,6 +35,7 @@ import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.*; import org.b3log.solo.model.*;
import org.b3log.solo.repository.*; import org.b3log.solo.repository.*;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.Thumbnails;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -45,7 +45,7 @@ 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="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:dongxu.wang@acm.org">Dongxu Wang</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 * @since 0.3.1
*/ */
@RequestProcessor @RequestProcessor
...@@ -147,17 +147,17 @@ public class UpgradeProcessor { ...@@ -147,17 +147,17 @@ public class UpgradeProcessor {
} }
LOGGER.log(Level.WARN, "Attempt to skip more than one version to upgrade. Expected: {0}; Actually: {1}", FROM_VER, currentVer); LOGGER.log(Level.WARN, "Attempt to skip more than one version to upgrade. Expected: {0}; Actually: {1}", FROM_VER, currentVer);
if (!sent) { if (!sent) {
notifyUserByEmail(); notifyUserByEmail();
sent = true; sent = true;
} }
renderer.setContent(langPropsService.get("skipVersionAlert")); renderer.setContent(langPropsService.get("skipVersionAlert"));
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e); LOGGER.log(Level.ERROR, e.getMessage(), e);
renderer.setContent( renderer.setContent(
"Upgrade failed [" + e.getMessage() + "], please contact the Solo developers or reports this " "Upgrade failed [" + e.getMessage() + "], please contact the Solo developers or reports this "
+ "issue directly (<a href='https://github.com/b3log/solo/issues/new'>" + "issue directly (<a href='https://github.com/b3log/solo/issues/new'>"
...@@ -178,6 +178,8 @@ public class UpgradeProcessor { ...@@ -178,6 +178,8 @@ public class UpgradeProcessor {
try { try {
transaction = userRepository.beginTransaction(); transaction = userRepository.beginTransaction();
upgradeUsers();
// Upgrades preference model // Upgrades preference model
final JSONObject preference = preferenceRepository.get(Preference.PREFERENCE); final JSONObject preference = preferenceRepository.get(Preference.PREFERENCE);
...@@ -213,11 +215,13 @@ public class UpgradeProcessor { ...@@ -213,11 +215,13 @@ public class UpgradeProcessor {
for (int i = 0; i < users.length(); i++) { for (int i = 0; i < users.length(); i++) {
final JSONObject user = users.getJSONObject(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); 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}]");
} }
} }
...@@ -288,9 +292,9 @@ public class UpgradeProcessor { ...@@ -288,9 +292,9 @@ public class UpgradeProcessor {
message.addRecipient(adminEmail); message.addRecipient(adminEmail);
message.setSubject(langPropsService.get("skipVersionMailSubject")); message.setSubject(langPropsService.get("skipVersionMailSubject"));
message.setHtmlBody(langPropsService.get("skipVersionMailBody")); message.setHtmlBody(langPropsService.get("skipVersionMailBody"));
MAIL_SVC.send(message); MAIL_SVC.send(message);
LOGGER.info("Send an email to the user who upgrades Solo with a discontinuous version."); LOGGER.info("Send an email to the user who upgrades Solo with a discontinuous version.");
} }
} }
...@@ -46,6 +46,7 @@ import org.b3log.solo.model.Common; ...@@ -46,6 +46,7 @@ import org.b3log.solo.model.Common;
import org.b3log.solo.model.Option; import org.b3log.solo.model.Option;
import org.b3log.solo.model.Preference; import org.b3log.solo.model.Preference;
import org.b3log.solo.model.Skin; import org.b3log.solo.model.Skin;
import org.b3log.solo.model.UserExt;
import org.b3log.solo.processor.renderer.ConsoleRenderer; import org.b3log.solo.processor.renderer.ConsoleRenderer;
import org.b3log.solo.processor.util.Filler; import org.b3log.solo.processor.util.Filler;
import org.b3log.solo.service.OptionQueryService; import org.b3log.solo.service.OptionQueryService;
...@@ -135,9 +136,14 @@ public class AdminConsole { ...@@ -135,9 +136,14 @@ public class AdminConsole {
dataModel.put(User.USER_ROLE, roleName); dataModel.put(User.USER_ROLE, roleName);
final String email = currentUser.optString(User.USER_EMAIL); final String email = currentUser.optString(User.USER_EMAIL);
final String gravatar = Thumbnails.getGravatarURL(email, "60");
dataModel.put(Common.GRAVATAR, gravatar); 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 { try {
final JSONObject qiniu = optionQueryService.getOptions(Option.CATEGORY_C_QINIU); final JSONObject qiniu = optionQueryService.getOptions(Option.CATEGORY_C_QINIU);
......
...@@ -44,7 +44,7 @@ import org.json.JSONObject; ...@@ -44,7 +44,7 @@ import org.json.JSONObject;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:385321165@qq.com">DASHU</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 * @since 0.4.0
*/ */
@RequestProcessor @RequestProcessor
...@@ -95,6 +95,7 @@ public class UserConsole { ...@@ -95,6 +95,7 @@ public class UserConsole {
* "userPassword": "", // Unhashed * "userPassword": "", // Unhashed
* "userRole": "", // optional * "userRole": "", // optional
* "userURL": "", // optional * "userURL": "", // optional
* "userAvatar": "" // optional
* } * }
* </pre> * </pre>
* @param context the specified http request context * @param context the specified http request context
...@@ -155,7 +156,8 @@ public class UserConsole { ...@@ -155,7 +156,8 @@ public class UserConsole {
* "userEmail": "", * "userEmail": "",
* "userPassword": "", * "userPassword": "",
* "userURL": "", // optional, uses 'servePath' instead if not specified * "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> * </pre>
* @param response the specified http servlet response * @param response the specified http servlet response
...@@ -327,7 +329,8 @@ public class UserConsole { ...@@ -327,7 +329,8 @@ public class UserConsole {
* "oId": "", * "oId": "",
* "userName": "", * "userName": "",
* "userEmail": "", * "userEmail": "",
* "userPassword": "" * "userPassword": "",
* "userAvatar": ""
* } * }
* } * }
* </pre> * </pre>
......
...@@ -575,9 +575,14 @@ public class Filler { ...@@ -575,9 +575,14 @@ public class Filler {
dataModel.put(User.USER_NAME, ""); dataModel.put(User.USER_NAME, "");
final JSONObject currentUser = userQueryService.getCurrentUser(request); final JSONObject currentUser = userQueryService.getCurrentUser(request);
if (null != currentUser) { if (null != currentUser) {
final String email = currentUser.optString(User.USER_EMAIL); final String userAvatar = currentUser.optString(UserExt.USER_AVATAR);
final String gravatar = Thumbnails.getGravatarURL(email, "60"); if (!Strings.isEmptyOrNull(userAvatar)) {
dataModel.put(Common.GRAVATAR, gravatar); 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)); dataModel.put(User.USER_NAME, currentUser.optString(User.USER_NAME));
} }
...@@ -909,8 +914,13 @@ public class Filler { ...@@ -909,8 +914,13 @@ public class Filler {
article.put(Common.AUTHOR_ID, authorId); article.put(Common.AUTHOR_ID, authorId);
final String thumbnailURL = Thumbnails.getGravatarURL(author.optString(User.USER_EMAIL), "60"); final String userAvatar = author.optString(UserExt.USER_AVATAR);
article.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL); 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)) { if (preference.getBoolean(Preference.ENABLE_ARTICLE_UPDATE_HINT)) {
article.put(Common.HAS_UPDATED, articleQueryService.hasUpdated(article)); article.put(Common.HAS_UPDATED, articleQueryService.hasUpdated(article));
...@@ -923,7 +933,7 @@ public class Filler { ...@@ -923,7 +933,7 @@ public class Filler {
article.put(ARTICLE_CONTENT, content); article.put(ARTICLE_CONTENT, content);
} }
processArticleAbstract(preference, article); processArticleAbstract(preference, article);
articleQueryService.markdown(article); articleQueryService.markdown(article);
...@@ -966,8 +976,13 @@ public class Filler { ...@@ -966,8 +976,13 @@ public class Filler {
article.put(Common.AUTHOR_ID, authorId); article.put(Common.AUTHOR_ID, authorId);
final String thumbnailURL = Thumbnails.getGravatarURL(author.optString(User.USER_EMAIL), "60"); final String userAvatar = author.optString(UserExt.USER_AVATAR);
article.put(Common.AUTHOR_THUMBNAIL_URL, thumbnailURL); 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)) { if (preference.getBoolean(Preference.ENABLE_ARTICLE_UPDATE_HINT)) {
article.put(Common.HAS_UPDATED, articleQueryService.hasUpdated(article)); article.put(Common.HAS_UPDATED, articleQueryService.hasUpdated(article));
...@@ -980,7 +995,7 @@ public class Filler { ...@@ -980,7 +995,7 @@ public class Filler {
article.put(ARTICLE_CONTENT, content); article.put(ARTICLE_CONTENT, content);
} }
processArticleAbstract(preference, article); processArticleAbstract(preference, article);
articleQueryService.markdown(article); articleQueryService.markdown(article);
......
...@@ -63,7 +63,7 @@ import org.json.JSONObject; ...@@ -63,7 +63,7 @@ import org.json.JSONObject;
* Solo initialization service. * Solo initialization service.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @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 * @since 0.4.0
*/ */
@Service @Service
...@@ -491,6 +491,7 @@ public class InitService { ...@@ -491,6 +491,7 @@ public class InitService {
admin.put(User.USER_PASSWORD, MD5.hash(requestJSONObject.getString(User.USER_PASSWORD))); admin.put(User.USER_PASSWORD, MD5.hash(requestJSONObject.getString(User.USER_PASSWORD)));
admin.put(UserExt.USER_ARTICLE_COUNT, 0); admin.put(UserExt.USER_ARTICLE_COUNT, 0);
admin.put(UserExt.USER_PUBLISHED_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); userRepository.add(admin);
......
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
*/ */
package org.b3log.solo.service; package org.b3log.solo.service;
import javax.inject.Inject; import javax.inject.Inject;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.Latkes; import org.b3log.latke.Latkes;
import org.b3log.latke.ioc.LatkeBeanManager; import org.b3log.latke.ioc.LatkeBeanManager;
...@@ -38,15 +38,15 @@ import org.b3log.latke.util.Sessions; ...@@ -38,15 +38,15 @@ import org.b3log.latke.util.Sessions;
import org.b3log.latke.util.Strings; import org.b3log.latke.util.Strings;
import org.b3log.solo.model.UserExt; import org.b3log.solo.model.UserExt;
import org.b3log.solo.repository.UserRepository; import org.b3log.solo.repository.UserRepository;
import org.b3log.solo.util.Thumbnails;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* User management service. * User management service.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:385321165@qq.com">DASHU</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 * @since 0.4.0
*/ */
@Service @Service
...@@ -135,8 +135,7 @@ public class UserMgmtService { ...@@ -135,8 +135,7 @@ public class UserMgmtService {
/** /**
* Updates a user by the specified request json object. * Updates a user by the specified request json object.
* *
* @param requestJSONObject the specified request json object, for example, * @param requestJSONObject the specified request json object, for example, <pre>
* <pre>
* { * {
* "oId": "", * "oId": "",
* "userName": "", * "userName": "",
...@@ -146,6 +145,7 @@ public class UserMgmtService { ...@@ -146,6 +145,7 @@ public class UserMgmtService {
* "userURL": "", // optional * "userURL": "", // optional
* } * }
* </pre> * </pre>
*
* @throws ServiceException service exception * @throws ServiceException service exception
*/ */
public void updateUser(final JSONObject requestJSONObject) throws ServiceException { public void updateUser(final JSONObject requestJSONObject) throws ServiceException {
...@@ -186,16 +186,19 @@ public class UserMgmtService { ...@@ -186,16 +186,19 @@ public class UserMgmtService {
} }
final String userRole = requestJSONObject.optString(User.USER_ROLE); final String userRole = requestJSONObject.optString(User.USER_ROLE);
if (!Strings.isEmptyOrNull(userRole)) { if (!Strings.isEmptyOrNull(userRole)) {
oldUser.put(User.USER_ROLE, userRole); oldUser.put(User.USER_ROLE, userRole);
} }
final String userURL = requestJSONObject.optString(User.USER_URL); final String userURL = requestJSONObject.optString(User.USER_URL);
if (!Strings.isEmptyOrNull(userURL)) { if (!Strings.isEmptyOrNull(userURL)) {
oldUser.put(User.USER_URL, 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); userRepository.update(oldUserId, oldUser);
transaction.commit(); transaction.commit();
...@@ -210,7 +213,7 @@ public class UserMgmtService { ...@@ -210,7 +213,7 @@ public class UserMgmtService {
} }
/** /**
* Swithches the user role between "defaultRole" and "visitorRole" by the specified user id. * Swithches the user role between "defaultRole" and "visitorRole" by the specified user id.
* *
* @param userId the specified user id * @param userId the specified user id
* @throws ServiceException exception * @throws ServiceException exception
...@@ -248,17 +251,18 @@ public class UserMgmtService { ...@@ -248,17 +251,18 @@ public class UserMgmtService {
/** /**
* Adds a user with the specified request json object. * Adds a user with the specified request json object.
* *
* @param requestJSONObject the specified request json object, for example, * @param requestJSONObject the specified request json object, for example, <pre>
* <pre>
* { * {
* "userName": "", * "userName": "",
* "userEmail": "", * "userEmail": "",
* "userPassword": "", // Unhashed * "userPassword": "", // Unhashed
* "userURL": "", // optional, uses 'servePath' instead if not specified * "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 * </pre>,see {@link User} for more details
*
* @return generated user id * @return generated user id
* @throws ServiceException service exception * @throws ServiceException service exception
*/ */
...@@ -281,15 +285,12 @@ public class UserMgmtService { ...@@ -281,15 +285,12 @@ public class UserMgmtService {
user.put(User.USER_EMAIL, userEmail); user.put(User.USER_EMAIL, userEmail);
final String userName = requestJSONObject.optString(User.USER_NAME); final String userName = requestJSONObject.optString(User.USER_NAME);
user.put(User.USER_NAME, userName); user.put(User.USER_NAME, userName);
final String userPassword = requestJSONObject.optString(User.USER_PASSWORD); final String userPassword = requestJSONObject.optString(User.USER_PASSWORD);
user.put(User.USER_PASSWORD, MD5.hash(userPassword)); user.put(User.USER_PASSWORD, MD5.hash(userPassword));
String userURL = requestJSONObject.optString(User.USER_URL); String userURL = requestJSONObject.optString(User.USER_URL);
if (Strings.isEmptyOrNull(userURL)) { if (Strings.isEmptyOrNull(userURL)) {
userURL = Latkes.getServePath(); userURL = Latkes.getServePath();
} }
...@@ -301,12 +302,17 @@ public class UserMgmtService { ...@@ -301,12 +302,17 @@ public class UserMgmtService {
user.put(User.USER_URL, userURL); user.put(User.USER_URL, userURL);
final String roleName = requestJSONObject.optString(User.USER_ROLE, Role.DEFAULT_ROLE); final String roleName = requestJSONObject.optString(User.USER_ROLE, Role.DEFAULT_ROLE);
user.put(User.USER_ROLE, roleName); user.put(User.USER_ROLE, roleName);
user.put(UserExt.USER_ARTICLE_COUNT, 0); user.put(UserExt.USER_ARTICLE_COUNT, 0);
user.put(UserExt.USER_PUBLISHED_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); userRepository.add(user);
transaction.commit(); transaction.commit();
...@@ -347,7 +353,7 @@ public class UserMgmtService { ...@@ -347,7 +353,7 @@ public class UserMgmtService {
/** /**
* Sets the user repository with the specified user repository. * Sets the user repository with the specified user repository.
* *
* @param userRepository the specified user repository * @param userRepository the specified user repository
*/ */
public void setUserRepository(final UserRepository userRepository) { public void setUserRepository(final UserRepository userRepository) {
...@@ -356,7 +362,7 @@ public class UserMgmtService { ...@@ -356,7 +362,7 @@ public class UserMgmtService {
/** /**
* Sets the language service with the specified language service. * Sets the language service with the specified language service.
* *
* @param langPropsService the specified language service * @param langPropsService the specified language service
*/ */
public void setLangPropsService(final LangPropsService langPropsService) { public void setLangPropsService(final LangPropsService langPropsService) {
......
...@@ -16,12 +16,13 @@ ...@@ -16,12 +16,13 @@
# #
# Description: Solo language configurations(en_US). # 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: Liang Ding
# Author: Liyuan Li # Author: Liyuan Li
# Author: Dongxu Wang # Author: Dongxu Wang
# #
userAvatar1Label=Avatar:
uploadFileLabel=Upload <a href="http://hacpai.com/article/1442418791213" target="_blank">(?)</a> uploadFileLabel=Upload <a href="http://hacpai.com/article/1442418791213" target="_blank">(?)</a>
accessKey1Label=Access Key: accessKey1Label=Access Key:
secretKey1Label=Secret Key: secretKey1Label=Secret Key:
......
...@@ -16,12 +16,13 @@ ...@@ -16,12 +16,13 @@
# #
# Description: Solo default language configurations(zh_CN). # 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: Liang Ding
# Author: Liyuan Li # Author: Liyuan Li
# Author: Dongxu Wang # Author: Dongxu Wang
# #
userAvatar1Label=\u5934\u50cf\uff1a
uploadFileLabel=\u6587\u4ef6\u4e0a\u4f20 <a href="http://hacpai.com/article/1442418791213" target="_blank">(?)</a> uploadFileLabel=\u6587\u4ef6\u4e0a\u4f20 <a href="http://hacpai.com/article/1442418791213" target="_blank">(?)</a>
accessKey1Label=Access Key\uff1a accessKey1Label=Access Key\uff1a
secretKey1Label=Secret Key\uff1a secretKey1Label=Secret Key\uff1a
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
# #
# Description: B3log Latke configurations. Configures the section "Server" carefully. # 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 # Author: Liang Ding
# #
...@@ -41,8 +41,8 @@ scanPath=org.b3log.solo ...@@ -41,8 +41,8 @@ scanPath=org.b3log.solo
runtimeEnv=LOCAL runtimeEnv=LOCAL
#### Runtime Mode #### #### Runtime Mode ####
runtimeMode=DEVELOPMENT
#runtimeMode=DEVELOPMENT #runtimeMode=DEVELOPMENT
runtimeMode=PRODUCTION
#### Cache Implementation #### #### Cache Implementation ####
# Note: If the runtime environment is LOCAL, the cache will be 'LOCAL' always # 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.", "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"], "authors": ["Liang Ding"],
"since": "0.4.0", "since": "0.4.0",
"repositories": [ "repositories": [
...@@ -553,6 +553,11 @@ ...@@ -553,6 +553,11 @@
{ {
"name": "userPublishedArticleCount", "name": "userPublishedArticleCount",
"type": "int" "type": "int"
},
{
"name": "userAvatar",
"type": "String",
"length": 255
} }
] ]
}, },
......
...@@ -42,6 +42,14 @@ ...@@ -42,6 +42,14 @@
<input id="userPassword" type="password"/> <input id="userPassword" type="password"/>
</td> </td>
</tr> </tr>
<tr>
<th>
<label for="userAvatar">${userAvatar1Label}</label>
</th>
<td>
<input id="userAvatar" type="text"/>
</td>
</tr>
<tr> <tr>
<td colspan="2" align="right"> <td colspan="2" align="right">
<button onclick="admin.userList.add();">${saveLabel}</button> <button onclick="admin.userList.add();">${saveLabel}</button>
...@@ -91,6 +99,14 @@ ...@@ -91,6 +99,14 @@
<input id="userPasswordUpdate" type="password"/> <input id="userPasswordUpdate" type="password"/>
</td> </td>
</tr> </tr>
<tr>
<th>
<label for="userAvatarUpdate">${userAvatar1Label}</label>
</th>
<td>
<input id="userAvatarUpdate" type="text"/>
</td>
</tr>
<tr> <tr>
<td colspan="2" align="right"> <td colspan="2" align="right">
<button onclick="admin.userList.update();">${updateLabel}</button> <button onclick="admin.userList.update();">${updateLabel}</button>
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a> * @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @author <a href="http://88250.b3log.org">Liang Ding</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 相关操作 */ /* user-list 相关操作 */
...@@ -59,7 +59,7 @@ admin.userList = { ...@@ -59,7 +59,7 @@ admin.userList = {
$("#userUpdate").dialog({ $("#userUpdate").dialog({
width: 700, width: 700,
height: 230, height: 250,
"modal": true, "modal": true,
"hideFooter": true "hideFooter": true
}); });
...@@ -136,7 +136,8 @@ admin.userList = { ...@@ -136,7 +136,8 @@ admin.userList = {
"userName": $("#userName").val(), "userName": $("#userName").val(),
"userEmail": $("#userEmail").val(), "userEmail": $("#userEmail").val(),
"userURL": $("#userURL").val(), "userURL": $("#userURL").val(),
"userPassword": $("#userPassword").val() "userPassword": $("#userPassword").val(),
"userAvatar": $("#userAvatar").val()
}; };
$.ajax({ $.ajax({
...@@ -155,6 +156,7 @@ admin.userList = { ...@@ -155,6 +156,7 @@ admin.userList = {
$("#userEmail").val(""); $("#userEmail").val("");
$("#userURL").val(""); $("#userURL").val("");
$("#userPassword").val(""); $("#userPassword").val("");
$("#userAvatar").val("");
if (admin.userList.pageInfo.currentCount === Label.PAGE_SIZE && if (admin.userList.pageInfo.currentCount === Label.PAGE_SIZE &&
admin.userList.pageInfo.currentPage === admin.userList.pageInfo.pageCount) { admin.userList.pageInfo.currentPage === admin.userList.pageInfo.pageCount) {
admin.userList.pageInfo.pageCount++; admin.userList.pageInfo.pageCount++;
...@@ -205,6 +207,7 @@ admin.userList = { ...@@ -205,6 +207,7 @@ admin.userList = {
$("#userURLUpdate").val(result.user.userURL); $("#userURLUpdate").val(result.user.userURL);
$("#userPasswordUpdate").val(result.user.userPassword); $("#userPasswordUpdate").val(result.user.userPassword);
$("#userAvatarUpdate").val(result.user.userAvatar);
$("#loadMsg").text(""); $("#loadMsg").text("");
} }
...@@ -225,7 +228,8 @@ admin.userList = { ...@@ -225,7 +228,8 @@ admin.userList = {
"userEmail": $("#userEmailUpdate").val(), "userEmail": $("#userEmailUpdate").val(),
"userURL": $("#userURLUpdate").val(), "userURL": $("#userURLUpdate").val(),
"userRole": userInfo.userRole, "userRole": userInfo.userRole,
"userPassword": $("#userPasswordUpdate").val() "userPassword": $("#userPasswordUpdate").val(),
"userAvatar": $("#userAvatarUpdate").val()
}; };
$.ajax({ $.ajax({
......
...@@ -34,7 +34,7 @@ import org.testng.annotations.Test; ...@@ -34,7 +34,7 @@ import org.testng.annotations.Test;
* {@link UserRepositoryImpl} test case. * {@link UserRepositoryImpl} test case.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @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") @Test(suiteName = "repository")
public final class UserRepositoryImplTestCase extends AbstractTestCase { public final class UserRepositoryImplTestCase extends AbstractTestCase {
...@@ -56,6 +56,7 @@ 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(User.USER_ROLE, Role.DEFAULT_ROLE);
another.put(UserExt.USER_ARTICLE_COUNT, 0); another.put(UserExt.USER_ARTICLE_COUNT, 0);
another.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0); another.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0);
another.put(UserExt.USER_AVATAR, "");
Transaction transaction = userRepository.beginTransaction(); Transaction transaction = userRepository.beginTransaction();
userRepository.add(another); userRepository.add(another);
...@@ -71,6 +72,7 @@ public final class UserRepositoryImplTestCase extends AbstractTestCase { ...@@ -71,6 +72,7 @@ public final class UserRepositoryImplTestCase extends AbstractTestCase {
admin.put(User.USER_ROLE, Role.ADMIN_ROLE); admin.put(User.USER_ROLE, Role.ADMIN_ROLE);
admin.put(UserExt.USER_ARTICLE_COUNT, 0); admin.put(UserExt.USER_ARTICLE_COUNT, 0);
admin.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0); admin.put(UserExt.USER_PUBLISHED_ARTICLE_COUNT, 0);
admin.put(UserExt.USER_AVATAR, "");
transaction = userRepository.beginTransaction(); transaction = userRepository.beginTransaction();
userRepository.add(admin); 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