Prechádzať zdrojové kódy

只有教师可以登录

chenw 6 rokov pred
rodič
commit
512ae47602

+ 11 - 1
base-servers/auth/auth-server/src/main/java/com/usoftchina/smartschool/auth/controller/AuthController.java

@@ -8,6 +8,8 @@ import com.usoftchina.smartschool.auth.jwt.JwtHelper;
 import com.usoftchina.smartschool.auth.jwt.JwtInfo;
 import com.usoftchina.smartschool.auth.jwt.JwtToken;
 import com.usoftchina.smartschool.base.Result;
+import com.usoftchina.smartschool.exception.BizException;
+import com.usoftchina.smartschool.exception.ExceptionCode;
 import com.usoftchina.smartschool.utils.BeanMapper;
 import com.usoftchina.smartschool.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -48,7 +50,15 @@ public class AuthController {
         Result<AccountDTO> result = accountApi.checkPwd(username, password);
         if (result.isSuccess()){
             AccountDTO accountDTO = result.getData();
-            Long school_id = accountDTO.getRoleMaps().stream().filter(roleDTO -> "教师".equals(roleDTO.getRole_name())).findFirst().get().getSchool_id();
+            Long school_id = -1L;
+            try {
+                school_id = accountDTO.getRoleMaps().stream().filter(roleDTO -> "教师".equals(roleDTO.getRole_name())).findFirst().get().getSchool_id();
+                if (school_id == -1){
+                    throw new BizException(ExceptionCode.USER_NOT_EXIST);
+                }
+            }catch (Exception e){
+                throw new BizException(ExceptionCode.USER_NOT_EXIST);
+            }
             accountDTO.setSchool_id(school_id);
             String realName = accountApi.getUsername(school_id, accountDTO.getId()).getData();
             accountDTO.setUsername(realName);