diff --git a/luoo_user/pom.xml b/luoo_user/pom.xml
index 11d1653..144d112 100644
--- a/luoo_user/pom.xml
+++ b/luoo_user/pom.xml
@@ -65,7 +65,7 @@
io.springfox
springfox-swagger2
- 2.9.2
+ 2.8.0
com.github.xiaoymin
diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserController.java
index fb11141..0c2de6e 100644
--- a/luoo_user/src/main/java/com/luoo/user/controller/UserController.java
+++ b/luoo_user/src/main/java/com/luoo/user/controller/UserController.java
@@ -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 sendSms(@PathVariable String mobile) {
userService.sendSms(mobile);
- return new Result(true,StatusCode.OK,"发送成功");
+ return ResultVO.success("发送成功");
}
@RequestMapping(value = "/register/{code}",method = RequestMethod.POST)
diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserService.java b/luoo_user/src/main/java/com/luoo/user/service/UserService.java
index 8526912..12d2fa7 100644
--- a/luoo_user/src/main/java/com/luoo/user/service/UserService.java
+++ b/luoo_user/src/main/java/com/luoo/user/service/UserService.java
@@ -17,6 +17,7 @@ import io.jsonwebtoken.Claims;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@@ -29,8 +30,11 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import util.IdWorker;
+import com.apifan.common.random.RandomSource;
import com.luoo.user.dao.UserDao;
import com.luoo.user.pojo.User;
+import com.luoo.user.vo.UserVO;
+
import util.JwtUtil;
/**
@@ -249,7 +253,23 @@ public class UserService {
userDao.updatefanscount(x,friendid);
userDao.updatefollowcount(x,userid);
}
-
+ public UserVO loginOrRegister(String mobile) {
+ User user = userDao.findByMobile(mobile);
+ if(null==user) {
+ user=new User();
+ user.setId(String.valueOf(idWorker.nextId()));
+ user.setMobile(mobile);
+ user.setNickname(RandomSource.personInfoSource().randomChineseNickName(8));
+ user.setAvatar("default");
+ userDao.save(user);
+ }
+
+ UserVO userVO=new UserVO();
+ BeanUtils.copyProperties(user, userVO);
+ String token = jwtUtil.createJWT(user.getId(),user.getMobile(),"user");
+ userVO.setToken(token);
+ return userVO;
+ }
public User findByMobile(String mobile) {
User user = userDao.findByMobile(mobile);
return user;
diff --git a/luoo_user/src/main/java/com/luoo/user/swagger/BaseSwaggerConfig.java b/luoo_user/src/main/java/com/luoo/user/swagger/BaseSwaggerConfig.java
index f9f6bd7..2ed11b5 100644
--- a/luoo_user/src/main/java/com/luoo/user/swagger/BaseSwaggerConfig.java
+++ b/luoo_user/src/main/java/com/luoo/user/swagger/BaseSwaggerConfig.java
@@ -3,6 +3,8 @@ package com.luoo.user.swagger;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.RequestMethod;
+
+import io.swagger.annotations.ApiOperation;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
@@ -34,6 +36,7 @@ public abstract class BaseSwaggerConfig {
.apiInfo(apiInfo(swaggerProperties))
.select()
.apis(RequestHandlerSelectors.basePackage(swaggerProperties.getApiBasePackage()))
+ //.apis(RequestHandlerSelectors.withClassAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build();
}