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
6ea880d3
Unverified
Commit
6ea880d3
authored
Sep 21, 2018
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🎨
注册/创建新用户校验
parent
ce3f49a2
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
41 additions
and
35 deletions
+41
-35
src/main/java/org/b3log/solo/model/UserExt.java
src/main/java/org/b3log/solo/model/UserExt.java
+3
-1
src/main/java/org/b3log/solo/processor/console/UserConsole.java
...in/java/org/b3log/solo/processor/console/UserConsole.java
+1
-1
src/main/java/org/b3log/solo/repository/UserRepository.java
src/main/java/org/b3log/solo/repository/UserRepository.java
+8
-9
src/main/java/org/b3log/solo/repository/impl/UserRepositoryImpl.java
...va/org/b3log/solo/repository/impl/UserRepositoryImpl.java
+15
-11
src/main/java/org/b3log/solo/service/UserMgmtService.java
src/main/java/org/b3log/solo/service/UserMgmtService.java
+10
-4
src/main/resources/lang_en_US.properties
src/main/resources/lang_en_US.properties
+2
-3
src/main/resources/lang_zh_CN.properties
src/main/resources/lang_zh_CN.properties
+2
-3
src/test/java/org/b3log/solo/repository/impl/UserRepositoryImplTestCase.java
...3log/solo/repository/impl/UserRepositoryImplTestCase.java
+0
-3
No files found.
src/main/java/org/b3log/solo/model/UserExt.java
View file @
6ea880d3
...
...
@@ -17,6 +17,8 @@
*/
package
org
.
b3log
.
solo
.
model
;
import
org.apache.commons.lang.StringUtils
;
/**
* This class defines ext of user model relevant keys.
*
...
...
@@ -89,6 +91,6 @@ public final class UserExt {
return
true
;
}
return
name
.
contains
(
"admin"
)
||
name
.
contains
(
"A
dmin"
);
return
StringUtils
.
containsIgnoreCase
(
name
,
"a
dmin"
);
}
}
src/main/java/org/b3log/solo/processor/console/UserConsole.java
View file @
6ea880d3
...
...
@@ -180,7 +180,7 @@ public class UserConsole {
return
;
}
// if a normal user or a visitor register a new user, treat
es the new user as a visitor
// if a normal user or a visitor register a new user, treat
s the new user as a visitor
// (visitorRole) who couldn't post article
requestJSONObject
.
put
(
User
.
USER_ROLE
,
Role
.
VISITOR_ROLE
);
}
...
...
src/main/java/org/b3log/solo/repository/UserRepository.java
View file @
6ea880d3
...
...
@@ -25,29 +25,28 @@ import org.json.JSONObject;
* User repository.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.
0.0.4, Nov 8, 2011
* @version 1.
1.0.0, Sep 21, 2018
* @since 0.3.1
*/
public
interface
UserRepository
extends
Repository
{
/**
* Gets a user by the specified
email
.
* Gets a user by the specified
username
.
*
* @param
email the specified email
* @param
userName the specified username
* @return user, returns {@code null} if not found
* @throws RepositoryException repository exception
* @throws RepositoryException repository exception
*/
JSONObject
getBy
Email
(
final
String
email
)
throws
RepositoryException
;
JSONObject
getBy
UserName
(
final
String
userName
)
throws
RepositoryException
;
/**
*
Determine whether the specified email is administrator's
.
*
Gets a user by the specified email
.
*
* @param email the specified email
* @return {@code true} if it is administrator's email, {@code false}
* otherwise
* @return user, returns {@code null} if not found
* @throws RepositoryException repository exception
*/
boolean
isAdmin
Email
(
final
String
email
)
throws
RepositoryException
;
JSONObject
getBy
Email
(
final
String
email
)
throws
RepositoryException
;
/**
* Gets the administrator user.
...
...
src/main/java/org/b3log/solo/repository/impl/UserRepositoryImpl.java
View file @
6ea880d3
...
...
@@ -28,11 +28,13 @@ import org.b3log.solo.repository.UserRepository;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
java.util.List
;
/**
* User repository.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.
9, Aug 27, 2017
* @version 1.1.0.
10, Sep 21, 2018
* @since 0.3.1
*/
@Repository
...
...
@@ -87,6 +89,18 @@ public class UserRepositoryImpl extends AbstractRepository implements UserReposi
}
}
@Override
public
JSONObject
getByUserName
(
final
String
userName
)
throws
RepositoryException
{
final
Query
query
=
new
Query
().
setPageCount
(
1
).
setFilter
(
new
PropertyFilter
(
User
.
USER_NAME
,
FilterOperator
.
EQUAL
,
userName
));
final
List
<
JSONObject
>
users
=
getList
(
query
);
if
(
users
.
isEmpty
())
{
return
null
;
}
return
users
.
get
(
0
);
}
@Override
public
JSONObject
getByEmail
(
final
String
email
)
throws
RepositoryException
{
JSONObject
ret
=
userCache
.
getUserByEmail
(
email
);
...
...
@@ -128,14 +142,4 @@ public class UserRepositoryImpl extends AbstractRepository implements UserReposi
return
ret
;
}
@Override
public
boolean
isAdminEmail
(
final
String
email
)
throws
RepositoryException
{
final
JSONObject
user
=
getByEmail
(
email
);
if
(
null
==
user
)
{
return
false
;
}
return
Role
.
ADMIN_ROLE
.
equals
(
user
.
optString
(
User
.
USER_ROLE
));
}
}
src/main/java/org/b3log/solo/service/UserMgmtService.java
View file @
6ea880d3
...
...
@@ -271,7 +271,7 @@ public class UserMgmtService {
* @return generated user id
* @throws ServiceException service exception
*/
public
String
addUser
(
final
JSONObject
requestJSONObject
)
throws
ServiceException
{
public
synchronized
String
addUser
(
final
JSONObject
requestJSONObject
)
throws
ServiceException
{
final
Transaction
transaction
=
userRepository
.
beginTransaction
();
try
{
...
...
@@ -281,8 +281,7 @@ public class UserMgmtService {
throw
new
ServiceException
(
langPropsService
.
get
(
"mailInvalidLabel"
));
}
final
JSONObject
duplicatedUser
=
userRepository
.
getByEmail
(
userEmail
);
JSONObject
duplicatedUser
=
userRepository
.
getByEmail
(
userEmail
);
if
(
null
!=
duplicatedUser
)
{
if
(
transaction
.
isActive
())
{
transaction
.
rollback
();
...
...
@@ -297,6 +296,14 @@ public class UserMgmtService {
if
(
UserExt
.
invalidUserName
(
userName
))
{
throw
new
ServiceException
(
langPropsService
.
get
(
"userNameInvalidLabel"
));
}
duplicatedUser
=
userRepository
.
getByUserName
(
userName
);
if
(
null
!=
duplicatedUser
)
{
if
(
transaction
.
isActive
())
{
transaction
.
rollback
();
}
throw
new
ServiceException
(
langPropsService
.
get
(
"duplicatedUserNameLabel"
));
}
user
.
put
(
User
.
USER_NAME
,
userName
);
final
String
userPassword
=
requestJSONObject
.
optString
(
User
.
USER_PASSWORD
);
...
...
@@ -326,7 +333,6 @@ public class UserMgmtService {
user
.
put
(
UserExt
.
USER_AVATAR
,
userAvatar
);
userRepository
.
add
(
user
);
transaction
.
commit
();
return
user
.
optString
(
Keys
.
OBJECT_ID
);
...
...
src/main/resources/lang_en_US.properties
View file @
6ea880d3
...
...
@@ -18,7 +18,7 @@
#
# Description: Solo language configurations(en_US).
# Version: 2.2
1.0.2, Aug 27
, 2018
# Version: 2.2
2.0.0, Sep 21
, 2018
# Author: Liang Ding
# Author: Liyuan Li
# Author: Dongxu Wang
...
...
@@ -36,7 +36,6 @@ addItalicLabel=Add italic text
insertQuoteLabel
=
Insert a quote
addBulletedLabel
=
Add a bulleted list
addNumberedListLabel
=
Add a numbered list
addLinkLabel
=
Add a link
undoLabel
=
Undo
redoLabel
=
Redo
fullscreenLabel
=
Fullscreen
...
...
@@ -189,7 +188,6 @@ archiveLabel=Archive
archive1Label
=
archive:
yearLabel
=
monthLabel
=
pageLabel
=
Page
navMgmtLabel
=
Navigation
navLabel
=
Navigation
openMethod1Label
=
Target:
...
...
@@ -401,6 +399,7 @@ make sure the <em>Consumer Secret</em> you typed in and then try again.
duplicatedPermalinkLabel
=
Duplicated permalink!
invalidPermalinkFormatLabel
=
Invalid permalink format!
duplicatedEmailLabel
=
Duplicated email!
duplicatedUserNameLabel
=
Duplicated username!
refreshAndRetryLabel
=
Please refresh and try again!
editorLeaveLabel
=
Content is not null, Do you leave?
editorPostLabel
=
Content is not null, Do you clear?
...
...
src/main/resources/lang_zh_CN.properties
View file @
6ea880d3
...
...
@@ -18,7 +18,7 @@
#
# Description: Solo default language configurations(zh_CN).
# Version: 2.2
1.0.2, Aug 27
, 2018
# Version: 2.2
2.0.0, Sep 21
, 2018
# Author: Liang Ding
# Author: Liyuan Li
# Author: Dongxu Wang
...
...
@@ -36,7 +36,6 @@ addItalicLabel=\u6DFB\u52A0\u659C\u4F53
insertQuoteLabel
=
\u
63D2
\u5165\u
5F15
\u7528
addBulletedLabel
=
\u
6DFB
\u
52A0
\u
65E0
\u
5E8F
\u5217\u8868
addNumberedListLabel
=
\u
6DFB
\u
52A0
\u6709\u
5E8F
\u5217\u8868
addLink1Label
=
\u
6DFB
\u
52A0
\u
94FE
\u
63A5
undoLabel
=
\u
64A4
\u9500
redoLabel
=
\u6062\u
590D
helpLabel
=
\u
5E2E
\u
52A9
...
...
@@ -189,7 +188,6 @@ archiveLabel=\u5B58\u6863
archive1Label
=
\u
5B58
\u6863\u
FF1A
yearLabel
=
\u
5E74
monthLabel
=
\u6708
pageLabel
=
\u9875\u9762
navMgmtLabel
=
\u
5BFC
\u
822A
\u
7BA1
\u7406
navLabel
=
\u
5BFC
\u
822A
openMethod1Label
=
\u9875\u9762\u6253\u
5F00
\u
65B9
\u
5F0F
\u
FF1A
...
...
@@ -399,6 +397,7 @@ noAuthorizationURLLabel=\u4ECE Google \u83B7\u53D6\u6388\u6743\u5730\u5740\u5931
duplicatedPermalinkLabel
=
\u
94FE
\u
63A5
\u
91CD
\u
590D
\u
FF01
invalidPermalinkFormatLabel
=
\u
975E
\u
6CD5
\u7684\u
94FE
\u
63A5
\u
683C
\u
5F0F
\u
FF01
duplicatedEmailLabel
=
\u
90AE
\u
4EF6
\u5730\u5740\u
91CD
\u
590D
\u
FF01
duplicatedUserNameLabel
=
\u7528\u6237\u
540D
\u
91CD
\u
590D
\u
FF01
refreshAndRetryLabel
=
\u
8BF7
\u5237\u
65B0
\u
91CD
\u
8BD5
\u
FF01
editorLeaveLabel
=
\u
7F16
\u
8F91
\u5668\u
4E2D
\u
8FD8
\u6709\u5185\u
5BB9
\u
FF0C
\u
662F
\u5426\u
79BB
\u
5F00
\u
FF1F
editorPostLabel
=
\u
7F16
\u
8F91
\u5668\u
4E2D
\u
8FD8
\u6709\u5185\u
5BB9
\u
FF0C
\u
662F
\u5426\u
6E05
\u
7A7A
\u
FF1F
...
...
src/test/java/org/b3log/solo/repository/impl/UserRepositoryImplTestCase.java
View file @
6ea880d3
...
...
@@ -80,9 +80,6 @@ public final class UserRepositoryImplTestCase extends AbstractTestCase {
userRepository
.
add
(
admin
);
transaction
.
commit
();
Assert
.
assertTrue
(
userRepository
.
isAdminEmail
(
"test@gmail.com"
));
Assert
.
assertFalse
(
userRepository
.
isAdminEmail
(
"notFound@gmail.com"
));
admin
=
userRepository
.
getAdmin
();
Assert
.
assertNotNull
(
admin
);
...
...
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