1
|
package com.xkl.controller;
|
1
|
package com.xkl.controller;
|
2
|
|
2
|
|
|
|
3
|
+import com.wordnik.swagger.annotations.ApiImplicitParam;
|
|
|
4
|
+import com.wordnik.swagger.annotations.ApiImplicitParams;
|
3
|
import com.wordnik.swagger.annotations.ApiOperation;
|
5
|
import com.wordnik.swagger.annotations.ApiOperation;
|
4
|
import com.xkl.authorization.annotation.Authorization;
|
6
|
import com.xkl.authorization.annotation.Authorization;
|
5
|
import com.xkl.authorization.annotation.CurrentUser;
|
7
|
import com.xkl.authorization.annotation.CurrentUser;
|
|
@@ -12,10 +14,7 @@ import com.xkl.config.ResultStatus; |
|
@@ -12,10 +14,7 @@ import com.xkl.config.ResultStatus; |
12
|
import com.xkl.domain.*;
|
14
|
import com.xkl.domain.*;
|
13
|
import com.xkl.model.ReportDetailModel;
|
15
|
import com.xkl.model.ReportDetailModel;
|
14
|
import com.xkl.model.ResultModel;
|
16
|
import com.xkl.model.ResultModel;
|
15
|
-import com.xkl.repository.XklAmpReportDetailRespository;
|
|
|
16
|
-import com.xkl.repository.XklAmpReportHealthScoreRespository;
|
|
|
17
|
-import com.xkl.repository.XklAmpReportRespository;
|
|
|
18
|
-import com.xkl.repository.XklMemberOpenidRespository;
|
17
|
+import com.xkl.repository.*;
|
19
|
import com.xkl.security.AntiXSS;
|
18
|
import com.xkl.security.AntiXSS;
|
20
|
import com.xkl.service.ILoginService;
|
19
|
import com.xkl.service.ILoginService;
|
21
|
import org.springframework.beans.factory.annotation.Autowired;
|
20
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -43,15 +42,17 @@ public class OpenIdController { |
|
@@ -43,15 +42,17 @@ public class OpenIdController { |
43
|
private ILoginService loginService;
|
42
|
private ILoginService loginService;
|
44
|
@Autowired
|
43
|
@Autowired
|
45
|
private XklMemberOpenidRespository xklMemberOpenidRespository;
|
44
|
private XklMemberOpenidRespository xklMemberOpenidRespository;
|
|
|
45
|
+ @Autowired
|
|
|
46
|
+ private UserRepository userRepository;
|
46
|
|
47
|
|
47
|
@LogAnnotation
|
48
|
@LogAnnotation
|
48
|
@AntiXSS
|
49
|
@AntiXSS
|
49
|
@Sign
|
50
|
@Sign
|
50
|
@RequestMapping(method = RequestMethod.POST)
|
51
|
@RequestMapping(method = RequestMethod.POST)
|
51
|
@ApiOperation(value = "OpenId绑定接口")
|
52
|
@ApiOperation(value = "OpenId绑定接口")
|
52
|
- public ResponseEntity<ResultModel> openIdBind(HttpServletRequest request,@RequestParam String username, @RequestParam String password, @RequestParam String openId, @RequestParam int openIdType,
|
|
|
53
|
- @RequestParam String sign,@RequestParam long t,@RequestParam int type) {
|
|
|
54
|
- if(!(boolean)request.getAttribute("signAspect"))
|
53
|
+ public ResponseEntity<ResultModel> openIdBind(HttpServletRequest request, @RequestParam String username, @RequestParam String password, @RequestParam String openId, @RequestParam int openIdType,
|
|
|
54
|
+ @RequestParam String sign, @RequestParam long t, @RequestParam int type) {
|
|
|
55
|
+ if (!(boolean) request.getAttribute("signAspect"))
|
55
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
|
56
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
|
56
|
|
57
|
|
57
|
Assert.notNull(username, "username can not be empty");
|
58
|
Assert.notNull(username, "username can not be empty");
|
|
@@ -62,14 +63,14 @@ public class OpenIdController { |
|
@@ -62,14 +63,14 @@ public class OpenIdController { |
62
|
if (user == null) {//用户,密码错误
|
63
|
if (user == null) {//用户,密码错误
|
63
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.OK);
|
64
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.OK);
|
64
|
} else {
|
65
|
} else {
|
65
|
- XklMemberOpenidEntity xklMemberOpenid=xklMemberOpenidRespository.findByAccountIdAndType(user.getId(),openIdType);
|
|
|
66
|
- if(xklMemberOpenid == null ){
|
66
|
+ XklMemberOpenidEntity xklMemberOpenid = xklMemberOpenidRespository.findByAccountIdAndType(user.getId(), openIdType);
|
|
|
67
|
+ if (xklMemberOpenid == null) {
|
67
|
xklMemberOpenid = new XklMemberOpenidEntity();
|
68
|
xklMemberOpenid = new XklMemberOpenidEntity();
|
68
|
xklMemberOpenid.setType(openIdType);
|
69
|
xklMemberOpenid.setType(openIdType);
|
69
|
xklMemberOpenid.setAccountId(user.getId());
|
70
|
xklMemberOpenid.setAccountId(user.getId());
|
70
|
xklMemberOpenid.setMemberId(user.getMemberId());
|
71
|
xklMemberOpenid.setMemberId(user.getMemberId());
|
71
|
xklMemberOpenid.setOpenid(openId);
|
72
|
xklMemberOpenid.setOpenid(openId);
|
72
|
- }else{//已经存在
|
73
|
+ } else {//已经存在
|
73
|
xklMemberOpenid.setOpenid(openId);
|
74
|
xklMemberOpenid.setOpenid(openId);
|
74
|
}
|
75
|
}
|
75
|
xklMemberOpenidRespository.save(xklMemberOpenid);
|
76
|
xklMemberOpenidRespository.save(xklMemberOpenid);
|
|
@@ -77,53 +78,55 @@ public class OpenIdController { |
|
@@ -77,53 +78,55 @@ public class OpenIdController { |
77
|
return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_BIND_SUCCESS), HttpStatus.OK);
|
78
|
return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_BIND_SUCCESS), HttpStatus.OK);
|
78
|
}
|
79
|
}
|
79
|
|
80
|
|
|
|
81
|
+
|
80
|
@LogAnnotation
|
82
|
@LogAnnotation
|
81
|
@AntiXSS
|
83
|
@AntiXSS
|
|
|
84
|
+ @Authorization
|
82
|
@Sign
|
85
|
@Sign
|
83
|
@RequestMapping(method = RequestMethod.DELETE)
|
86
|
@RequestMapping(method = RequestMethod.DELETE)
|
84
|
@ApiOperation(value = "OpenId解除绑定接口")
|
87
|
@ApiOperation(value = "OpenId解除绑定接口")
|
85
|
- public ResponseEntity<ResultModel> openIdUnBind(HttpServletRequest request,@RequestParam String username,@RequestParam String password,@RequestParam String openId, @RequestParam int openIdType,
|
|
|
86
|
- @RequestParam String sign,@RequestParam long t,@RequestParam int type) {
|
|
|
87
|
- if(!(boolean)request.getAttribute("signAspect"))
|
88
|
+ @ApiImplicitParams({
|
|
|
89
|
+ @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
|
|
|
90
|
+ })
|
|
|
91
|
+ public ResponseEntity<ResultModel> openIdUnBind(HttpServletRequest request, @CurrentUser User user, @RequestParam String openId, @RequestParam int openIdType,
|
|
|
92
|
+ @RequestParam String sign, @RequestParam long t, @RequestParam int type) {
|
|
|
93
|
+ if (!(boolean) request.getAttribute("signAspect"))
|
88
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
|
94
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
|
89
|
|
95
|
|
90
|
- Assert.notNull(username, "username can not be empty");
|
|
|
91
|
- Assert.notNull(password, "password can not be empty");
|
|
|
92
|
-
|
|
|
93
|
- User user = loginService.check(username, password);
|
|
|
94
|
-
|
|
|
95
|
- if (user == null) {//用户,密码错误
|
|
|
96
|
- return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.OK);
|
96
|
+ XklMemberOpenidEntity xklMemberOpenid = xklMemberOpenidRespository.findByAccountIdAndTypeAndOpenid(user.getId(), openIdType, openId);
|
|
|
97
|
+ if (xklMemberOpenid != null) {
|
|
|
98
|
+ xklMemberOpenidRespository.delete(xklMemberOpenid);
|
|
|
99
|
+ return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_UNBIND_SUCESS), HttpStatus.OK);
|
97
|
} else {
|
100
|
} else {
|
98
|
- XklMemberOpenidEntity xklMemberOpenid = xklMemberOpenidRespository.findByAccountIdAndTypeAndOpenid(user.getId(), openIdType,openId);
|
|
|
99
|
- if(xklMemberOpenid!=null) {
|
|
|
100
|
- xklMemberOpenidRespository.delete(xklMemberOpenid);
|
|
|
101
|
- }else{
|
|
|
102
|
- return new ResponseEntity<>(ResultModel.error(ResultStatus.OPENID_ERROR), HttpStatus.OK);
|
|
|
103
|
- }
|
101
|
+ return new ResponseEntity<>(ResultModel.error(ResultStatus.OPENID_ERROR), HttpStatus.OK);
|
104
|
}
|
102
|
}
|
105
|
- return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_UNBIND_SUCESS), HttpStatus.OK);
|
|
|
106
|
}
|
103
|
}
|
107
|
|
104
|
|
|
|
105
|
+
|
108
|
@LogAnnotation
|
106
|
@LogAnnotation
|
109
|
@AntiXSS
|
107
|
@AntiXSS
|
110
|
@Sign
|
108
|
@Sign
|
111
|
- @RequestMapping(value="/login",method = RequestMethod.POST)
|
109
|
+ @RequestMapping(value = "/login", method = RequestMethod.POST)
|
112
|
@ApiOperation(value = "OpenId登录接口")
|
110
|
@ApiOperation(value = "OpenId登录接口")
|
113
|
- public ResponseEntity<ResultModel> openIdLogin(HttpServletRequest request,@RequestParam String openId, @RequestParam int openIdType,
|
|
|
114
|
- @RequestParam String sign,@RequestParam long t,@RequestParam int type) {
|
|
|
115
|
- if(!(boolean)request.getAttribute("signAspect"))
|
111
|
+ public ResponseEntity<ResultModel> openIdLogin(HttpServletRequest request, @RequestParam String openId, @RequestParam int openIdType,
|
|
|
112
|
+ @RequestParam String sign, @RequestParam long t, @RequestParam int type) {
|
|
|
113
|
+ if (!(boolean) request.getAttribute("signAspect"))
|
116
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
|
114
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
|
117
|
|
115
|
|
118
|
XklMemberOpenidEntity xklMemberOpenid = xklMemberOpenidRespository.findByOpenidAndType(openId, openIdType);
|
116
|
XklMemberOpenidEntity xklMemberOpenid = xklMemberOpenidRespository.findByOpenidAndType(openId, openIdType);
|
119
|
|
117
|
|
120
|
- if(xklMemberOpenid == null){
|
118
|
+ if (xklMemberOpenid == null) {
|
121
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.OPENID_ERROR), HttpStatus.OK);
|
119
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.OPENID_ERROR), HttpStatus.OK);
|
122
|
}
|
120
|
}
|
123
|
long accountId = xklMemberOpenid.getAccountId();
|
121
|
long accountId = xklMemberOpenid.getAccountId();
|
124
|
TokenModel model = tokenManager.createToken(String.valueOf(accountId));
|
122
|
TokenModel model = tokenManager.createToken(String.valueOf(accountId));
|
125
|
-
|
|
|
126
|
- return new ResponseEntity<>(ResultModel.ok(model), HttpStatus.OK);
|
123
|
+ User user = userRepository.findOne(accountId);
|
|
|
124
|
+ if (user.isStatus() == true) {
|
|
|
125
|
+ model.setAccount(user.getLoginAccount());
|
|
|
126
|
+ return new ResponseEntity<>(ResultModel.ok(model), HttpStatus.OK);
|
|
|
127
|
+ } else {
|
|
|
128
|
+ return new ResponseEntity<>(ResultModel.error(ResultStatus.USER_NOT_FOUND), HttpStatus.OK);
|
|
|
129
|
+ }
|
127
|
}
|
130
|
}
|
128
|
|
131
|
|
129
|
} |
132
|
} |