Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo-1
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
solo-1
Commits
0c3f2b69
Commit
0c3f2b69
authored
May 25, 2017
by
Liang Ding
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'refs/remotes/origin/2.1.0-dev'
parents
b7c19cf0
e149ec24
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
70 deletions
+74
-70
src/main/java/org/b3log/solo/model/UserExt.java
src/main/java/org/b3log/solo/model/UserExt.java
+49
-4
src/main/java/org/b3log/solo/processor/InitProcessor.java
src/main/java/org/b3log/solo/processor/InitProcessor.java
+14
-60
src/main/java/org/b3log/solo/service/UserMgmtService.java
src/main/java/org/b3log/solo/service/UserMgmtService.java
+7
-4
src/main/resources/lang_en_US.properties
src/main/resources/lang_en_US.properties
+2
-1
src/main/resources/lang_zh_CN.properties
src/main/resources/lang_zh_CN.properties
+2
-1
No files found.
src/main/java/org/b3log/solo/model/UserExt.java
View file @
0c3f2b69
...
...
@@ -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"
);
}
}
src/main/java/org/b3log/solo/processor/InitProcessor.java
View file @
0c3f2b69
...
...
@@ -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.1
0, Aug 9, 2016
* @version 1.2.0.1
1, 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"
);
}
}
src/main/java/org/b3log/solo/service/UserMgmtService.java
View file @
0c3f2b69
...
...
@@ -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
);
...
...
src/main/resources/lang_en_US.properties
View file @
0c3f2b69
...
...
@@ -16,12 +16,13 @@
#
# Description: Solo language configurations(en_US).
# Version: 2.1
4.0.0, May 21
, 2017
# Version: 2.1
5.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
...
...
src/main/resources/lang_zh_CN.properties
View file @
0c3f2b69
...
...
@@ -16,12 +16,13 @@
#
# Description: Solo default language configurations(zh_CN).
# Version: 2.1
4.0.0, May 21
, 2017
# Version: 2.1
5.0.0, May 25
, 2017
# Author: Liang Ding
# Author: Liyuan Li
# Author: Dongxu Wang
#
userNameInvalidLabel
=
\u7528\u6237\u
540D
\u
53EA
\u
80FD
\u
662F
\u
5B57
\u
6BCD
\u6216\u6570\u
5B57
\u
FF01
sponsorLabel
=
\u6210\u
4E3A
\u
8D5E
\u
52A9
\u8005
addBoldLabel
=
\u
6DFB
\u
52A0
\u
7C97
\u
4F53
addItalicLabel
=
\u
6DFB
\u
52A0
\u
659C
\u
4F53
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment