Authored by zhaoyue

Merge branch 'zhaoyue-dev4' into 'master'

Zhaoyue dev4



See merge request !56
... ... @@ -2,7 +2,7 @@ git pull
git add --all src/main/java/*
git add push.sh
git add pom.xml
git commit -m "Add hasReport inter"
git commit -m "Add openid login return token;unbind pwd is necessary"
#git push origin master
git push origin zhaoyue-dev4
git status
... ...
... ... @@ -16,6 +16,14 @@ public class TokenModel {
//随机生成的uuid
private String token;
//使用openId 登录时,会返回该用户openid对应的account。
private String username;
public TokenModel(String userId, String token) {
this.userId = userId;
this.token = token;
}
public String getUserId() {
return userId;
}
... ... @@ -31,4 +39,12 @@ public class TokenModel {
public void setToken(String token) {
this.token = token;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
... ...
package com.xkl.controller;
import com.wordnik.swagger.annotations.ApiImplicitParam;
import com.wordnik.swagger.annotations.ApiImplicitParams;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xkl.authorization.annotation.Authorization;
import com.xkl.authorization.annotation.CurrentUser;
... ... @@ -12,10 +14,7 @@ import com.xkl.config.ResultStatus;
import com.xkl.domain.*;
import com.xkl.model.ReportDetailModel;
import com.xkl.model.ResultModel;
import com.xkl.repository.XklAmpReportDetailRespository;
import com.xkl.repository.XklAmpReportHealthScoreRespository;
import com.xkl.repository.XklAmpReportRespository;
import com.xkl.repository.XklMemberOpenidRespository;
import com.xkl.repository.*;
import com.xkl.security.AntiXSS;
import com.xkl.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -43,15 +42,17 @@ public class OpenIdController {
private ILoginService loginService;
@Autowired
private XklMemberOpenidRespository xklMemberOpenidRespository;
@Autowired
private UserRepository userRepository;
@LogAnnotation
@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) {
if(!(boolean)request.getAttribute("signAspect"))
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) {
if (!(boolean) request.getAttribute("signAspect"))
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
Assert.notNull(username, "username can not be empty");
... ... @@ -62,14 +63,14 @@ public class OpenIdController {
if (user == null) {//用户,密码错误
return new ResponseEntity<>(ResultModel.error(ResultStatus.USERNAME_OR_PASSWORD_ERROR), HttpStatus.OK);
} else {
XklMemberOpenidEntity xklMemberOpenid=xklMemberOpenidRespository.findByAccountIdAndType(user.getId(),openIdType);
if(xklMemberOpenid == null ){
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{//已经存在
} else {//已经存在
xklMemberOpenid.setOpenid(openId);
}
xklMemberOpenidRespository.save(xklMemberOpenid);
... ... @@ -77,53 +78,55 @@ public class OpenIdController {
return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_BIND_SUCCESS), HttpStatus.OK);
}
@LogAnnotation
@AntiXSS
@Authorization
@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) {
if(!(boolean)request.getAttribute("signAspect"))
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
})
public ResponseEntity<ResultModel> openIdUnBind(HttpServletRequest request, @CurrentUser User user, @RequestParam String openId, @RequestParam int openIdType,
@RequestParam String sign, @RequestParam long t, @RequestParam int type) {
if (!(boolean) request.getAttribute("signAspect"))
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
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.OK);
XklMemberOpenidEntity xklMemberOpenid = xklMemberOpenidRespository.findByAccountIdAndTypeAndOpenid(user.getId(), openIdType, openId);
if (xklMemberOpenid != null) {
xklMemberOpenidRespository.delete(xklMemberOpenid);
return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_UNBIND_SUCESS), HttpStatus.OK);
} else {
XklMemberOpenidEntity xklMemberOpenid = xklMemberOpenidRespository.findByAccountIdAndTypeAndOpenid(user.getId(), openIdType,openId);
if(xklMemberOpenid!=null) {
xklMemberOpenidRespository.delete(xklMemberOpenid);
}else{
return new ResponseEntity<>(ResultModel.error(ResultStatus.OPENID_ERROR), HttpStatus.OK);
}
return new ResponseEntity<>(ResultModel.error(ResultStatus.OPENID_ERROR), HttpStatus.OK);
}
return new ResponseEntity<>(ResultModel.ok(ResultStatus.OPENID_UNBIND_SUCESS), HttpStatus.OK);
}
@LogAnnotation
@AntiXSS
@Sign
@RequestMapping(value="/login",method = RequestMethod.POST)
@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) {
if(!(boolean)request.getAttribute("signAspect"))
public ResponseEntity<ResultModel> openIdLogin(HttpServletRequest request, @RequestParam String openId, @RequestParam int openIdType,
@RequestParam String sign, @RequestParam long t, @RequestParam int type) {
if (!(boolean) request.getAttribute("signAspect"))
return new ResponseEntity<>(ResultModel.error(ResultStatus.SIGN_ERROR), HttpStatus.OK);
XklMemberOpenidEntity xklMemberOpenid = xklMemberOpenidRespository.findByOpenidAndType(openId, openIdType);
if(xklMemberOpenid == null){
if (xklMemberOpenid == null) {
return new ResponseEntity<>(ResultModel.error(ResultStatus.OPENID_ERROR), HttpStatus.OK);
}
long accountId = xklMemberOpenid.getAccountId();
TokenModel model = tokenManager.createToken(String.valueOf(accountId));
return new ResponseEntity<>(ResultModel.ok(model), HttpStatus.OK);
User user = userRepository.findOne(accountId);
if (user.isStatus() == true) {
model.setUsername(user.getLoginAccount());
return new ResponseEntity<>(ResultModel.ok(model), HttpStatus.OK);
} else {
return new ResponseEntity<>(ResultModel.error(ResultStatus.USER_NOT_FOUND), HttpStatus.OK);
}
}
}
... ...
... ... @@ -54,6 +54,7 @@ public class TokenController {
}
//生成一个token,保存用户登录状态
TokenModel model = tokenManager.createToken(String.valueOf(user.getId()));
model.setUsername(user.getLoginAccount());
return new ResponseEntity<>(ResultModel.ok(model), HttpStatus.OK);
}
... ...