|
|
package com.xkl.controller;
|
|
|
|
|
|
import com.wordnik.swagger.annotations.ApiOperation;
|
|
|
import com.xkl.authorization.manager.ITokenManager;
|
|
|
import com.xkl.config.ResultStatus;
|
|
|
import com.xkl.domain.User;
|
|
|
import com.xkl.domain.XklMemberOpenidEntity;
|
|
|
import com.xkl.model.ResultModel;
|
|
|
import com.xkl.repository.XklMemberOpenidRespository;
|
|
|
import com.xkl.security.AntiXSS;
|
|
|
import com.xkl.service.ILoginService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.util.Assert;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
/**
|
|
|
* Created by win7 on 2016/10/19.
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/openId")
|
|
|
public class OpenIdController {
|
|
|
@Autowired
|
|
|
private ITokenManager tokenManager;
|
|
|
@Autowired
|
|
|
private ILoginService loginService;
|
|
|
@Autowired
|
|
|
private XklMemberOpenidRespository xklMemberOpenidRespository;
|
|
|
|
|
|
@AntiXSS
|
|
|
//@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,
|
|
|
@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");
|
|
|
|
|
|
User user = loginService.check(username, password);
|
|
|
|
|
|
if (user == null) {//用户,密码错误
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND);
|
|
|
} else {
|
|
|
XklMemberOpenidEntity xklMemberOpenid=xklMemberOpenidRespository.findByMemberIdAndType(user.getMemberId(),openIdtype);
|
|
|
if(xklMemberOpenid == null ){
|
|
|
xklMemberOpenid = new XklMemberOpenidEntity();
|
|
|
xklMemberOpenid.setType(openIdtype);
|
|
|
xklMemberOpenid.setMemberId(user.getMemberId());
|
|
|
xklMemberOpenid.setOpenid(openId);
|
|
|
}else{//已经存在
|
|
|
xklMemberOpenid.setOpenid(openId);
|
|
|
}
|
|
|
xklMemberOpenidRespository.save(xklMemberOpenid);
|
|
|
}
|
|
|
return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_BIND_SUCCESS), HttpStatus.OK);
|
|
|
}
|
|
|
|
|
|
|
|
|
@AntiXSS
|
|
|
//@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,
|
|
|
@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");
|
|
|
|
|
|
User user = loginService.check(username, password);
|
|
|
|
|
|
if (user == null) {//用户,密码错误
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND);
|
|
|
} else {
|
|
|
XklMemberOpenidEntity xklMemberOpenid = xklMemberOpenidRespository.findByMemberIdAndTypeAndOpenid(user.getMemberId(), openIdtype,openId);
|
|
|
if(xklMemberOpenid!=null) {
|
|
|
xklMemberOpenidRespository.delete(xklMemberOpenid);
|
|
|
}else{
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.OPENID_ERROR), HttpStatus.NOT_FOUND);
|
|
|
}
|
|
|
}
|
|
|
return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_UNBIND_SUCESS), HttpStatus.OK);
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|