Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
member-api
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
曲欣亮
member-api
Commits
d0a8e3fc
Commit
d0a8e3fc
authored
Oct 10, 2018
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化消息提醒
parent
8543f53a
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
40 additions
and
16 deletions
+40
-16
ExceptionHandler.java
src/main/java/com/egolm/film/config/ExceptionHandler.java
+11
-3
XException.java
src/main/java/com/egolm/film/config/XException.java
+5
-3
AdminLoginController.java
src/main/java/com/egolm/film/login/AdminLoginController.java
+6
-3
MemberLoginController.java
...main/java/com/egolm/film/login/MemberLoginController.java
+7
-2
UserLoginController.java
src/main/java/com/egolm/film/login/UserLoginController.java
+7
-2
MemberTokenServiceImpl.java
...egolm/film/login/service/impl/MemberTokenServiceImpl.java
+2
-2
message.properties
src/main/resources/i18n/message.properties
+2
-1
No files found.
src/main/java/com/egolm/film/config/ExceptionHandler.java
View file @
d0a8e3fc
...
@@ -14,21 +14,29 @@ import com.egolm.common.bean.Rjx;
...
@@ -14,21 +14,29 @@ import com.egolm.common.bean.Rjx;
@Component
@Component
public
class
ExceptionHandler
implements
HandlerExceptionResolver
{
public
class
ExceptionHandler
implements
HandlerExceptionResolver
{
private
Logger
logger
=
Logger
.
getLogger
(
ExceptionHandler
.
class
);
private
static
final
Logger
logger
=
Logger
.
getLogger
(
ExceptionHandler
.
class
);
@Override
@Override
public
ModelAndView
resolveException
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
ex
)
{
public
ModelAndView
resolveException
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
ex
)
{
logger
.
error
(
""
,
ex
)
;
boolean
displayInLog
=
true
;
ModelAndView
mav
=
new
ModelAndView
(
new
MappingJackson2JsonView
());
ModelAndView
mav
=
new
ModelAndView
(
new
MappingJackson2JsonView
());
try
{
try
{
response
.
setContentType
(
"application/json"
);
response
.
setContentType
(
"application/json"
);
if
(
ex
instanceof
XException
)
{
if
(
ex
instanceof
XException
)
{
mav
.
addAllObjects
(((
XException
)
ex
).
getRjx
());
Rjx
rjx
=
((
XException
)
ex
).
getRjx
();
mav
.
addAllObjects
(
rjx
);
if
(
rjx
.
getCode
()
==
200
)
{
displayInLog
=
false
;
}
}
else
{
}
else
{
mav
.
addAllObjects
(
Rjx
.
jsonErr
().
setMessage
(
"未处理异常["
+
ex
.
getClass
().
getName
()
+
":"
+
ex
.
getMessage
()
+
"]"
));
mav
.
addAllObjects
(
Rjx
.
jsonErr
().
setMessage
(
"未处理异常["
+
ex
.
getClass
().
getName
()
+
":"
+
ex
.
getMessage
()
+
"]"
));
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
mav
.
addAllObjects
(
Rjx
.
jsonErr
().
setMessage
(
"异常处理失败"
));
mav
.
addAllObjects
(
Rjx
.
jsonErr
().
setMessage
(
"异常处理失败"
));
}
finally
{
if
(
displayInLog
)
{
logger
.
error
(
""
,
ex
);
}
}
}
return
mav
;
return
mav
;
}
}
...
...
src/main/java/com/egolm/film/config/XException.java
View file @
d0a8e3fc
...
@@ -34,10 +34,12 @@ public class XException extends RuntimeException {
...
@@ -34,10 +34,12 @@ public class XException extends RuntimeException {
return
rjx
;
return
rjx
;
}
}
public
static
void
assertNotBlank
(
Object
obj
,
String
message
)
{
public
static
void
assertNotBlank
(
String
message
,
Object
...
objs
)
{
for
(
Object
obj
:
objs
)
{
if
(
obj
==
null
||
obj
.
toString
().
trim
().
equals
(
""
))
{
if
(
obj
==
null
||
obj
.
toString
().
trim
().
equals
(
""
))
{
throw
new
XException
((
message
==
null
||
message
.
trim
().
equals
(
""
))
?
"对象不能为空"
:
message
);
throw
new
XException
((
message
==
null
||
message
.
trim
().
equals
(
""
))
?
"对象不能为空"
:
message
);
}
}
}
}
}
}
}
src/main/java/com/egolm/film/login/AdminLoginController.java
View file @
d0a8e3fc
...
@@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
...
@@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
com.egolm.common.bean.Rjx
;
import
com.egolm.common.bean.Rjx
;
import
com.egolm.film.common.Messages
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.login.service.AdminTokenService
;
import
com.egolm.film.login.service.AdminTokenService
;
import
com.egolm.film.model.LoginToken
;
import
com.egolm.film.model.LoginToken
;
...
@@ -22,13 +23,15 @@ public class AdminLoginController {
...
@@ -22,13 +23,15 @@ public class AdminLoginController {
@Autowired
@Autowired
private
AdminTokenService
tokenService
;
private
AdminTokenService
tokenService
;
@Autowired
private
Messages
messages
;
@ResponseBody
@ResponseBody
@PostMapping
(
"login"
)
@PostMapping
(
"login"
)
@ApiOperation
(
"登陆"
)
@ApiOperation
(
"登陆"
)
public
Object
login
(
String
username
,
String
password
)
{
public
Object
login
(
String
username
,
String
password
)
{
XException
.
assertNotBlank
(
username
,
"用户名不能为空"
);
XException
.
assertNotBlank
(
messages
.
get
(
"sys.err.user_pwd_null"
),
username
,
password
);
XException
.
assertNotBlank
(
password
,
"密码不能为空"
);
if
(
tokenService
.
isLogin
())
{
if
(
tokenService
.
isLogin
())
{
throw
new
XException
(
"用户已登录"
,
200
);
throw
new
XException
(
"用户已登录"
,
200
);
}
else
{
}
else
{
...
@@ -36,7 +39,7 @@ public class AdminLoginController {
...
@@ -36,7 +39,7 @@ public class AdminLoginController {
if
(
token
!=
null
)
{
if
(
token
!=
null
)
{
return
Rjx
.
jsonOk
().
setData
(
token
);
return
Rjx
.
jsonOk
().
setData
(
token
);
}
else
{
}
else
{
throw
new
XException
(
"用户名或密码错误"
);
throw
new
XException
(
messages
.
get
(
"sys.err.user_or_pwd"
)
);
}
}
}
}
}
}
...
...
src/main/java/com/egolm/film/login/MemberLoginController.java
View file @
d0a8e3fc
...
@@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
...
@@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
com.egolm.common.bean.Rjx
;
import
com.egolm.common.bean.Rjx
;
import
com.egolm.film.common.Messages
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.login.service.MemberTokenService
;
import
com.egolm.film.login.service.MemberTokenService
;
import
com.egolm.film.model.LoginToken
;
import
com.egolm.film.model.LoginToken
;
...
@@ -19,6 +20,9 @@ import io.swagger.annotations.ApiOperation;
...
@@ -19,6 +20,9 @@ import io.swagger.annotations.ApiOperation;
@RequestMapping
(
"member"
)
@RequestMapping
(
"member"
)
public
class
MemberLoginController
{
public
class
MemberLoginController
{
@Autowired
private
Messages
messages
;
@Autowired
@Autowired
private
MemberTokenService
tokenService
;
private
MemberTokenService
tokenService
;
...
@@ -26,14 +30,15 @@ public class MemberLoginController {
...
@@ -26,14 +30,15 @@ public class MemberLoginController {
@PostMapping
(
"login"
)
@PostMapping
(
"login"
)
@ApiOperation
(
"登陆"
)
@ApiOperation
(
"登陆"
)
public
Object
login
(
String
username
,
String
password
)
{
public
Object
login
(
String
username
,
String
password
)
{
XException
.
assertNotBlank
(
messages
.
get
(
"sys.err.user_pwd_null"
),
username
,
password
);
if
(
tokenService
.
isLogin
())
{
if
(
tokenService
.
isLogin
())
{
throw
new
XException
(
"
用户已登录
"
,
200
);
throw
new
XException
(
""
,
200
);
}
else
{
}
else
{
LoginToken
token
=
tokenService
.
doLogin
(
username
,
password
);
LoginToken
token
=
tokenService
.
doLogin
(
username
,
password
);
if
(
token
!=
null
)
{
if
(
token
!=
null
)
{
return
Rjx
.
jsonOk
().
setData
(
token
);
return
Rjx
.
jsonOk
().
setData
(
token
);
}
else
{
}
else
{
throw
new
XException
(
"用户名或密码错误"
);
throw
new
XException
(
messages
.
get
(
"sys.err.user_or_pwd"
)
);
}
}
}
}
}
}
...
...
src/main/java/com/egolm/film/login/UserLoginController.java
View file @
d0a8e3fc
...
@@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
...
@@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
com.egolm.common.bean.Rjx
;
import
com.egolm.common.bean.Rjx
;
import
com.egolm.film.common.Messages
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.login.service.UserTokenService
;
import
com.egolm.film.login.service.UserTokenService
;
import
com.egolm.film.model.LoginToken
;
import
com.egolm.film.model.LoginToken
;
...
@@ -22,18 +23,22 @@ public class UserLoginController {
...
@@ -22,18 +23,22 @@ public class UserLoginController {
@Autowired
@Autowired
private
UserTokenService
tokenService
;
private
UserTokenService
tokenService
;
@Autowired
private
Messages
messages
;
@ResponseBody
@ResponseBody
@PostMapping
(
"login"
)
@PostMapping
(
"login"
)
@ApiOperation
(
"登陆"
)
@ApiOperation
(
"登陆"
)
public
Object
login
(
String
username
,
String
password
)
{
public
Object
login
(
String
username
,
String
password
)
{
XException
.
assertNotBlank
(
messages
.
get
(
"sys.err.user_pwd_null"
),
username
,
password
);
if
(
tokenService
.
isLogin
())
{
if
(
tokenService
.
isLogin
())
{
throw
new
XException
(
"
用户已登录
"
,
200
);
throw
new
XException
(
""
,
200
);
}
else
{
}
else
{
LoginToken
token
=
tokenService
.
doLogin
(
username
,
password
);
LoginToken
token
=
tokenService
.
doLogin
(
username
,
password
);
if
(
token
!=
null
)
{
if
(
token
!=
null
)
{
return
Rjx
.
jsonOk
().
setData
(
token
);
return
Rjx
.
jsonOk
().
setData
(
token
);
}
else
{
}
else
{
throw
new
XException
(
"用户名或密码错误"
);
throw
new
XException
(
messages
.
get
(
"sys.err.user_or_pwd"
)
);
}
}
}
}
}
}
...
...
src/main/java/com/egolm/film/login/service/impl/MemberTokenServiceImpl.java
View file @
d0a8e3fc
...
@@ -46,12 +46,12 @@ public class MemberTokenServiceImpl implements MemberTokenService {
...
@@ -46,12 +46,12 @@ public class MemberTokenServiceImpl implements MemberTokenService {
throw
new
XException
(
messages
.
get
(
"sys.err"
));
throw
new
XException
(
messages
.
get
(
"sys.err"
));
}
}
}
else
if
(
list
.
size
()
==
0
)
{
}
else
if
(
list
.
size
()
==
0
)
{
throw
new
XException
(
messages
.
get
(
"sys.err.user_
or_pwd
"
));
throw
new
XException
(
messages
.
get
(
"sys.err.user_
pwd_err
"
));
}
else
{
}
else
{
throw
new
XException
(
messages
.
get
(
"sys.err"
));
throw
new
XException
(
messages
.
get
(
"sys.err"
));
}
}
}
else
{
}
else
{
throw
new
XException
(
messages
.
get
(
"sys.err.user_
or_pwd
"
));
throw
new
XException
(
messages
.
get
(
"sys.err.user_
pwd_err
"
));
}
}
}
}
...
...
src/main/resources/i18n/message.properties
View file @
d0a8e3fc
...
@@ -3,7 +3,8 @@ email.getPassword.content={0}, \u60A8\u597D, \u60A8\u7684\u65B0\u5BC6\u7801\u662
...
@@ -3,7 +3,8 @@ email.getPassword.content={0}, \u60A8\u597D, \u60A8\u7684\u65B0\u5BC6\u7801\u662
sys.err
=
\u
7CFB
\u
7EDF
\u9519\u
8BEF
sys.err
=
\u
7CFB
\u
7EDF
\u9519\u
8BEF
sys.err.user_disabled
=
\u7528\u6237\u
5DF2
\u
7ECF
\u7981\u7528
sys.err.user_disabled
=
\u7528\u6237\u
5DF2
\u
7ECF
\u7981\u7528
sys.err.user_or_pwd=
\u7528\u6237\u6216\u
5BC6
\u7801\u9519\u
8BEF
sys.err.user_pwd_err=
\u7528\u6237\u6216\u
5BC6
\u7801\u9519\u
8BEF
sys.err.user_pwd_null
=
\u7528\u6237\u
540D
\u
548C
\u
5BC6
\u7801\u
4E0D
\u
80FD
\u
4E3A
\u
7A7A
msg.hello
=
\u
60A8
\u
597D
msg.hello
=
\u
60A8
\u
597D
msg.your_pwd
=
\u
60A8
\u7684\u
5BC6
\u7801\u
662F
msg.your_pwd
=
\u
60A8
\u7684\u
5BC6
\u7801\u
662F
\ No newline at end of file
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