Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
sentinel
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
曲欣亮
sentinel
Commits
98d89338
Commit
98d89338
authored
Nov 22, 2018
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
操作日志
parent
0c33d873
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
84 additions
and
71 deletions
+84
-71
TokenService.java
src/main/java/com/egolm/film/api/TokenService.java
+4
-0
AdminLoginController.java
...n/java/com/egolm/film/api/admin/AdminLoginController.java
+6
-8
AdminTokenService.java
...a/com/egolm/film/api/admin/service/AdminTokenService.java
+1
-0
AdminTokenServiceImpl.java
...lm/film/api/admin/service/impl/AdminTokenServiceImpl.java
+19
-0
MemberLoginController.java
...java/com/egolm/film/api/member/MemberLoginController.java
+4
-2
MemberTokenService.java
...com/egolm/film/api/member/service/MemberTokenService.java
+1
-0
MemberTokenServiceImpl.java
.../film/api/member/service/impl/MemberTokenServiceImpl.java
+23
-0
UserTokenService.java
...ava/com/egolm/film/api/user/service/UserTokenService.java
+1
-0
UserTokenServiceImpl.java
...golm/film/api/user/service/impl/UserTokenServiceImpl.java
+19
-0
AdminLoginInterceptor.java
.../egolm/film/config/interceptor/AdminLoginInterceptor.java
+2
-5
LogsUtil.java
...main/java/com/egolm/film/config/interceptor/LogsUtil.java
+0
-46
MemberLoginInterceptor.java
...egolm/film/config/interceptor/MemberLoginInterceptor.java
+2
-5
UserLoginInterceptor.java
...m/egolm/film/config/interceptor/UserLoginInterceptor.java
+2
-5
No files found.
src/main/java/com/egolm/film/api/TokenService.java
View file @
98d89338
package
com
.
egolm
.
film
.
api
;
import
javax.servlet.http.HttpServletRequest
;
import
com.egolm.film.model.LoginToken
;
public
interface
TokenService
{
...
...
@@ -15,4 +17,6 @@ public interface TokenService {
boolean
isLogin
();
boolean
isLoginByToken
(
String
token
);
void
log
(
HttpServletRequest
request
);
}
src/main/java/com/egolm/film/api/admin/AdminLoginController.java
View file @
98d89338
package
com
.
egolm
.
film
.
api
.
admin
;
import
javax.servlet.http.HttpServletRequest
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
...
@@ -8,7 +10,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
import
com.egolm.common.bean.Rjx
;
import
com.egolm.film.api.admin.service.AdminTokenService
;
import
com.egolm.film.api.common.service.Messages
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.model.LoginToken
;
...
...
@@ -23,23 +24,20 @@ public class AdminLoginController {
@Autowired
private
AdminTokenService
tokenService
;
@Autowired
private
Messages
messages
;
@ResponseBody
@PostMapping
(
"login"
)
@ApiOperation
(
"登陆"
)
public
Object
login
(
String
username
,
String
password
)
{
XException
.
assertNotBlank
(
messages
.
get
(
"err.user_pwd_null"
)
,
username
,
password
);
public
Object
login
(
String
username
,
String
password
,
HttpServletRequest
request
)
{
XException
.
assertNotBlank
(
"用户名或密码不能为空"
,
username
,
password
);
if
(
tokenService
.
isLogin
())
{
throw
new
XException
(
"用户已登录"
,
200
);
}
else
{
LoginToken
token
=
tokenService
.
doLogin
(
username
,
password
);
if
(
token
!=
null
)
{
tokenService
.
log
(
request
);
return
Rjx
.
jsonOk
().
setData
(
token
);
}
else
{
throw
new
XException
(
messages
.
get
(
"err.user_or_pwd"
)
);
throw
new
XException
(
"用户名或密码错误"
);
}
}
}
...
...
src/main/java/com/egolm/film/api/admin/service/AdminTokenService.java
View file @
98d89338
...
...
@@ -5,5 +5,6 @@ import com.egolm.film.api.TokenService;
public
interface
AdminTokenService
extends
TokenService
{
final
String
TOKEN_NAME
=
"FILM_ADMIN_LOGIN_TOKEN_NAME"
;
final
String
LOG_TYPE
=
"ADMIN"
;
}
src/main/java/com/egolm/film/api/admin/service/impl/AdminTokenServiceImpl.java
View file @
98d89338
package
com
.
egolm
.
film
.
api
.
admin
.
service
.
impl
;
import
java.util.Date
;
import
java.util.List
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.alibaba.fastjson.JSON
;
import
com.egolm.common.jdbc.JdbcTemplate
;
import
com.egolm.common.web.ServletUtil
;
import
com.egolm.film.api.admin.service.AdminTokenService
;
import
com.egolm.film.bean.Fc_admin
;
import
com.egolm.film.config.WebMvcConfig
;
...
...
@@ -95,4 +99,19 @@ public class AdminTokenServiceImpl implements AdminTokenService {
return
false
;
}
}
@Override
public
void
log
(
HttpServletRequest
request
)
{
LoginToken
token
=
this
.
getToken
();
String
loginid
=
String
.
valueOf
(
token
.
getId
());
Date
now
=
new
Date
();
String
path
=
request
.
getRequestURI
().
replace
(
request
.
getContextPath
(),
""
);
String
prefix
=
path
.
split
(
"/"
)[
1
];
String
content
=
JSON
.
toJSONString
(
request
.
getParameterMap
());
String
ip
=
ServletUtil
.
readReqJson
(
request
);
String
sql
=
"insert into fc_logs (type, loginid, prefix, path, ip, content, create_time) values (?, ?, ?, ?, ?, ?, ?)"
;
Object
[]
objs
=
new
Object
[]{
LOG_TYPE
,
loginid
,
prefix
,
path
,
ip
,
content
,
now
};
jdbcTemplate
.
executeUpdate
(
sql
,
objs
);
}
}
src/main/java/com/egolm/film/api/member/MemberLoginController.java
View file @
98d89338
package
com
.
egolm
.
film
.
api
.
member
;
import
javax.servlet.http.HttpServletRequest
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
...
@@ -34,14 +36,14 @@ public class MemberLoginController {
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"header"
,
dataType
=
"string"
,
name
=
"i18n_language"
)
})
public
Object
login
(
String
username
,
String
password
)
{
public
Object
login
(
String
username
,
String
password
,
HttpServletRequest
request
)
{
XException
.
assertNotBlank
(
messages
.
get
(
"err.user_pwd_null"
),
username
,
password
);
if
(
tokenService
.
isLogin
())
{
throw
new
XException
(
""
,
200
);
}
else
{
LoginToken
token
=
tokenService
.
doLogin
(
username
,
password
);
if
(
token
!=
null
)
{
tokenService
.
log
(
request
);
return
Rjx
.
jsonOk
();
}
else
{
throw
new
XException
(
messages
.
get
(
"err.user_or_pwd"
));
...
...
src/main/java/com/egolm/film/api/member/service/MemberTokenService.java
View file @
98d89338
...
...
@@ -5,5 +5,6 @@ import com.egolm.film.api.TokenService;
public
interface
MemberTokenService
extends
TokenService
{
final
String
TOKEN_NAME
=
"FILM_MEMBER_LOGIN_TOKEN_NAME"
;
final
String
LOG_TYPE
=
"MEMBER"
;
}
src/main/java/com/egolm/film/api/member/service/impl/MemberTokenServiceImpl.java
View file @
98d89338
package
com
.
egolm
.
film
.
api
.
member
.
service
.
impl
;
import
java.util.Date
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.alibaba.fastjson.JSON
;
import
com.egolm.common.jdbc.JdbcTemplate
;
import
com.egolm.common.web.ServletUtil
;
import
com.egolm.film.api.common.service.Messages
;
import
com.egolm.film.api.member.service.MemberService
;
import
com.egolm.film.api.member.service.MemberTokenService
;
...
...
@@ -24,6 +30,9 @@ public class MemberTokenServiceImpl implements MemberTokenService {
@Autowired
private
MemberService
memberService
;
@Autowired
private
JdbcTemplate
jdbcTemplate
;
@Override
public
LoginToken
doLogin
(
String
email
,
String
password
)
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
...
...
@@ -95,4 +104,18 @@ public class MemberTokenServiceImpl implements MemberTokenService {
}
}
@Override
public
void
log
(
HttpServletRequest
request
)
{
LoginToken
token
=
this
.
getToken
();
String
loginid
=
String
.
valueOf
(
token
.
getId
());
Date
now
=
new
Date
();
String
path
=
request
.
getRequestURI
().
replace
(
request
.
getContextPath
(),
""
);
String
prefix
=
path
.
split
(
"/"
)[
1
];
String
content
=
JSON
.
toJSONString
(
request
.
getParameterMap
());
String
ip
=
ServletUtil
.
readReqJson
(
request
);
String
sql
=
"insert into fc_logs (type, loginid, prefix, path, ip, content, create_time) values (?, ?, ?, ?, ?, ?, ?)"
;
Object
[]
objs
=
new
Object
[]{
LOG_TYPE
,
loginid
,
prefix
,
path
,
ip
,
content
,
now
};
jdbcTemplate
.
executeUpdate
(
sql
,
objs
);
}
}
src/main/java/com/egolm/film/api/user/service/UserTokenService.java
View file @
98d89338
...
...
@@ -5,5 +5,6 @@ import com.egolm.film.api.TokenService;
public
interface
UserTokenService
extends
TokenService
{
final
String
TOKEN_NAME
=
"FILM_USER_LOGIN_TOKEN_NAME"
;
final
String
LOG_TYPE
=
"USER"
;
}
src/main/java/com/egolm/film/api/user/service/impl/UserTokenServiceImpl.java
View file @
98d89338
package
com
.
egolm
.
film
.
api
.
user
.
service
.
impl
;
import
java.util.Date
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.alibaba.fastjson.JSON
;
import
com.egolm.common.jdbc.JdbcTemplate
;
import
com.egolm.common.web.ServletUtil
;
import
com.egolm.film.api.common.service.Messages
;
import
com.egolm.film.api.user.service.UserTokenService
;
import
com.egolm.film.bean.Fc_user
;
...
...
@@ -89,4 +94,18 @@ public class UserTokenServiceImpl implements UserTokenService {
return
false
;
}
}
@Override
public
void
log
(
HttpServletRequest
request
)
{
LoginToken
token
=
this
.
getToken
();
String
loginid
=
String
.
valueOf
(
token
.
getId
());
Date
now
=
new
Date
();
String
path
=
request
.
getRequestURI
().
replace
(
request
.
getContextPath
(),
""
);
String
prefix
=
path
.
split
(
"/"
)[
1
];
String
content
=
JSON
.
toJSONString
(
request
.
getParameterMap
());
String
ip
=
ServletUtil
.
readReqJson
(
request
);
String
sql
=
"insert into fc_logs (type, loginid, prefix, path, ip, content, create_time) values (?, ?, ?, ?, ?, ?, ?)"
;
Object
[]
objs
=
new
Object
[]{
LOG_TYPE
,
loginid
,
prefix
,
path
,
ip
,
content
,
now
};
jdbcTemplate
.
executeUpdate
(
sql
,
objs
);
}
}
src/main/java/com/egolm/film/config/interceptor/AdminLoginInterceptor.java
View file @
98d89338
...
...
@@ -18,13 +18,10 @@ public class AdminLoginInterceptor extends HandlerInterceptorAdapter {
@Autowired
private
AdminTokenService
tokenService
;
@Autowired
private
LogsUtil
logUtil
;
@Override
public
boolean
preHandle
(
HttpServletRequest
req
,
HttpServletResponse
resp
,
Object
handler
)
throws
Exception
{
if
(
tokenService
.
isLogin
())
{
logUtil
.
log
(
tokenService
,
req
);
tokenService
.
log
(
req
);
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
else
{
String
sessionid
=
null
;
...
...
@@ -35,7 +32,7 @@ public class AdminLoginInterceptor extends HandlerInterceptorAdapter {
}
}
if
(
sessionid
!=
null
&&
tokenService
.
isLoginByToken
(
sessionid
))
{
logUtil
.
log
(
tokenService
,
req
);
tokenService
.
log
(
req
);
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
throw
new
XException
(
"用户未登陆"
,
300
);
...
...
src/main/java/com/egolm/film/config/interceptor/LogsUtil.java
deleted
100644 → 0
View file @
0c33d873
package
com
.
egolm
.
film
.
config
.
interceptor
;
import
java.util.Date
;
import
javax.servlet.http.HttpServletRequest
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
com.alibaba.fastjson.JSON
;
import
com.egolm.common.jdbc.JdbcTemplate
;
import
com.egolm.common.web.ServletUtil
;
import
com.egolm.film.api.TokenService
;
import
com.egolm.film.api.admin.service.AdminTokenService
;
import
com.egolm.film.api.member.service.MemberTokenService
;
import
com.egolm.film.api.user.service.UserTokenService
;
import
com.egolm.film.model.LoginToken
;
@Component
public
class
LogsUtil
{
@Autowired
private
JdbcTemplate
jdbcTemplate
;
public
void
log
(
TokenService
tokenService
,
HttpServletRequest
request
)
{
LoginToken
token
=
tokenService
.
getToken
();
String
type
=
null
;
if
(
tokenService
instanceof
AdminTokenService
)
{
type
=
"admin"
;
}
else
if
(
tokenService
instanceof
MemberTokenService
)
{
type
=
"member"
;
}
else
if
(
tokenService
instanceof
UserTokenService
)
{
type
=
"user"
;
}
String
loginid
=
String
.
valueOf
(
token
.
getId
());
Date
now
=
new
Date
();
String
path
=
request
.
getRequestURI
().
replace
(
request
.
getContextPath
(),
""
);
String
prefix
=
path
.
split
(
"/"
)[
1
];
String
content
=
JSON
.
toJSONString
(
request
.
getParameterMap
());
String
ip
=
ServletUtil
.
readReqJson
(
request
);
String
sql
=
"insert into fc_logs (type, loginid, prefix, path, ip, content, create_time) values (?, ?, ?, ?, ?, ?, ?)"
;
Object
[]
objs
=
new
Object
[]{
type
,
loginid
,
prefix
,
path
,
ip
,
content
,
now
};
jdbcTemplate
.
executeUpdate
(
sql
,
objs
);
}
}
src/main/java/com/egolm/film/config/interceptor/MemberLoginInterceptor.java
View file @
98d89338
...
...
@@ -18,13 +18,10 @@ public class MemberLoginInterceptor extends HandlerInterceptorAdapter {
@Autowired
private
MemberTokenService
tokenService
;
@Autowired
private
LogsUtil
logUtil
;
@Override
public
boolean
preHandle
(
HttpServletRequest
req
,
HttpServletResponse
resp
,
Object
handler
)
throws
Exception
{
if
(
tokenService
.
isLogin
())
{
logUtil
.
log
(
tokenService
,
req
);
tokenService
.
log
(
req
);
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
else
{
String
sessionid
=
null
;
...
...
@@ -35,7 +32,7 @@ public class MemberLoginInterceptor extends HandlerInterceptorAdapter {
}
}
if
(
sessionid
!=
null
&&
tokenService
.
isLoginByToken
(
sessionid
))
{
logUtil
.
log
(
tokenService
,
req
);
tokenService
.
log
(
req
);
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
throw
new
XException
(
"用户未登陆"
,
300
);
...
...
src/main/java/com/egolm/film/config/interceptor/UserLoginInterceptor.java
View file @
98d89338
...
...
@@ -18,13 +18,10 @@ public class UserLoginInterceptor extends HandlerInterceptorAdapter {
@Autowired
private
UserTokenService
tokenService
;
@Autowired
private
LogsUtil
logUtil
;
@Override
public
boolean
preHandle
(
HttpServletRequest
req
,
HttpServletResponse
resp
,
Object
handler
)
throws
Exception
{
if
(
tokenService
.
isLogin
())
{
logUtil
.
log
(
tokenService
,
req
);
tokenService
.
log
(
req
);
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
else
{
String
sessionid
=
null
;
...
...
@@ -35,7 +32,7 @@ public class UserLoginInterceptor extends HandlerInterceptorAdapter {
}
}
if
(
sessionid
!=
null
&&
tokenService
.
isLoginByToken
(
sessionid
))
{
logUtil
.
log
(
tokenService
,
req
);
tokenService
.
log
(
req
);
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
throw
new
XException
(
"用户未登陆"
,
300
);
...
...
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