新增 CommonResult 。
将使用手机号进行注册登陆的逻辑,进行变更~
This commit is contained in:
@@ -92,6 +92,12 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId> <!-- use mapstruct-jdk8 for Java 8 or higher -->
|
||||
<version>${org.mapstruct.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package cn.iocoder.mall.user.controller;
|
||||
|
||||
import cn.iocoder.common.framework.exception.ServiceException;
|
||||
import cn.iocoder.common.framework.util.ExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.user.sdk.annotation.PermitAll;
|
||||
import cn.iocoder.mall.user.service.api.MobileCodeService;
|
||||
import cn.iocoder.mall.user.service.api.OAuth2Service;
|
||||
import cn.iocoder.mall.user.service.api.UserService;
|
||||
import cn.iocoder.mall.user.service.api.bo.OAuth2AccessTokenBO;
|
||||
import cn.iocoder.mall.user.service.api.constant.UserErrorCodeEnum;
|
||||
import cn.iocoder.mall.user.service.api.dto.OAuth2AccessTokenBO;
|
||||
import com.alibaba.dubbo.config.annotation.Reference;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -35,7 +37,7 @@ public class PassportController {
|
||||
* 手机号 + 验证码登陆
|
||||
*
|
||||
* @param mobile 手机号
|
||||
* @param code 验证码
|
||||
* @param code 验证码
|
||||
* @return 授权信息
|
||||
*/
|
||||
@PermitAll
|
||||
@@ -47,7 +49,11 @@ public class PassportController {
|
||||
try {
|
||||
accessTokenDTO = oauth2Service.getAccessToken(mobile, code);
|
||||
return accessTokenDTO;
|
||||
} catch (ServiceException serviceException) {
|
||||
} catch (Exception ex) {
|
||||
ServiceException serviceException = ExceptionUtil.getServiceException(ex);
|
||||
if (serviceException == null) {
|
||||
throw ex;
|
||||
}
|
||||
if (!serviceException.getCode().equals(UserErrorCodeEnum.USER_MOBILE_NOT_REGISTERED.getCode())) { // 如果是未注册异常,忽略。下面发起自动注册逻辑。
|
||||
throw serviceException;
|
||||
}
|
||||
@@ -55,7 +61,11 @@ public class PassportController {
|
||||
// 上面尝试授权失败,说明用户未注册,发起自动注册。
|
||||
try {
|
||||
userService.createUser(mobile, code);
|
||||
} catch (ServiceException serviceException) {
|
||||
} catch (Exception ex) {
|
||||
ServiceException serviceException = ExceptionUtil.getServiceException(ex);
|
||||
if (serviceException == null) {
|
||||
throw ex;
|
||||
}
|
||||
if (!serviceException.getCode().equals(UserErrorCodeEnum.USER_MOBILE_ALREADY_REGISTERED.getCode())) { // 如果是已注册异常,忽略。下面再次发起授权
|
||||
throw serviceException;
|
||||
}
|
||||
@@ -65,11 +75,26 @@ public class PassportController {
|
||||
return accessTokenDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号 + 验证码登陆
|
||||
*
|
||||
* @param mobile 手机号
|
||||
* @param code 验证码
|
||||
* @return 授权信息
|
||||
*/
|
||||
@PermitAll
|
||||
@PostMapping("/mobile/login2")
|
||||
public CommonResult<OAuth2AccessTokenBO> mobileRegister2(@RequestParam("mobile") String mobile,
|
||||
@RequestParam("code") String code) {
|
||||
return oauth2Service.getAccessToken2(mobile, code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送手机验证码
|
||||
*
|
||||
* @param mobile 手机号
|
||||
*/
|
||||
@PermitAll
|
||||
@PostMapping("mobile/send")
|
||||
public void mobileSend(@RequestParam("mobile") String mobile) {
|
||||
mobileCodeService.send(mobile);
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package cn.iocoder.mall.user.controller;
|
||||
|
||||
import cn.iocoder.mall.user.sdk.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
//@RestController
|
||||
//@RequestMapping("/user")
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
|
||||
@GetMapping("/info")
|
||||
public Long info() {
|
||||
// TODO 芋艿,正在实现中
|
||||
// return SecurityContextHolder.getContext().getUid();
|
||||
return null;
|
||||
return SecurityContextHolder.getContext().getUid();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user