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
cf027b5a
Commit
cf027b5a
authored
Oct 29, 2018
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化登陆
parent
99e999b0
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
136 additions
and
4 deletions
+136
-4
TokenService.java
src/main/java/com/egolm/film/api/TokenService.java
+5
-2
AdminTokenServiceImpl.java
...lm/film/api/admin/service/impl/AdminTokenServiceImpl.java
+20
-0
MemberService.java
...java/com/egolm/film/api/member/service/MemberService.java
+4
-0
MemberTokenService.java
...com/egolm/film/api/member/service/MemberTokenService.java
+1
-1
MemberServiceImpl.java
...egolm/film/api/member/service/impl/MemberServiceImpl.java
+12
-0
MemberTokenServiceImpl.java
.../film/api/member/service/impl/MemberTokenServiceImpl.java
+25
-1
UserTokenServiceImpl.java
...golm/film/api/user/service/impl/UserTokenServiceImpl.java
+20
-0
WebMvcConfig.java
src/main/java/com/egolm/film/config/WebMvcConfig.java
+13
-0
AdminLoginInterceptor.java
.../egolm/film/config/interceptor/AdminLoginInterceptor.java
+12
-0
MemberLoginInterceptor.java
...egolm/film/config/interceptor/MemberLoginInterceptor.java
+12
-0
UserLoginInterceptor.java
...m/egolm/film/config/interceptor/UserLoginInterceptor.java
+12
-0
No files found.
src/main/java/com/egolm/film/api/TokenService.java
View file @
cf027b5a
...
@@ -3,13 +3,16 @@ package com.egolm.film.api;
...
@@ -3,13 +3,16 @@ package com.egolm.film.api;
import
com.egolm.film.model.LoginToken
;
import
com.egolm.film.model.LoginToken
;
public
interface
TokenService
{
public
interface
TokenService
{
final
String
JSESSIONID
=
"JSESSIONID"
;
LoginToken
getToken
();
LoginToken
getToken
();
LoginToken
doLogin
(
String
username
,
String
password
);
LoginToken
doLogin
(
String
username
,
String
password
);
void
doLogout
();
void
doLogout
();
boolean
isLogin
();
boolean
isLogin
();
boolean
isLoginByToken
(
String
token
);
}
}
src/main/java/com/egolm/film/api/admin/service/impl/AdminTokenServiceImpl.java
View file @
cf027b5a
...
@@ -3,6 +3,7 @@ package com.egolm.film.api.admin.service.impl;
...
@@ -3,6 +3,7 @@ package com.egolm.film.api.admin.service.impl;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpSession
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -35,6 +36,11 @@ public class AdminTokenServiceImpl implements AdminTokenService {
...
@@ -35,6 +36,11 @@ public class AdminTokenServiceImpl implements AdminTokenService {
Integer
adminid
=
(
Integer
)
map
.
get
(
"adminid"
);
Integer
adminid
=
(
Integer
)
map
.
get
(
"adminid"
);
LoginToken
token
=
new
LoginToken
(
adminid
);
LoginToken
token
=
new
LoginToken
(
adminid
);
session
.
setAttribute
(
TOKEN_NAME
,
token
);
session
.
setAttribute
(
TOKEN_NAME
,
token
);
Cookie
cookie
=
WebMvcConfig
.
getCookie
(
JSESSIONID
);
if
(
cookie
!=
null
)
{
String
sql
=
"update fc_admin set token = ? where id = ?"
;
jdbcTemplate
.
executeUpdate
(
sql
,
cookie
.
getValue
(),
adminid
);
}
return
token
;
return
token
;
}
else
if
(
state
==
2
)
{
}
else
if
(
state
==
2
)
{
throw
new
XException
(
"用户已禁用"
);
throw
new
XException
(
"用户已禁用"
);
...
@@ -69,4 +75,18 @@ public class AdminTokenServiceImpl implements AdminTokenService {
...
@@ -69,4 +75,18 @@ public class AdminTokenServiceImpl implements AdminTokenService {
public
boolean
isLogin
()
{
public
boolean
isLogin
()
{
return
this
.
getToken
()
!=
null
;
return
this
.
getToken
()
!=
null
;
}
}
@Override
public
boolean
isLoginByToken
(
String
token_string
)
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
try
{
String
sql
=
"select adminid from fc_admin where token = ?"
;
Integer
adminid
=
jdbcTemplate
.
queryForInt
(
sql
,
token_string
);
LoginToken
token
=
new
LoginToken
(
adminid
);
session
.
setAttribute
(
TOKEN_NAME
,
token
);
return
true
;
}
catch
(
Exception
e
)
{
return
false
;
}
}
}
}
src/main/java/com/egolm/film/api/member/service/MemberService.java
View file @
cf027b5a
...
@@ -125,4 +125,8 @@ public interface MemberService {
...
@@ -125,4 +125,8 @@ public interface MemberService {
boolean
changePasswordByMemberId
(
Integer
member_id
,
String
password
,
String
newPassword
);
boolean
changePasswordByMemberId
(
Integer
member_id
,
String
password
,
String
newPassword
);
Fc_member
getMemberByToken
(
String
token
);
void
updateToken
(
Integer
member_id
,
String
token_string
);
}
}
src/main/java/com/egolm/film/api/member/service/MemberTokenService.java
View file @
cf027b5a
...
@@ -5,5 +5,5 @@ import com.egolm.film.api.TokenService;
...
@@ -5,5 +5,5 @@ import com.egolm.film.api.TokenService;
public
interface
MemberTokenService
extends
TokenService
{
public
interface
MemberTokenService
extends
TokenService
{
final
String
TOKEN_NAME
=
"FILM_MEMBER_LOGIN_TOKEN_NAME"
;
final
String
TOKEN_NAME
=
"FILM_MEMBER_LOGIN_TOKEN_NAME"
;
}
}
src/main/java/com/egolm/film/api/member/service/impl/MemberServiceImpl.java
View file @
cf027b5a
...
@@ -466,4 +466,16 @@ public class MemberServiceImpl implements MemberService {
...
@@ -466,4 +466,16 @@ public class MemberServiceImpl implements MemberService {
return
false
;
return
false
;
}
}
@Override
public
Fc_member
getMemberByToken
(
String
token
)
{
String
sql
=
"select * from fc_member where token = ?"
;
return
jdbcTemplate
.
queryForBean
(
sql
,
Fc_member
.
class
,
token
);
}
@Override
public
void
updateToken
(
Integer
member_id
,
String
token_string
)
{
String
sql
=
"update fc_member set token = ? where id = ?"
;
jdbcTemplate
.
executeUpdate
(
sql
,
token_string
,
member_id
);
}
}
}
src/main/java/com/egolm/film/api/member/service/impl/MemberTokenServiceImpl.java
View file @
cf027b5a
package
com
.
egolm
.
film
.
api
.
member
.
service
.
impl
;
package
com
.
egolm
.
film
.
api
.
member
.
service
.
impl
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpSession
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -41,6 +42,10 @@ public class MemberTokenServiceImpl implements MemberTokenService {
...
@@ -41,6 +42,10 @@ public class MemberTokenServiceImpl implements MemberTokenService {
Integer
id
=
member
.
getId
();
Integer
id
=
member
.
getId
();
LoginToken
token
=
new
LoginToken
(
id
);
LoginToken
token
=
new
LoginToken
(
id
);
session
.
setAttribute
(
TOKEN_NAME
,
token
);
session
.
setAttribute
(
TOKEN_NAME
,
token
);
Cookie
cookie
=
WebMvcConfig
.
getCookie
(
JSESSIONID
);
if
(
cookie
!=
null
)
{
memberService
.
updateToken
(
id
,
cookie
.
getValue
());
}
return
token
;
return
token
;
}
else
{
}
else
{
throw
new
XException
(
messages
.
get
(
"err.user_pwd_err"
));
throw
new
XException
(
messages
.
get
(
"err.user_pwd_err"
));
...
@@ -51,7 +56,7 @@ public class MemberTokenServiceImpl implements MemberTokenService {
...
@@ -51,7 +56,7 @@ public class MemberTokenServiceImpl implements MemberTokenService {
throw
new
XException
(
messages
.
get
(
"err"
));
throw
new
XException
(
messages
.
get
(
"err"
));
}
}
}
}
@Override
@Override
public
LoginToken
getToken
()
{
public
LoginToken
getToken
()
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
HttpSession
session
=
WebMvcConfig
.
getSession
();
...
@@ -71,4 +76,23 @@ public class MemberTokenServiceImpl implements MemberTokenService {
...
@@ -71,4 +76,23 @@ public class MemberTokenServiceImpl implements MemberTokenService {
return
this
.
getToken
()
!=
null
;
return
this
.
getToken
()
!=
null
;
}
}
@Override
public
boolean
isLoginByToken
(
String
token_string
)
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
try
{
Fc_member
member
=
memberService
.
getMemberByToken
(
token_string
);
Integer
state
=
member
.
getState
();
if
(
state
==
1
)
{
Integer
id
=
member
.
getId
();
LoginToken
token
=
new
LoginToken
(
id
);
session
.
setAttribute
(
TOKEN_NAME
,
token
);
return
true
;
}
else
{
return
false
;
}
}
catch
(
Exception
e
)
{
return
false
;
}
}
}
}
src/main/java/com/egolm/film/api/user/service/impl/UserTokenServiceImpl.java
View file @
cf027b5a
...
@@ -3,6 +3,7 @@ package com.egolm.film.api.user.service.impl;
...
@@ -3,6 +3,7 @@ package com.egolm.film.api.user.service.impl;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpSession
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -35,6 +36,11 @@ public class UserTokenServiceImpl implements UserTokenService {
...
@@ -35,6 +36,11 @@ public class UserTokenServiceImpl implements UserTokenService {
Integer
uid
=
(
Integer
)
map
.
get
(
"uid"
);
Integer
uid
=
(
Integer
)
map
.
get
(
"uid"
);
LoginToken
token
=
new
LoginToken
(
uid
);
LoginToken
token
=
new
LoginToken
(
uid
);
session
.
setAttribute
(
TOKEN_NAME
,
token
);
session
.
setAttribute
(
TOKEN_NAME
,
token
);
Cookie
cookie
=
WebMvcConfig
.
getCookie
(
JSESSIONID
);
if
(
cookie
!=
null
)
{
String
sql
=
"update fc_user set token = ? where id = ?"
;
jdbcTemplate
.
executeUpdate
(
sql
,
cookie
.
getValue
(),
uid
);
}
return
token
;
return
token
;
}
else
if
(
state
==
2
)
{
}
else
if
(
state
==
2
)
{
throw
new
XException
(
"用户已禁用"
);
throw
new
XException
(
"用户已禁用"
);
...
@@ -69,4 +75,18 @@ public class UserTokenServiceImpl implements UserTokenService {
...
@@ -69,4 +75,18 @@ public class UserTokenServiceImpl implements UserTokenService {
public
boolean
isLogin
()
{
public
boolean
isLogin
()
{
return
this
.
getToken
()
!=
null
;
return
this
.
getToken
()
!=
null
;
}
}
@Override
public
boolean
isLoginByToken
(
String
token_string
)
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
try
{
String
sql
=
"select uid from fc_user where token = ?"
;
Long
uid
=
jdbcTemplate
.
queryForLong
(
sql
,
token_string
);
LoginToken
token
=
new
LoginToken
(
uid
);
session
.
setAttribute
(
TOKEN_NAME
,
token
);
return
true
;
}
catch
(
Exception
e
)
{
return
false
;
}
}
}
}
src/main/java/com/egolm/film/config/WebMvcConfig.java
View file @
cf027b5a
...
@@ -2,6 +2,7 @@ package com.egolm.film.config;
...
@@ -2,6 +2,7 @@ package com.egolm.film.config;
import
java.util.EventListener
;
import
java.util.EventListener
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
javax.servlet.http.HttpSession
;
...
@@ -82,4 +83,16 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
...
@@ -82,4 +83,16 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
return
null
;
return
null
;
}
}
public
static
Cookie
getCookie
(
String
name
)
{
HttpServletRequest
request
=
WebMvcConfig
.
getRequest
();
if
(
request
!=
null
)
{
Cookie
[]
cookies
=
request
.
getCookies
();
for
(
Cookie
cookie
:
cookies
)
{
if
(
cookie
.
getName
().
equals
(
name
))
{
return
cookie
;
}
}
}
return
null
;
}
}
}
src/main/java/com/egolm/film/config/interceptor/AdminLoginInterceptor.java
View file @
cf027b5a
package
com
.
egolm
.
film
.
config
.
interceptor
;
package
com
.
egolm
.
film
.
config
.
interceptor
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
...
@@ -7,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -7,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
com.egolm.film.api.TokenService
;
import
com.egolm.film.api.admin.service.AdminTokenService
;
import
com.egolm.film.api.admin.service.AdminTokenService
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.config.XException
;
...
@@ -21,6 +23,16 @@ public class AdminLoginInterceptor extends HandlerInterceptorAdapter {
...
@@ -21,6 +23,16 @@ public class AdminLoginInterceptor extends HandlerInterceptorAdapter {
if
(
tokenService
.
isLogin
())
{
if
(
tokenService
.
isLogin
())
{
return
super
.
preHandle
(
req
,
resp
,
handler
);
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
else
{
}
else
{
String
sessionid
=
null
;
Cookie
[]
cookies
=
req
.
getCookies
();
for
(
Cookie
cookie
:
cookies
)
{
if
(
cookie
.
getName
().
equals
(
TokenService
.
JSESSIONID
))
{
sessionid
=
cookie
.
getValue
();
}
}
if
(
sessionid
!=
null
&&
tokenService
.
isLoginByToken
(
sessionid
))
{
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
throw
new
XException
(
"用户未登陆"
,
300
);
throw
new
XException
(
"用户未登陆"
,
300
);
}
}
}
}
...
...
src/main/java/com/egolm/film/config/interceptor/MemberLoginInterceptor.java
View file @
cf027b5a
package
com
.
egolm
.
film
.
config
.
interceptor
;
package
com
.
egolm
.
film
.
config
.
interceptor
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
...
@@ -7,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -7,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
com.egolm.film.api.TokenService
;
import
com.egolm.film.api.member.service.MemberTokenService
;
import
com.egolm.film.api.member.service.MemberTokenService
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.config.XException
;
...
@@ -21,6 +23,16 @@ public class MemberLoginInterceptor extends HandlerInterceptorAdapter {
...
@@ -21,6 +23,16 @@ public class MemberLoginInterceptor extends HandlerInterceptorAdapter {
if
(
tokenService
.
isLogin
())
{
if
(
tokenService
.
isLogin
())
{
return
super
.
preHandle
(
req
,
resp
,
handler
);
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
else
{
}
else
{
String
sessionid
=
null
;
Cookie
[]
cookies
=
req
.
getCookies
();
for
(
Cookie
cookie
:
cookies
)
{
if
(
cookie
.
getName
().
equals
(
TokenService
.
JSESSIONID
))
{
sessionid
=
cookie
.
getValue
();
}
}
if
(
sessionid
!=
null
&&
tokenService
.
isLoginByToken
(
sessionid
))
{
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
throw
new
XException
(
"用户未登陆"
,
300
);
throw
new
XException
(
"用户未登陆"
,
300
);
}
}
}
}
...
...
src/main/java/com/egolm/film/config/interceptor/UserLoginInterceptor.java
View file @
cf027b5a
package
com
.
egolm
.
film
.
config
.
interceptor
;
package
com
.
egolm
.
film
.
config
.
interceptor
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
...
@@ -7,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -7,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
com.egolm.film.api.TokenService
;
import
com.egolm.film.api.user.service.UserTokenService
;
import
com.egolm.film.api.user.service.UserTokenService
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.config.XException
;
...
@@ -21,6 +23,16 @@ public class UserLoginInterceptor extends HandlerInterceptorAdapter {
...
@@ -21,6 +23,16 @@ public class UserLoginInterceptor extends HandlerInterceptorAdapter {
if
(
tokenService
.
isLogin
())
{
if
(
tokenService
.
isLogin
())
{
return
super
.
preHandle
(
req
,
resp
,
handler
);
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
else
{
}
else
{
String
sessionid
=
null
;
Cookie
[]
cookies
=
req
.
getCookies
();
for
(
Cookie
cookie
:
cookies
)
{
if
(
cookie
.
getName
().
equals
(
TokenService
.
JSESSIONID
))
{
sessionid
=
cookie
.
getValue
();
}
}
if
(
sessionid
!=
null
&&
tokenService
.
isLoginByToken
(
sessionid
))
{
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
throw
new
XException
(
"用户未登陆"
,
300
);
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