|
|
|
@ -16,10 +16,14 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import com.luoo.user.pojo.User;
|
|
|
|
|
import com.luoo.user.service.UserService;
|
|
|
|
|
import com.luoo.user.vo.UserVO;
|
|
|
|
|
|
|
|
|
|
import entity.PageResult;
|
|
|
|
|
import entity.Result;
|
|
|
|
|
import entity.ResultVO;
|
|
|
|
|
import entity.StatusCode;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import util.IdWorker;
|
|
|
|
|
import util.JwtUtil;
|
|
|
|
|
|
|
|
|
@ -31,6 +35,7 @@ import util.JwtUtil;
|
|
|
|
|
@RestController
|
|
|
|
|
@CrossOrigin
|
|
|
|
|
@RequestMapping("/user")
|
|
|
|
|
@Api(tags="UserController")
|
|
|
|
|
public class UserController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@ -73,37 +78,30 @@ public class UserController {
|
|
|
|
|
return new Result(true,StatusCode.OK,"登录成功",map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value="2.登录/注册后返回token")
|
|
|
|
|
@RequestMapping(value = "/appLogin/{mobile}/{checkcode}",method = RequestMethod.POST)
|
|
|
|
|
public Result appLogin(@PathVariable String mobile,@PathVariable String checkcode){
|
|
|
|
|
|
|
|
|
|
public ResultVO appLogin(@PathVariable String mobile,@PathVariable String checkcode){
|
|
|
|
|
// 得到缓存中的验证码
|
|
|
|
|
String checkcodeRedis = (String)redisTemplate.opsForValue().get("checkcode_"+mobile);
|
|
|
|
|
if (checkcodeRedis.isEmpty()){
|
|
|
|
|
return new Result(false,StatusCode.ERROR,"请先获取手机验证码");
|
|
|
|
|
return new ResultVO(false,StatusCode.ERROR,"请先获取手机验证码");
|
|
|
|
|
}
|
|
|
|
|
if (!checkcodeRedis.equals(checkcode)) {
|
|
|
|
|
return new Result(false,StatusCode.ERROR,"请输入正确的验证码");
|
|
|
|
|
return new ResultVO(false,StatusCode.ERROR,"请输入正确的验证码");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
User user = userService.findByMobile(mobile);
|
|
|
|
|
// 如果数据库中有这个手机号,登录通道,
|
|
|
|
|
if (user != null){
|
|
|
|
|
String token = jwtUtil.createJWT(user.getId(),user.getMobile(),"user");
|
|
|
|
|
}
|
|
|
|
|
// 如果数据库中没有这个手机号,为新用户,注册添加用户
|
|
|
|
|
|
|
|
|
|
return new Result(true,StatusCode.OK,"登录成功");}
|
|
|
|
|
UserVO userVO=userService.loginOrRegister(mobile);
|
|
|
|
|
return ResultVO.success(userVO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 发送短信验证码
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value="1.发送短信验证码")
|
|
|
|
|
@RequestMapping(value = "/sendsms/{mobile}",method = RequestMethod.POST)
|
|
|
|
|
public Result sendSms(@PathVariable String mobile) {
|
|
|
|
|
public ResultVO<Void> sendSms(@PathVariable String mobile) {
|
|
|
|
|
|
|
|
|
|
userService.sendSms(mobile);
|
|
|
|
|
return new Result(true,StatusCode.OK,"发送成功");
|
|
|
|
|
return ResultVO.success("发送成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/register/{code}",method = RequestMethod.POST)
|
|
|
|
|