Authored by fangyeqing

ADD:add openid login interface

... ... @@ -2,6 +2,7 @@ package com.xkl.controller;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xkl.authorization.manager.ITokenManager;
import com.xkl.authorization.model.TokenModel;
import com.xkl.config.ResultStatus;
import com.xkl.domain.User;
import com.xkl.domain.XklMemberOpenidEntity;
... ... @@ -47,10 +48,11 @@ public class OpenIdController {
if (user == null) {//用户,密码错误
return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.NOT_FOUND);
} else {
XklMemberOpenidEntity xklMemberOpenid=xklMemberOpenidRespository.findByMemberIdAndType(user.getMemberId(),openIdtype);
XklMemberOpenidEntity xklMemberOpenid=xklMemberOpenidRespository.findByAccountIdAndType(user.getId(),openIdtype);
if(xklMemberOpenid == null ){
xklMemberOpenid = new XklMemberOpenidEntity();
xklMemberOpenid.setType(openIdtype);
xklMemberOpenid.setAccountId(user.getId());
xklMemberOpenid.setMemberId(user.getMemberId());
xklMemberOpenid.setOpenid(openId);
}else{//已经存在
... ... @@ -76,7 +78,7 @@ public class OpenIdController {
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);
XklMemberOpenidEntity xklMemberOpenid = xklMemberOpenidRespository.findByAccountIdAndTypeAndOpenid(user.getId(), openIdtype,openId);
if(xklMemberOpenid!=null) {
xklMemberOpenidRespository.delete(xklMemberOpenid);
}else{
... ... @@ -86,4 +88,24 @@ public class OpenIdController {
return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_UNBIND_SUCESS), HttpStatus.OK);
}
@AntiXSS
//@Sign
@RequestMapping(value="/login",method = RequestMethod.POST)
@ApiOperation(value = "OpenId登录接口")
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);
if(xklMemberOpenid == null){
return new ResponseEntity<>(ResultModel.error(ResultStatus.OPENID_ERROR), HttpStatus.NOT_FOUND);
}
long accountId = xklMemberOpenid.getId();
TokenModel model = tokenManager.createToken(String.valueOf(accountId));
return new ResponseEntity<>(ResultModel.ok(model), HttpStatus.OK);
}
}
... ...
... ... @@ -91,7 +91,7 @@ public class UserInfoController {
user.setSalt(salt);
userRepository.save(user);
tokenManager.deleteToken(String.valueOf(user.getId()));//退出登录
return new ResponseEntity<>(ResultModel.ok(ResultStatus.USER_MODPASS_LOGOUT), HttpStatus.OK);
return new ResponseEntity<>(new ResultModel(ResultStatus.USER_MODPASS_LOGOUT), HttpStatus.OK);
}
@RequestMapping(method = RequestMethod.GET)
... ...
... ... @@ -16,6 +16,9 @@ public class XklMemberOpenidEntity {
@Column(name = "id")
private long id;
@Basic
@Column(name = "account_id")
private long accountId;
@Basic
@Column(name = "member_id")
private long memberId;
@Basic
... ...
... ... @@ -66,6 +66,10 @@ public class ResultModel {
return new ResultModel(ResultStatus.SUCCESS);
}
public static ResultModel ok(ResultStatus ok) {
return new ResultModel(ok);
}
public static ResultModel error(ResultStatus error) {
return new ResultModel(error);
}
... ...
... ... @@ -7,7 +7,9 @@ import org.springframework.data.repository.CrudRepository;
* Created by win7 on 2016/11/20.
*/
public interface XklMemberOpenidRespository extends CrudRepository<XklMemberOpenidEntity, Long> {
public XklMemberOpenidEntity findByMemberIdAndType(long memberId, int type);
public XklMemberOpenidEntity findByAccountIdAndType(long accountId, int type);
public XklMemberOpenidEntity findByMemberIdAndTypeAndOpenid(long memberId, int type, String openid);
public XklMemberOpenidEntity findByAccountIdAndTypeAndOpenid(long accountId, int type, String openid);
public XklMemberOpenidEntity findByOpenidAndType(String openid,int type);
}
... ...