...
|
...
|
@@ -6,15 +6,19 @@ import com.xkl.config.Constants; |
|
|
import com.xkl.config.ResultStatus;
|
|
|
import com.xkl.domain.User;
|
|
|
import com.xkl.domain.XklAdminEntity;
|
|
|
import com.xkl.domain.XklCompanyEntity;
|
|
|
import com.xkl.domain.XklMemberEntity;
|
|
|
import com.xkl.model.CityModel;
|
|
|
import com.xkl.model.ResultModel;
|
|
|
import com.xkl.repository.UserRepository;
|
|
|
import com.xkl.repository.XklCompanyRespository;
|
|
|
import com.xkl.repository.XklMemberRespository;
|
|
|
import com.xkl.security.AntiXSS;
|
|
|
import com.wordnik.swagger.annotations.ApiImplicitParam;
|
|
|
import com.wordnik.swagger.annotations.ApiImplicitParams;
|
|
|
import com.wordnik.swagger.annotations.ApiOperation;
|
|
|
import com.xkl.security.SecurityTool;
|
|
|
import com.xkl.tools.UtilTools;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
...
|
...
|
@@ -25,7 +29,7 @@ import org.springframework.web.bind.annotation.RequestParam; |
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.xml.transform.Result;
|
|
|
import java.sql.Date;
|
|
|
|
|
|
/**
|
|
|
* Created by win7 on 2016/10/19.
|
...
|
...
|
@@ -39,39 +43,77 @@ public class UserInfoController { |
|
|
private ITokenManager tokenManager;
|
|
|
@Autowired
|
|
|
private XklMemberRespository xklMemberRespository;
|
|
|
@Autowired
|
|
|
private XklCompanyRespository xklCompanyRespository;
|
|
|
|
|
|
@LogAnnotation
|
|
|
@AntiXSS
|
|
|
@Authorization
|
|
|
@Sign
|
|
|
@RequestMapping(method = RequestMethod.POST)
|
|
|
@ApiOperation(value = "用户注册接口")
|
|
|
public ResponseEntity<ResultModel> register(HttpServletRequest request,@RequestParam String username, @RequestParam String password,
|
|
|
@RequestParam String sign,@RequestParam long t,@RequestParam int type) {
|
|
|
public ResponseEntity<ResultModel> register(HttpServletRequest request, @CurrentAdmin XklAdminEntity admin, @RequestParam String username, @RequestParam String password,
|
|
|
@RequestParam String name, @RequestParam String phone,@RequestParam boolean sex,@RequestParam String birthDate,
|
|
|
@RequestParam(required=false) String idcard,
|
|
|
@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");
|
|
|
Assert.notNull(name, "name can not be empty");
|
|
|
Assert.notNull(sex, "sex can not be empty");
|
|
|
Assert.notNull(birthDate, "birthDate can not be empty");
|
|
|
Assert.notNull(phone, "phone can not be empty");
|
|
|
|
|
|
User user = userRepository.findByLoginAccountAndStatus(username, Constants.STATUS_OK2);
|
|
|
if (user != null ) { //用户已注册
|
|
|
return new ResponseEntity<>(ResultModel.error(ResultStatus.USER_IS_EXIT), HttpStatus.OK);
|
|
|
}else{
|
|
|
String salt= SecurityTool.genSalt();
|
|
|
String pass=SecurityTool.getPassword(username,password,salt);
|
|
|
user = new User();
|
|
|
/**
|
|
|
* TODO:
|
|
|
* 1. sign检测注解@Sign先注释掉 ,便于测试
|
|
|
* 2. 暂时把所有注册的用户的member表member_id都设置为1
|
|
|
* member表
|
|
|
*/
|
|
|
XklMemberEntity member = new XklMemberEntity();
|
|
|
member.setName(name);
|
|
|
member.setSex(sex);
|
|
|
member.setBirthDate(birthDate);
|
|
|
member.setPhone(phone);
|
|
|
member.setRegisterBy(admin.getId());
|
|
|
member.setCompanyId(admin.getCoid());
|
|
|
member.setRegisterTime(UtilTools.getNow());
|
|
|
member.setStatus(1);
|
|
|
//member表自动判断归属地
|
|
|
if(idcard!=null&&idcard!=""){//身份证存在
|
|
|
member.setIdcard(idcard);
|
|
|
CityModel cityModel = Constants.cityMap.get(idcard.substring(0,6));
|
|
|
if(cityModel!=null){
|
|
|
member.setCountry(cityModel.getCountry());
|
|
|
member.setProvince(cityModel.getProvince());
|
|
|
member.setCity(cityModel.getCity());
|
|
|
}
|
|
|
}else{
|
|
|
long coid = admin.getCoid();
|
|
|
XklCompanyEntity xklCompanyEntity = xklCompanyRespository.findOne(coid);
|
|
|
if(xklCompanyEntity!=null){
|
|
|
member.setCountry(xklCompanyEntity.getCountryId());
|
|
|
member.setProvince(xklCompanyEntity.getProvinceId());
|
|
|
member.setCity(xklCompanyEntity.getCityId());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
XklMemberEntity memberEntity = xklMemberRespository.save(member);
|
|
|
if(memberEntity!=null){
|
|
|
String salt= SecurityTool.genSalt();
|
|
|
String pass=SecurityTool.getPassword(username,password,salt);
|
|
|
user = new User();
|
|
|
|
|
|
user.setMemberId(1);
|
|
|
user.setLoginAccount(username);
|
|
|
user.setLoginPwd(pass);
|
|
|
user.setSalt(salt);
|
|
|
user.setStatus(true);
|
|
|
userRepository.save(user);
|
|
|
user.setMemberId(memberEntity.getId());
|
|
|
user.setLoginAccount(username);
|
|
|
user.setLoginPwd(pass);
|
|
|
user.setSalt(salt);
|
|
|
user.setStatus(true);
|
|
|
userRepository.save(user);
|
|
|
}
|
|
|
}
|
|
|
return new ResponseEntity<>(ResultModel.ok(ResultStatus.USER_REGISTER), HttpStatus.OK);
|
|
|
}
|
...
|
...
|
|