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
d0a8e3fc
Commit
d0a8e3fc
authored
Oct 10, 2018
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化消息提醒
parent
8543f53a
Hide 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;
@Component
public
class
ExceptionHandler
implements
HandlerExceptionResolver
{
private
Logger
logger
=
Logger
.
getLogger
(
ExceptionHandler
.
class
);
private
static
final
Logger
logger
=
Logger
.
getLogger
(
ExceptionHandler
.
class
);
@Override
public
ModelAndView
resolveException
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
ex
)
{
logger
.
error
(
""
,
ex
)
;
boolean
displayInLog
=
true
;
ModelAndView
mav
=
new
ModelAndView
(
new
MappingJackson2JsonView
());
try
{
response
.
setContentType
(
"application/json"
);
if
(
ex
instanceof
XException
)
{
mav
.
addAllObjects
(((
XException
)
ex
).
getRjx
());
Rjx
rjx
=
((
XException
)
ex
).
getRjx
();
mav
.
addAllObjects
(
rjx
);
if
(
rjx
.
getCode
()
==
200
)
{
displayInLog
=
false
;
}
}
else
{
mav
.
addAllObjects
(
Rjx
.
jsonErr
().
setMessage
(
"未处理异常["
+
ex
.
getClass
().
getName
()
+
":"
+
ex
.
getMessage
()
+
"]"
));
}
}
catch
(
Exception
e
)
{
mav
.
addAllObjects
(
Rjx
.
jsonErr
().
setMessage
(
"异常处理失败"
));
}
finally
{
if
(
displayInLog
)
{
logger
.
error
(
""
,
ex
);
}
}
return
mav
;
}
...
...
src/main/java/com/egolm/film/config/XException.java
View file @
d0a8e3fc
...
...
@@ -34,9 +34,11 @@ public class XException extends RuntimeException {
return
rjx
;
}
public
static
void
assertNotBlank
(
Object
obj
,
String
message
)
{
if
(
obj
==
null
||
obj
.
toString
().
trim
().
equals
(
""
))
{
throw
new
XException
((
message
==
null
||
message
.
trim
().
equals
(
""
))
?
"对象不能为空"
:
message
);
public
static
void
assertNotBlank
(
String
message
,
Object
...
objs
)
{
for
(
Object
obj
:
objs
)
{
if
(
obj
==
null
||
obj
.
toString
().
trim
().
equals
(
""
))
{
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;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
com.egolm.common.bean.Rjx
;
import
com.egolm.film.common.Messages
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.login.service.AdminTokenService
;
import
com.egolm.film.model.LoginToken
;
...
...
@@ -21,14 +22,16 @@ public class AdminLoginController {
@Autowired
private
AdminTokenService
tokenService
;
@Autowired
private
Messages
messages
;
@ResponseBody
@PostMapping
(
"login"
)
@ApiOperation
(
"登陆"
)
public
Object
login
(
String
username
,
String
password
)
{
XException
.
assertNotBlank
(
username
,
"用户名不能为空"
);
XException
.
assertNotBlank
(
password
,
"密码不能为空"
);
XException
.
assertNotBlank
(
messages
.
get
(
"sys.err.user_pwd_null"
),
username
,
password
);
if
(
tokenService
.
isLogin
())
{
throw
new
XException
(
"用户已登录"
,
200
);
}
else
{
...
...
@@ -36,7 +39,7 @@ public class AdminLoginController {
if
(
token
!=
null
)
{
return
Rjx
.
jsonOk
().
setData
(
token
);
}
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;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
com.egolm.common.bean.Rjx
;
import
com.egolm.film.common.Messages
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.login.service.MemberTokenService
;
import
com.egolm.film.model.LoginToken
;
...
...
@@ -19,6 +20,9 @@ import io.swagger.annotations.ApiOperation;
@RequestMapping
(
"member"
)
public
class
MemberLoginController
{
@Autowired
private
Messages
messages
;
@Autowired
private
MemberTokenService
tokenService
;
...
...
@@ -26,14 +30,15 @@ public class MemberLoginController {
@PostMapping
(
"login"
)
@ApiOperation
(
"登陆"
)
public
Object
login
(
String
username
,
String
password
)
{
XException
.
assertNotBlank
(
messages
.
get
(
"sys.err.user_pwd_null"
),
username
,
password
);
if
(
tokenService
.
isLogin
())
{
throw
new
XException
(
"
用户已登录
"
,
200
);
throw
new
XException
(
""
,
200
);
}
else
{
LoginToken
token
=
tokenService
.
doLogin
(
username
,
password
);
if
(
token
!=
null
)
{
return
Rjx
.
jsonOk
().
setData
(
token
);
}
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;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
com.egolm.common.bean.Rjx
;
import
com.egolm.film.common.Messages
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.login.service.UserTokenService
;
import
com.egolm.film.model.LoginToken
;
...
...
@@ -21,19 +22,23 @@ public class UserLoginController {
@Autowired
private
UserTokenService
tokenService
;
@Autowired
private
Messages
messages
;
@ResponseBody
@PostMapping
(
"login"
)
@ApiOperation
(
"登陆"
)
public
Object
login
(
String
username
,
String
password
)
{
XException
.
assertNotBlank
(
messages
.
get
(
"sys.err.user_pwd_null"
),
username
,
password
);
if
(
tokenService
.
isLogin
())
{
throw
new
XException
(
"
用户已登录
"
,
200
);
throw
new
XException
(
""
,
200
);
}
else
{
LoginToken
token
=
tokenService
.
doLogin
(
username
,
password
);
if
(
token
!=
null
)
{
return
Rjx
.
jsonOk
().
setData
(
token
);
}
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 {
throw
new
XException
(
messages
.
get
(
"sys.err"
));
}
}
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
{
throw
new
XException
(
messages
.
get
(
"sys.err"
));
}
}
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
sys.err
=
\u
7CFB
\u
7EDF
\u9519\u
8BEF
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.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