Commit 0c3f2b69 authored by Liang Ding's avatar Liang Ding

Merge remote-tracking branch 'refs/remotes/origin/2.1.0-dev'

parents b7c19cf0 e149ec24
......@@ -20,9 +20,9 @@ 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.1.0.0, Oct 17, 2015
* @since 0.4.1
* @version 1.2.0.0, May 25, 2017
* @see org.b3log.latke.model.User
* @since 0.4.1
*/
public final class UserExt {
......@@ -35,14 +35,59 @@ public final class UserExt {
* Key of user article count.
*/
public static final String USER_PUBLISHED_ARTICLE_COUNT = "userPublishedArticleCount";
/**
* Key of user avatar.
*/
public static final String USER_AVATAR = "userAvatar";
/**
* Max user name length.
*/
public static final int MAX_USER_NAME_LENGTH = 20;
/**
* Min user name length.
*/
public static final int MIN_USER_NAME_LENGTH = 1;
/**
* Private constructor.
*/
private UserExt() {}
private UserExt() {
}
/**
* Checks whether the specified name is invalid.
* <p>
* A valid user name:
* <ul>
* <li>length [1, 20]</li>
* <li>content {a-z, A-Z, 0-9}</li>
* <li>Not contains "admin"/"Admin"</li>
* </ul>
* </p>
*
* @param name the specified name
* @return {@code true} if it is invalid, returns {@code false} otherwise
*/
public static boolean invalidUserName(final String name) {
final int length = name.length();
if (length < MIN_USER_NAME_LENGTH || length > MAX_USER_NAME_LENGTH) {
return true;
}
char c;
for (int i = 0; i < length; i++) {
c = name.charAt(i);
if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || '0' <= c && c <= '9') {
continue;
}
return true;
}
return name.contains("admin") || name.contains("Admin");
}
}
......@@ -53,7 +53,7 @@ import java.util.Map;
* Solo initialization service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.2.0.10, Aug 9, 2016
* @version 1.2.0.11, May 25, 2017
* @since 0.4.0
*/
@RequestProcessor
......@@ -62,7 +62,7 @@ public class InitProcessor {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(InitProcessor.class.getName());
private static final Logger LOGGER = Logger.getLogger(InitProcessor.class);
/**
* Initialization service.
......@@ -82,21 +82,11 @@ public class InitProcessor {
@Inject
private LangPropsService langPropsService;
/**
* Max user name length.
*/
public static final int MAX_USER_NAME_LENGTH = 20;
/**
* Min user name length.
*/
public static final int MIN_USER_NAME_LENGTH = 1;
/**
* Shows initialization page.
*
* @param context the specified http request context
* @param request the specified http servlet request
* @param context the specified http request context
* @param request the specified http servlet request
* @param response the specified http servlet response
* @throws Exception exception
*/
......@@ -131,21 +121,20 @@ public class InitProcessor {
/**
* Initializes Solo.
*
* @param context the specified http request context
* @param request the specified http servlet request, for example, <pre>
* {
* "userName": "",
* "userEmail": "",
* "userPassword": ""
* }
* </pre>
*
* @param context the specified http request context
* @param request the specified http servlet request, for example, <pre>
* {
* "userName": "",
* "userEmail": "",
* "userPassword": ""
* }
* </pre>
* @param response the specified http servlet response
* @throws Exception exception
*/
@RequestProcessing(value = "/init", method = HTTPRequestMethod.POST)
public void initSolo(final HTTPRequestContext context, final HttpServletRequest request,
final HttpServletResponse response) throws Exception {
final HttpServletResponse response) throws Exception {
if (initService.isInited()) {
response.sendRedirect("/");
......@@ -172,7 +161,7 @@ public class InitProcessor {
return;
}
if (invalidUserName(userName)) {
if (UserExt.invalidUserName(userName)) {
ret.put(Keys.MSG, "Init failed, please check your username (length [1, 20], content {a-z, A-Z, 0-9}, do not contain 'admin' for security reason]");
return;
......@@ -200,39 +189,4 @@ public class InitProcessor {
ret.put(Keys.MSG, e.getMessage());
}
}
/**
* Checks whether the specified name is invalid.
*
* <p>
* A valid user name:
* <ul>
* <li>length [1, 20]</li>
* <li>content {a-z, A-Z, 0-9}</li>
* <li>Not contains "admin"/"Admin"</li>
* </ul>
* </p>
*
* @param name the specified name
* @return {@code true} if it is invalid, returns {@code false} otherwise
*/
public static boolean invalidUserName(final String name) {
final int length = name.length();
if (length < MIN_USER_NAME_LENGTH || length > MAX_USER_NAME_LENGTH) {
return true;
}
char c;
for (int i = 0; i < length; i++) {
c = name.charAt(i);
if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || '0' <= c && c <= '9') {
continue;
}
return true;
}
return name.contains("admin") || name.contains("Admin");
}
}
......@@ -47,7 +47,7 @@ import javax.servlet.http.HttpServletResponse;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:385321165@qq.com">DASHU</a>
* @version 1.1.0.7, May 6, 2017
* @version 1.1.0.8, May 25, 2017
* @since 0.4.0
*/
@Service
......@@ -162,13 +162,16 @@ public class UserMgmtService {
throw new ServiceException(langPropsService.get("duplicatedEmailLabel"));
}
oldUser.put(User.USER_EMAIL, userNewEmail);
// Update
final String userName = requestJSONObject.optString(User.USER_NAME);
final String userPassword = requestJSONObject.optString(User.USER_PASSWORD);
oldUser.put(User.USER_EMAIL, userNewEmail);
if (UserExt.invalidUserName(userName)) {
throw new ServiceException(langPropsService.get("userNameInvalidLabel"));
}
oldUser.put(User.USER_NAME, userName);
final String userPassword = requestJSONObject.optString(User.USER_PASSWORD);
final boolean maybeHashed = HASHED_PASSWORD_LENGTH == userPassword.length();
final String newHashedPassword = MD5.hash(userPassword);
final String oldHashedPassword = oldUser.optString(User.USER_PASSWORD);
......
......@@ -16,12 +16,13 @@
#
# Description: Solo language configurations(en_US).
# Version: 2.14.0.0, May 21, 2017
# Version: 2.15.0.0, May 25, 2017
# Author: Liang Ding
# Author: Liyuan Li
# Author: Dongxu Wang
#
userNameInvalidLabel=Username only allow alphabet or number!
sponsorLabel=Become a Sponsor
addBoldLabel=Add bold text
addItalicLabel=Add italic text
......
......@@ -16,12 +16,13 @@
#
# Description: Solo default language configurations(zh_CN).
# Version: 2.14.0.0, May 21, 2017
# Version: 2.15.0.0, May 25, 2017
# Author: Liang Ding
# Author: Liyuan Li
# Author: Dongxu Wang
#
userNameInvalidLabel=\u7528\u6237\u540D\u53EA\u80FD\u662F\u5B57\u6BCD\u6216\u6570\u5B57\uFF01
sponsorLabel=\u6210\u4E3A\u8D5E\u52A9\u8005
addBoldLabel=\u6DFB\u52A0\u7C97\u4F53
addItalicLabel=\u6DFB\u52A0\u659C\u4F53
......
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