Skip to content

Commit 0c3f2b6

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/2.1.0-dev'
2 parents b7c19cf + e149ec2 commit 0c3f2b6

File tree

5 files changed

+74
-70
lines changed

5 files changed

+74
-70
lines changed

src/main/java/org/b3log/solo/model/UserExt.java

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
* This class defines ext of user model relevant keys.
2121
*
2222
* @author <a href="http://88250.b3log.org">Liang Ding</a>
23-
* @version 1.1.0.0, Oct 17, 2015
24-
* @since 0.4.1
23+
* @version 1.2.0.0, May 25, 2017
2524
* @see org.b3log.latke.model.User
25+
* @since 0.4.1
2626
*/
2727
public final class UserExt {
2828

@@ -35,14 +35,59 @@ public final class UserExt {
3535
* Key of user article count.
3636
*/
3737
public static final String USER_PUBLISHED_ARTICLE_COUNT = "userPublishedArticleCount";
38-
38+
3939
/**
4040
* Key of user avatar.
4141
*/
4242
public static final String USER_AVATAR = "userAvatar";
4343

44+
/**
45+
* Max user name length.
46+
*/
47+
public static final int MAX_USER_NAME_LENGTH = 20;
48+
49+
/**
50+
* Min user name length.
51+
*/
52+
public static final int MIN_USER_NAME_LENGTH = 1;
53+
4454
/**
4555
* Private constructor.
4656
*/
47-
private UserExt() {}
57+
private UserExt() {
58+
}
59+
60+
/**
61+
* Checks whether the specified name is invalid.
62+
* <p>
63+
* A valid user name:
64+
* <ul>
65+
* <li>length [1, 20]</li>
66+
* <li>content {a-z, A-Z, 0-9}</li>
67+
* <li>Not contains "admin"/"Admin"</li>
68+
* </ul>
69+
* </p>
70+
*
71+
* @param name the specified name
72+
* @return {@code true} if it is invalid, returns {@code false} otherwise
73+
*/
74+
public static boolean invalidUserName(final String name) {
75+
final int length = name.length();
76+
if (length < MIN_USER_NAME_LENGTH || length > MAX_USER_NAME_LENGTH) {
77+
return true;
78+
}
79+
80+
char c;
81+
for (int i = 0; i < length; i++) {
82+
c = name.charAt(i);
83+
84+
if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || '0' <= c && c <= '9') {
85+
continue;
86+
}
87+
88+
return true;
89+
}
90+
91+
return name.contains("admin") || name.contains("Admin");
92+
}
4893
}

src/main/java/org/b3log/solo/processor/InitProcessor.java

Lines changed: 14 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
* Solo initialization service.
5454
*
5555
* @author <a href="http://88250.b3log.org">Liang Ding</a>
56-
* @version 1.2.0.10, Aug 9, 2016
56+
* @version 1.2.0.11, May 25, 2017
5757
* @since 0.4.0
5858
*/
5959
@RequestProcessor
@@ -62,7 +62,7 @@ public class InitProcessor {
6262
/**
6363
* Logger.
6464
*/
65-
private static final Logger LOGGER = Logger.getLogger(InitProcessor.class.getName());
65+
private static final Logger LOGGER = Logger.getLogger(InitProcessor.class);
6666

6767
/**
6868
* Initialization service.
@@ -82,21 +82,11 @@ public class InitProcessor {
8282
@Inject
8383
private LangPropsService langPropsService;
8484

85-
/**
86-
* Max user name length.
87-
*/
88-
public static final int MAX_USER_NAME_LENGTH = 20;
89-
90-
/**
91-
* Min user name length.
92-
*/
93-
public static final int MIN_USER_NAME_LENGTH = 1;
94-
9585
/**
9686
* Shows initialization page.
9787
*
98-
* @param context the specified http request context
99-
* @param request the specified http servlet request
88+
* @param context the specified http request context
89+
* @param request the specified http servlet request
10090
* @param response the specified http servlet response
10191
* @throws Exception exception
10292
*/
@@ -131,21 +121,20 @@ public void showInit(final HTTPRequestContext context, final HttpServletRequest
131121
/**
132122
* Initializes Solo.
133123
*
134-
* @param context the specified http request context
135-
* @param request the specified http servlet request, for example, <pre>
136-
* {
137-
* "userName": "",
138-
* "userEmail": "",
139-
* "userPassword": ""
140-
* }
141-
* </pre>
142-
*
124+
* @param context the specified http request context
125+
* @param request the specified http servlet request, for example, <pre>
126+
* {
127+
* "userName": "",
128+
* "userEmail": "",
129+
* "userPassword": ""
130+
* }
131+
* </pre>
143132
* @param response the specified http servlet response
144133
* @throws Exception exception
145134
*/
146135
@RequestProcessing(value = "/init", method = HTTPRequestMethod.POST)
147136
public void initSolo(final HTTPRequestContext context, final HttpServletRequest request,
148-
final HttpServletResponse response) throws Exception {
137+
final HttpServletResponse response) throws Exception {
149138
if (initService.isInited()) {
150139
response.sendRedirect("/");
151140

@@ -172,7 +161,7 @@ public void initSolo(final HTTPRequestContext context, final HttpServletRequest
172161
return;
173162
}
174163

175-
if (invalidUserName(userName)) {
164+
if (UserExt.invalidUserName(userName)) {
176165
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]");
177166

178167
return;
@@ -200,39 +189,4 @@ public void initSolo(final HTTPRequestContext context, final HttpServletRequest
200189
ret.put(Keys.MSG, e.getMessage());
201190
}
202191
}
203-
204-
/**
205-
* Checks whether the specified name is invalid.
206-
*
207-
* <p>
208-
* A valid user name:
209-
* <ul>
210-
* <li>length [1, 20]</li>
211-
* <li>content {a-z, A-Z, 0-9}</li>
212-
* <li>Not contains "admin"/"Admin"</li>
213-
* </ul>
214-
* </p>
215-
*
216-
* @param name the specified name
217-
* @return {@code true} if it is invalid, returns {@code false} otherwise
218-
*/
219-
public static boolean invalidUserName(final String name) {
220-
final int length = name.length();
221-
if (length < MIN_USER_NAME_LENGTH || length > MAX_USER_NAME_LENGTH) {
222-
return true;
223-
}
224-
225-
char c;
226-
for (int i = 0; i < length; i++) {
227-
c = name.charAt(i);
228-
229-
if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || '0' <= c && c <= '9') {
230-
continue;
231-
}
232-
233-
return true;
234-
}
235-
236-
return name.contains("admin") || name.contains("Admin");
237-
}
238192
}

src/main/java/org/b3log/solo/service/UserMgmtService.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
*
4848
* @author <a href="http://88250.b3log.org">Liang Ding</a>
4949
* @author <a href="mailto:385321165@qq.com">DASHU</a>
50-
* @version 1.1.0.7, May 6, 2017
50+
* @version 1.1.0.8, May 25, 2017
5151
* @since 0.4.0
5252
*/
5353
@Service
@@ -162,13 +162,16 @@ public void updateUser(final JSONObject requestJSONObject) throws ServiceExcepti
162162
throw new ServiceException(langPropsService.get("duplicatedEmailLabel"));
163163
}
164164

165+
oldUser.put(User.USER_EMAIL, userNewEmail);
166+
165167
// Update
166168
final String userName = requestJSONObject.optString(User.USER_NAME);
167-
final String userPassword = requestJSONObject.optString(User.USER_PASSWORD);
168-
169-
oldUser.put(User.USER_EMAIL, userNewEmail);
169+
if (UserExt.invalidUserName(userName)) {
170+
throw new ServiceException(langPropsService.get("userNameInvalidLabel"));
171+
}
170172
oldUser.put(User.USER_NAME, userName);
171173

174+
final String userPassword = requestJSONObject.optString(User.USER_PASSWORD);
172175
final boolean maybeHashed = HASHED_PASSWORD_LENGTH == userPassword.length();
173176
final String newHashedPassword = MD5.hash(userPassword);
174177
final String oldHashedPassword = oldUser.optString(User.USER_PASSWORD);

src/main/resources/lang_en_US.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616

1717
#
1818
# Description: Solo language configurations(en_US).
19-
# Version: 2.14.0.0, May 21, 2017
19+
# Version: 2.15.0.0, May 25, 2017
2020
# Author: Liang Ding
2121
# Author: Liyuan Li
2222
# Author: Dongxu Wang
2323
#
2424

25+
userNameInvalidLabel=Username only allow alphabet or number!
2526
sponsorLabel=Become a Sponsor
2627
addBoldLabel=Add bold text
2728
addItalicLabel=Add italic text

src/main/resources/lang_zh_CN.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616

1717
#
1818
# Description: Solo default language configurations(zh_CN).
19-
# Version: 2.14.0.0, May 21, 2017
19+
# Version: 2.15.0.0, May 25, 2017
2020
# Author: Liang Ding
2121
# Author: Liyuan Li
2222
# Author: Dongxu Wang
2323
#
2424

25+
userNameInvalidLabel=\u7528\u6237\u540D\u53EA\u80FD\u662F\u5B57\u6BCD\u6216\u6570\u5B57\uFF01
2526
sponsorLabel=\u6210\u4E3A\u8D5E\u52A9\u8005
2627
addBoldLabel=\u6DFB\u52A0\u7C97\u4F53
2728
addItalicLabel=\u6DFB\u52A0\u659C\u4F53

0 commit comments

Comments
 (0)