licailing 5 лет назад
Родитель
Сommit
bba479b3bc

+ 0 - 6
src/main/java/com/izouma/dingdong/dto/OrderInfoDTO.java

@@ -1,15 +1,9 @@
 package com.izouma.dingdong.dto;
 
-import com.izouma.dingdong.domain.OrderGoodsSpec;
 import com.izouma.dingdong.domain.OrderInfo;
-import com.izouma.dingdong.enums.*;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.*;
-import javax.persistence.*;
-import java.math.BigDecimal;
-import java.time.LocalDateTime;
-import java.util.List;
 
 @Data
 @AllArgsConstructor

+ 15 - 13
src/main/java/com/izouma/dingdong/service/UserService.java

@@ -65,19 +65,21 @@ public class UserService {
             if (StrUtil.isNotBlank(password)) {
                 user.setPassword(new BCryptPasswordEncoder().encode(password));
             }
-            userRepo.save(user);
-        } else {
-            if (user.getBlacklist()) {
-                throw new BusinessException("被拉入黑名单!");
-            }
-            if (RIDER.equals(identity)) {
-                boolean matches = new BCryptPasswordEncoder().matches(password, user.getPassword());
-                if (!matches) {
-                    throw new BusinessException("密码不正确");
-                }
+            return userRepo.save(user);
+        }
+
+        if (user.getBlacklist()) {
+            throw new BusinessException("被拉入黑名单!");
+        }
+        if (RIDER.equals(identity)) {
+            boolean matches = new BCryptPasswordEncoder().matches(password, user.getPassword());
+            if (!matches) {
+                throw new BusinessException("密码不正确");
             }
         }
+
         return user;
+
     }
 
     public User merUser(MerchantDTO merchantDTO) {
@@ -102,20 +104,20 @@ public class UserService {
         return userRepo.save(user);
     }
 
-    public User loginByPhone(String phone, String code) {
+    public User loginByPhone(String phone, String code, Identity identity) {
         try {
             smsService.verify(phone, code);
         } catch (SmsService.SmsVerifyException e) {
             e.printStackTrace();
             throw new BusinessException("验证码错误");
         }
-        User user = userRepo.findByPhone(phone);
+        User user = userRepo.findByPhoneAndIdentity(phone, identity);
         if (user == null) {
             user = User.builder()
                     .username(UUID.randomUUID().toString())
                     .nickname(phone)
                     .phone(phone)
-                    .identity(USER)
+                    .identity(identity)
                     .enabled(true)
                     .avatar(Constants.DEFAULT_AVATAR)
                     .build();

+ 2 - 2
src/main/java/com/izouma/dingdong/web/AuthenticationController.java

@@ -49,9 +49,9 @@ public class AuthenticationController {
 
     @PostMapping("/phoneLogin")
     @ApiOperation(value = "手机号登录")
-    public String phoneLogin(String phone, String code) {
+    public String phoneLogin(String phone, String code, Identity identity) {
         try {
-            User user = userService.loginByPhone(phone, code);
+            User user = userService.loginByPhone(phone, code, identity);
             return jwtTokenUtil.generateToken(JwtUserFactory.create(user));
         } catch (Exception e) {
             log.error("loginByPhone", e);