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
dbf70a36
Commit
dbf70a36
authored
Aug 11, 2017
by
Vanessa
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/2.3.0-dev' into 2.3.0-dev
parents
6f841758
89e465d1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
13 deletions
+24
-13
pom.xml
pom.xml
+1
-1
src/main/java/org/b3log/solo/service/UserMgmtService.java
src/main/java/org/b3log/solo/service/UserMgmtService.java
+18
-11
src/main/resources/latke.properties
src/main/resources/latke.properties
+5
-1
No files found.
pom.xml
View file @
dbf70a36
...
...
@@ -75,7 +75,7 @@
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<org.b3log.latke.version>
2.3.1
3
</org.b3log.latke.version>
<org.b3log.latke.version>
2.3.1
4
</org.b3log.latke.version>
<servlet.version>
3.1.0
</servlet.version>
<slf4j.version>
1.7.5
</slf4j.version>
...
...
src/main/java/org/b3log/solo/service/UserMgmtService.java
View file @
dbf70a36
...
...
@@ -30,6 +30,7 @@ import org.b3log.latke.repository.Transaction;
import
org.b3log.latke.service.LangPropsService
;
import
org.b3log.latke.service.ServiceException
;
import
org.b3log.latke.service.annotation.Service
;
import
org.b3log.latke.util.Crypts
;
import
org.b3log.latke.util.MD5
;
import
org.b3log.latke.util.Sessions
;
import
org.b3log.latke.util.Strings
;
...
...
@@ -47,7 +48,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.
8, May 25
, 2017
* @version 1.1.0.
9, Aug 11
, 2017
* @since 0.4.0
*/
@Service
...
...
@@ -83,7 +84,6 @@ public class UserMgmtService {
*/
public
void
tryLogInWithCookie
(
final
HttpServletRequest
request
,
final
HttpServletResponse
response
)
{
final
Cookie
[]
cookies
=
request
.
getCookies
();
if
(
null
==
cookies
||
0
==
cookies
.
length
)
{
return
;
}
...
...
@@ -91,38 +91,45 @@ public class UserMgmtService {
try
{
for
(
int
i
=
0
;
i
<
cookies
.
length
;
i
++)
{
final
Cookie
cookie
=
cookies
[
i
];
if
(!
"b3log-latke"
.
equals
(
cookie
.
getName
()))
{
if
(!
Sessions
.
COOKIE_NAME
.
equals
(
cookie
.
getName
()))
{
continue
;
}
final
JSONObject
cookieJSONObject
=
new
JSONObject
(
cookie
.
getValue
());
final
String
value
=
Crypts
.
decryptByAES
(
cookie
.
getValue
(),
Sessions
.
COOKIE_SECRET
);
final
JSONObject
cookieJSONObject
=
new
JSONObject
(
value
);
final
String
user
Email
=
cookieJSONObject
.
optString
(
User
.
USER_EMAIL
);
if
(
Strings
.
isEmptyOrNull
(
user
Email
))
{
final
String
user
Id
=
cookieJSONObject
.
optString
(
Keys
.
OBJECT_ID
);
if
(
Strings
.
isEmptyOrNull
(
user
Id
))
{
break
;
}
final
LatkeBeanManager
beanManager
=
Lifecycle
.
getBeanManager
();
final
UserQueryService
userQueryService
=
beanManager
.
getReference
(
UserQueryService
.
class
);
final
JSONObject
user
=
userQueryService
.
getUserByEmail
(
userEmail
.
toLowerCase
().
trim
());
final
JSONObject
userResult
=
userQueryService
.
getUser
(
userId
);
if
(
null
==
userResult
)
{
break
;
}
final
JSONObject
user
=
userResult
.
getJSONObject
(
User
.
USER
);
if
(
null
==
user
)
{
break
;
}
final
String
userPassword
=
user
.
optString
(
User
.
USER_PASSWORD
);
final
String
hashPassword
=
cookieJSONObject
.
optString
(
User
.
USER_PASSWORD
);
final
String
token
=
cookieJSONObject
.
optString
(
Keys
.
TOKEN
);
final
String
hashPassword
=
StringUtils
.
substringBeforeLast
(
token
,
":"
);
if
(
userPassword
.
equals
(
hashPassword
))
{
Sessions
.
login
(
request
,
response
,
user
);
LOGGER
.
log
(
Level
.
DEBUG
,
"Logged in with cookie[email={0}]"
,
userEmail
);
LOGGER
.
log
(
Level
.
DEBUG
,
"Logged in with cookie [email={0}]"
,
user
.
optString
(
User
.
USER_EMAIL
));
}
}
}
catch
(
final
Exception
e
)
{
LOGGER
.
log
(
Level
.
TRACE
,
"Parses cookie failed, clears the cookie [name=
b3log-latke
]"
);
LOGGER
.
log
(
Level
.
TRACE
,
"Parses cookie failed, clears the cookie [name=
"
+
Sessions
.
COOKIE_NAME
+
"
]"
);
final
Cookie
cookie
=
new
Cookie
(
"b3log-latke"
,
null
);
final
Cookie
cookie
=
new
Cookie
(
Sessions
.
COOKIE_NAME
,
null
);
cookie
.
setMaxAge
(
0
);
cookie
.
setPath
(
"/"
);
...
...
src/main/resources/latke.properties
View file @
dbf70a36
...
...
@@ -16,7 +16,7 @@
#
# Description: B3log Latke configurations. Configures the section "Server" carefully.
# Version: 1.
4.3.9, Dec 23, 2015
# Version: 1.
5.3.9, Aug 11, 2017
# Author: Liang Ding
#
...
...
@@ -28,6 +28,10 @@ serverHost=localhost
# Browser visit port, 80 as usual, THIS IS NOT SERVER LISTEN PORT!
serverPort
=
8080
#### Cookie ####
cookieName
=
solo
cookieSecret
=
Beyond
#### Runtime Mode ####
runtimeMode
=
DEVELOPMENT
#runtimeMode=PRODUCTION
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