|
|
package com.xkl.controller;
|
|
|
|
|
|
import com.wordnik.swagger.annotations.ApiOperation;
|
|
|
import com.xkl.authorization.annotation.Sign;
|
|
|
import com.xkl.authorization.manager.ITokenManager;
|
|
|
import com.xkl.authorization.model.TokenModel;
|
|
|
import com.xkl.config.ResultStatus;
|
...
|
...
|
@@ -35,10 +36,10 @@ public class OpenIdController { |
|
|
private XklMemberOpenidRespository xklMemberOpenidRespository;
|
|
|
|
|
|
@AntiXSS
|
|
|
//@Sign
|
|
|
@Sign
|
|
|
@RequestMapping(method = RequestMethod.POST)
|
|
|
@ApiOperation(value = "OpenId绑定接口")
|
|
|
public ResponseEntity<ResultModel> openIdBind(HttpServletRequest request,@RequestParam String username, @RequestParam String password, @RequestParam String openId, @RequestParam int openIdtype,
|
|
|
public ResponseEntity<ResultModel> openIdBind(HttpServletRequest request,@RequestParam String username, @RequestParam String password, @RequestParam String openId, @RequestParam int openIdType,
|
|
|
@RequestParam String sign,@RequestParam long t,@RequestParam int type) {
|
|
|
Assert.notNull(username, "username can not be empty");
|
|
|
Assert.notNull(password, "password can not be empty");
|
...
|
...
|
@@ -46,12 +47,12 @@ public class OpenIdController { |
|
|
User user = loginService.check(username, password);
|
|
|
|
|
|
if (user == null) {//用户,密码错误
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND);
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.OK);
|
|
|
} else {
|
|
|
XklMemberOpenidEntity xklMemberOpenid=xklMemberOpenidRespository.findByAccountIdAndType(user.getId(),openIdtype);
|
|
|
XklMemberOpenidEntity xklMemberOpenid=xklMemberOpenidRespository.findByAccountIdAndType(user.getId(),openIdType);
|
|
|
if(xklMemberOpenid == null ){
|
|
|
xklMemberOpenid = new XklMemberOpenidEntity();
|
|
|
xklMemberOpenid.setType(openIdtype);
|
|
|
xklMemberOpenid.setType(openIdType);
|
|
|
xklMemberOpenid.setAccountId(user.getId());
|
|
|
xklMemberOpenid.setMemberId(user.getMemberId());
|
|
|
xklMemberOpenid.setOpenid(openId);
|
...
|
...
|
@@ -65,10 +66,10 @@ public class OpenIdController { |
|
|
|
|
|
|
|
|
@AntiXSS
|
|
|
//@Sign
|
|
|
@Sign
|
|
|
@RequestMapping(method = RequestMethod.DELETE)
|
|
|
@ApiOperation(value = "OpenId解除绑定接口")
|
|
|
public ResponseEntity<ResultModel> openIdUnBind(HttpServletRequest request,@RequestParam String username,@RequestParam String password,@RequestParam String openId, @RequestParam int openIdtype,
|
|
|
public ResponseEntity<ResultModel> openIdUnBind(HttpServletRequest request,@RequestParam String username,@RequestParam String password,@RequestParam String openId, @RequestParam int openIdType,
|
|
|
@RequestParam String sign,@RequestParam long t,@RequestParam int type) {
|
|
|
Assert.notNull(username, "username can not be empty");
|
|
|
Assert.notNull(password, "password can not be empty");
|
...
|
...
|
@@ -76,28 +77,28 @@ public class OpenIdController { |
|
|
User user = loginService.check(username, password);
|
|
|
|
|
|
if (user == null) {//用户,密码错误
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND);
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.OK);
|
|
|
} else {
|
|
|
XklMemberOpenidEntity xklMemberOpenid = xklMemberOpenidRespository.findByAccountIdAndTypeAndOpenid(user.getId(), openIdtype,openId);
|
|
|
XklMemberOpenidEntity xklMemberOpenid = xklMemberOpenidRespository.findByAccountIdAndTypeAndOpenid(user.getId(), openIdType,openId);
|
|
|
if(xklMemberOpenid!=null) {
|
|
|
xklMemberOpenidRespository.delete(xklMemberOpenid);
|
|
|
}else{
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.OPENID_ERROR), HttpStatus.NOT_FOUND);
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.OPENID_ERROR), HttpStatus.OK);
|
|
|
}
|
|
|
}
|
|
|
return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_UNBIND_SUCESS), HttpStatus.OK);
|
|
|
}
|
|
|
|
|
|
@AntiXSS
|
|
|
//@Sign
|
|
|
@Sign
|
|
|
@RequestMapping(value="/login",method = RequestMethod.POST)
|
|
|
@ApiOperation(value = "OpenId登录接口")
|
|
|
public ResponseEntity<ResultModel> openIdLogin(HttpServletRequest request,@RequestParam String openId, @RequestParam int openIdtype,
|
|
|
public ResponseEntity<ResultModel> openIdLogin(HttpServletRequest request,@RequestParam String openId, @RequestParam int openIdType,
|
|
|
@RequestParam String sign,@RequestParam long t,@RequestParam int type) {
|
|
|
XklMemberOpenidEntity xklMemberOpenid = xklMemberOpenidRespository.findByOpenidAndType(openId, openIdtype);
|
|
|
XklMemberOpenidEntity xklMemberOpenid = xklMemberOpenidRespository.findByOpenidAndType(openId, openIdType);
|
|
|
|
|
|
if(xklMemberOpenid == null){
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.OPENID_ERROR), HttpStatus.NOT_FOUND);
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.OPENID_ERROR), HttpStatus.OK);
|
|
|
}
|
|
|
long accountId = xklMemberOpenid.getId();
|
|
|
TokenModel model = tokenManager.createToken(String.valueOf(accountId));
|
...
|
...
|
|