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
faa1cfc0
Commit
faa1cfc0
authored
Oct 09, 2018
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初始化语言环境,优化登陆TOKEN代码
parent
12ce8052
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
82 additions
and
73 deletions
+82
-73
FilmApplication.java
src/main/java/com/egolm/film/FilmApplication.java
+0
-5
MemberOpenApiController.java
...main/java/com/egolm/film/api/MemberOpenApiController.java
+9
-0
WebMvcConfig.java
src/main/java/com/egolm/film/config/WebMvcConfig.java
+4
-0
LocaleSessionInterceptor.java
...olm/film/config/interceptor/LocaleSessionInterceptor.java
+29
-0
AbstractTokenService.java
...va/com/egolm/film/login/service/AbstractTokenService.java
+32
-0
AdminTokenServiceImpl.java
.../egolm/film/login/service/impl/AdminTokenServiceImpl.java
+2
-20
MemberTokenServiceImpl.java
...egolm/film/login/service/impl/MemberTokenServiceImpl.java
+2
-21
UserTokenServiceImpl.java
...m/egolm/film/login/service/impl/UserTokenServiceImpl.java
+2
-21
DefaultMessages.java
src/main/java/com/egolm/film/messages/DefaultMessages.java
+2
-6
No files found.
src/main/java/com/egolm/film/FilmApplication.java
View file @
faa1cfc0
package
com
.
egolm
.
film
;
package
com
.
egolm
.
film
;
import
java.util.Locale
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
@EnableCaching
@EnableCaching
...
@@ -21,7 +17,6 @@ public class FilmApplication {
...
@@ -21,7 +17,6 @@ public class FilmApplication {
private
static
ApplicationContext
applicationContext
;
private
static
ApplicationContext
applicationContext
;
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
LocaleContextHolder
.
setDefaultLocale
(
Locale
.
CHINA
);
applicationContext
=
SpringApplication
.
run
(
FilmApplication
.
class
,
args
);
applicationContext
=
SpringApplication
.
run
(
FilmApplication
.
class
,
args
);
}
}
...
...
src/main/java/com/egolm/film/api/MemberOpenApiController.java
View file @
faa1cfc0
...
@@ -35,4 +35,13 @@ public class MemberOpenApiController {
...
@@ -35,4 +35,13 @@ public class MemberOpenApiController {
public
Object
getPassword
(
String
email
)
{
public
Object
getPassword
(
String
email
)
{
return
Rjx
.
jsonOk
();
return
Rjx
.
jsonOk
();
}
}
@PostMapping
(
"setLocale"
)
@ApiOperation
(
"设置语言环境"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"query"
,
dataType
=
"string"
,
required
=
true
,
name
=
"i18n_language"
,
defaultValue
=
"zh_CN"
),
})
public
Object
setLocale
(
String
i18n_language
)
{
return
Rjx
.
jsonOk
();
}
}
}
src/main/java/com/egolm/film/config/WebMvcConfig.java
View file @
faa1cfc0
...
@@ -18,6 +18,7 @@ import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
...
@@ -18,6 +18,7 @@ import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
com.egolm.film.config.interceptor.AdminLoginInterceptor
;
import
com.egolm.film.config.interceptor.AdminLoginInterceptor
;
import
com.egolm.film.config.interceptor.LocaleSessionInterceptor
;
import
com.egolm.film.config.interceptor.UserLoginInterceptor
;
import
com.egolm.film.config.interceptor.UserLoginInterceptor
;
@Configuration
@Configuration
...
@@ -32,9 +33,12 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
...
@@ -32,9 +33,12 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Autowired
@Autowired
private
UserLoginInterceptor
memberLoginInterceptor
;
private
UserLoginInterceptor
memberLoginInterceptor
;
@Autowired
private
LocaleSessionInterceptor
localeSessionInterceptor
;
@Override
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
registry
.
addInterceptor
(
localeSessionInterceptor
).
addPathPatterns
(
"/**"
);
registry
.
addInterceptor
(
adminLoginInterceptor
).
addPathPatterns
(
"/admin/**"
).
excludePathPatterns
(
"/admin/login"
);
registry
.
addInterceptor
(
adminLoginInterceptor
).
addPathPatterns
(
"/admin/**"
).
excludePathPatterns
(
"/admin/login"
);
registry
.
addInterceptor
(
userLoginInterceptor
).
addPathPatterns
(
"/user/**"
).
excludePathPatterns
(
"/user/login"
);
registry
.
addInterceptor
(
userLoginInterceptor
).
addPathPatterns
(
"/user/**"
).
excludePathPatterns
(
"/user/login"
);
registry
.
addInterceptor
(
memberLoginInterceptor
).
addPathPatterns
(
"/member/**"
).
excludePathPatterns
(
"/member/login"
);
registry
.
addInterceptor
(
memberLoginInterceptor
).
addPathPatterns
(
"/member/**"
).
excludePathPatterns
(
"/member/login"
);
...
...
src/main/java/com/egolm/film/config/interceptor/LocaleSessionInterceptor.java
0 → 100644
View file @
faa1cfc0
package
com
.
egolm
.
film
.
config
.
interceptor
;
import
java.util.Locale
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
@Component
public
class
LocaleSessionInterceptor
extends
HandlerInterceptorAdapter
{
public
static
final
String
I18N_LANGUAGE_SESSION
=
"I18N_LANGUAGE_SESSION"
;
@Override
public
boolean
preHandle
(
HttpServletRequest
req
,
HttpServletResponse
resp
,
Object
handler
)
throws
Exception
{
HttpSession
session
=
req
.
getSession
();
Locale
locale
=
(
Locale
)
session
.
getAttribute
(
I18N_LANGUAGE_SESSION
);
if
(
locale
==
null
)
{
locale
=
req
.
getLocale
();
}
LocaleContextHolder
.
setLocale
(
locale
);
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
}
src/main/java/com/egolm/film/login/service/AbstractTokenService.java
0 → 100644
View file @
faa1cfc0
package
com
.
egolm
.
film
.
login
.
service
;
import
javax.servlet.http.HttpSession
;
import
com.egolm.film.config.WebMvcConfig
;
import
com.egolm.film.model.LoginToken
;
public
abstract
class
AbstractTokenService
implements
UserTokenService
{
@Override
public
LoginToken
getToken
()
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
LoginToken
token
=
(
LoginToken
)
session
.
getAttribute
(
TOKEN_NAME
);
return
token
;
}
@Override
abstract
public
LoginToken
doLogin
(
String
username
,
String
password
);
@Override
public
void
doLogout
()
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
session
.
removeAttribute
(
TOKEN_NAME
);
session
.
invalidate
();
}
@Override
public
boolean
isLogin
()
{
return
this
.
getToken
()
!=
null
;
}
}
src/main/java/com/egolm/film/login/service/impl/AdminTokenServiceImpl.java
View file @
faa1cfc0
...
@@ -12,22 +12,15 @@ import com.egolm.common.StringUtil;
...
@@ -12,22 +12,15 @@ import com.egolm.common.StringUtil;
import
com.egolm.common.jdbc.JdbcTemplate
;
import
com.egolm.common.jdbc.JdbcTemplate
;
import
com.egolm.film.config.WebMvcConfig
;
import
com.egolm.film.config.WebMvcConfig
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.login.service.A
dmin
TokenService
;
import
com.egolm.film.login.service.A
bstract
TokenService
;
import
com.egolm.film.model.LoginToken
;
import
com.egolm.film.model.LoginToken
;
@Service
@Service
public
class
AdminTokenServiceImpl
implements
Admin
TokenService
{
public
class
AdminTokenServiceImpl
extends
Abstract
TokenService
{
@Autowired
@Autowired
private
JdbcTemplate
jdbcTemplate
;
private
JdbcTemplate
jdbcTemplate
;
@Override
public
LoginToken
getToken
()
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
LoginToken
token
=
(
LoginToken
)
session
.
getAttribute
(
TOKEN_NAME
);
return
token
;
}
@Override
@Override
public
LoginToken
doLogin
(
String
username
,
String
password
)
{
public
LoginToken
doLogin
(
String
username
,
String
password
)
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
HttpSession
session
=
WebMvcConfig
.
getSession
();
...
@@ -58,16 +51,5 @@ public class AdminTokenServiceImpl implements AdminTokenService {
...
@@ -58,16 +51,5 @@ public class AdminTokenServiceImpl implements AdminTokenService {
}
}
}
}
@Override
public
void
doLogout
()
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
session
.
removeAttribute
(
TOKEN_NAME
);
session
.
invalidate
();
}
@Override
public
boolean
isLogin
()
{
return
this
.
getToken
()
!=
null
;
}
}
}
src/main/java/com/egolm/film/login/service/impl/MemberTokenServiceImpl.java
View file @
faa1cfc0
...
@@ -12,22 +12,15 @@ import com.egolm.common.StringUtil;
...
@@ -12,22 +12,15 @@ import com.egolm.common.StringUtil;
import
com.egolm.common.jdbc.JdbcTemplate
;
import
com.egolm.common.jdbc.JdbcTemplate
;
import
com.egolm.film.config.WebMvcConfig
;
import
com.egolm.film.config.WebMvcConfig
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.login.service.
Member
TokenService
;
import
com.egolm.film.login.service.
Abstract
TokenService
;
import
com.egolm.film.model.LoginToken
;
import
com.egolm.film.model.LoginToken
;
@Service
@Service
public
class
MemberTokenServiceImpl
implements
Member
TokenService
{
public
class
MemberTokenServiceImpl
extends
Abstract
TokenService
{
@Autowired
@Autowired
private
JdbcTemplate
jdbcTemplate
;
private
JdbcTemplate
jdbcTemplate
;
@Override
public
LoginToken
getToken
()
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
LoginToken
token
=
(
LoginToken
)
session
.
getAttribute
(
TOKEN_NAME
);
return
token
;
}
@Override
@Override
public
LoginToken
doLogin
(
String
username
,
String
password
)
{
public
LoginToken
doLogin
(
String
username
,
String
password
)
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
HttpSession
session
=
WebMvcConfig
.
getSession
();
...
@@ -58,16 +51,4 @@ public class MemberTokenServiceImpl implements MemberTokenService {
...
@@ -58,16 +51,4 @@ public class MemberTokenServiceImpl implements MemberTokenService {
}
}
}
}
@Override
public
void
doLogout
()
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
session
.
removeAttribute
(
TOKEN_NAME
);
session
.
invalidate
();
}
@Override
public
boolean
isLogin
()
{
return
this
.
getToken
()
!=
null
;
}
}
}
src/main/java/com/egolm/film/login/service/impl/UserTokenServiceImpl.java
View file @
faa1cfc0
...
@@ -12,22 +12,15 @@ import com.egolm.common.StringUtil;
...
@@ -12,22 +12,15 @@ import com.egolm.common.StringUtil;
import
com.egolm.common.jdbc.JdbcTemplate
;
import
com.egolm.common.jdbc.JdbcTemplate
;
import
com.egolm.film.config.WebMvcConfig
;
import
com.egolm.film.config.WebMvcConfig
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.login.service.
User
TokenService
;
import
com.egolm.film.login.service.
Abstract
TokenService
;
import
com.egolm.film.model.LoginToken
;
import
com.egolm.film.model.LoginToken
;
@Service
@Service
public
class
UserTokenServiceImpl
implements
User
TokenService
{
public
class
UserTokenServiceImpl
extends
Abstract
TokenService
{
@Autowired
@Autowired
private
JdbcTemplate
jdbcTemplate
;
private
JdbcTemplate
jdbcTemplate
;
@Override
public
LoginToken
getToken
()
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
LoginToken
token
=
(
LoginToken
)
session
.
getAttribute
(
TOKEN_NAME
);
return
token
;
}
@Override
@Override
public
LoginToken
doLogin
(
String
username
,
String
password
)
{
public
LoginToken
doLogin
(
String
username
,
String
password
)
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
HttpSession
session
=
WebMvcConfig
.
getSession
();
...
@@ -58,16 +51,4 @@ public class UserTokenServiceImpl implements UserTokenService {
...
@@ -58,16 +51,4 @@ public class UserTokenServiceImpl implements UserTokenService {
}
}
}
}
@Override
public
void
doLogout
()
{
HttpSession
session
=
WebMvcConfig
.
getSession
();
session
.
removeAttribute
(
TOKEN_NAME
);
session
.
invalidate
();
}
@Override
public
boolean
isLogin
()
{
return
this
.
getToken
()
!=
null
;
}
}
}
src/main/java/com/egolm/film/messages/DefaultMessages.java
View file @
faa1cfc0
...
@@ -2,15 +2,12 @@ package com.egolm.film.messages;
...
@@ -2,15 +2,12 @@ package com.egolm.film.messages;
import
java.util.Locale
;
import
java.util.Locale
;
import
javax.servlet.http.HttpServletRequest
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.MessageSource
;
import
org.springframework.context.MessageSource
;
import
org.springframework.context.NoSuchMessageException
;
import
org.springframework.context.NoSuchMessageException
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.support.RequestContextUtils
;
import
com.egolm.film.config.WebMvcConfig
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.config.XException
;
@Component
@Component
...
@@ -21,8 +18,7 @@ public class DefaultMessages implements Messages {
...
@@ -21,8 +18,7 @@ public class DefaultMessages implements Messages {
public
String
get
(
String
name
,
String
...
args
)
{
public
String
get
(
String
name
,
String
...
args
)
{
try
{
try
{
HttpServletRequest
request
=
WebMvcConfig
.
getRequest
();
Locale
locale
=
LocaleContextHolder
.
getLocale
();
Locale
locale
=
RequestContextUtils
.
getLocale
(
request
);
return
messageSource
.
getMessage
(
name
,
args
,
locale
==
null
?
Locale
.
CHINA
:
locale
);
return
messageSource
.
getMessage
(
name
,
args
,
locale
==
null
?
Locale
.
CHINA
:
locale
);
}
catch
(
NoSuchMessageException
e
)
{
}
catch
(
NoSuchMessageException
e
)
{
return
name
;
return
name
;
...
...
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