|
@@ -1,7 +1,9 @@
|
|
|
package com.ym.mec.auth.core.provider;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
@@ -21,7 +23,6 @@ import com.ym.mec.auth.api.entity.SysUserDevice;
|
|
|
import com.ym.mec.auth.config.token.PhoneAuthenticationToken;
|
|
|
import com.ym.mec.auth.service.SysUserDeviceService;
|
|
|
import com.ym.mec.auth.service.SysUserService;
|
|
|
-import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.service.IdGeneratorService;
|
|
|
|
|
|
public class PhoneAuthenticationProvider extends AbstractAuthenticationProvider {
|
|
@@ -73,12 +74,15 @@ public class PhoneAuthenticationProvider extends AbstractAuthenticationProvider
|
|
|
if (isRegister == false || StringUtils.equals("SYSTEM", clientId)) {
|
|
|
throw new LockedException("用户不存在");
|
|
|
}
|
|
|
- if (StringUtils.isNotBlank(deviceNum) && !StringUtils.equals("STUDENT", clientId)) {
|
|
|
- // 检查设备
|
|
|
- List<SysUserDevice> sysUserDeviceList = sysUserDeviceService.queryByDeviceNum(deviceNum);
|
|
|
-
|
|
|
- if (sysUserDeviceList != null && sysUserDeviceList.size() > 0) {
|
|
|
- throw new BadCredentialsException("当前设备已绑定账号,请更换设备");
|
|
|
+ if (StringUtils.isNotBlank(deviceNum)) {
|
|
|
+
|
|
|
+ if(!StringUtils.equals("STUDENT", clientId)){
|
|
|
+ // 检查设备
|
|
|
+ List<SysUserDevice> sysUserDeviceList = sysUserDeviceService.queryByDeviceNum(deviceNum);
|
|
|
+
|
|
|
+ if (sysUserDeviceList != null && sysUserDeviceList.size() > 0) {
|
|
|
+ throw new BadCredentialsException("当前设备已绑定账号,请更换设备");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
userInfo = sysUserService.initUser(loginEntity.getPhone(), clientId);
|
|
@@ -96,14 +100,39 @@ public class PhoneAuthenticationProvider extends AbstractAuthenticationProvider
|
|
|
if (user == null) {
|
|
|
throw new LockedException("用户不存在");
|
|
|
}
|
|
|
- if (StringUtils.isNotBlank(deviceNum) && !StringUtils.equals("STUDENT", clientId)) {
|
|
|
- // 检查设备
|
|
|
- try {
|
|
|
- sysUserDeviceService.bindDevice(user.getId(), deviceNum);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new BadCredentialsException("当前设备已绑定账号,请更换设备");
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(deviceNum)) {
|
|
|
+ if(StringUtils.equals("STUDENT", clientId)){
|
|
|
+ // 检查学生是否绑定了多个设备号
|
|
|
+ List<SysUserDevice> sysUserDeviceList = sysUserDeviceService.queryByUserId(user.getId());
|
|
|
+
|
|
|
+ if(sysUserDeviceList == null){
|
|
|
+ sysUserDeviceList = new ArrayList<SysUserDevice>();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> deviceList = sysUserDeviceList.stream().map(t -> t.getDeviceNum()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if(!deviceList.contains(deviceNum)){
|
|
|
+ if(deviceList.size() >= 5){
|
|
|
+ throw new BadCredentialsException("当前账号绑定设备过多,请联系主教老师");
|
|
|
+ }
|
|
|
+ SysUserDevice sysUserDevice = new SysUserDevice();
|
|
|
+ sysUserDevice.setUserId(userInfo.getSysUser().getId());
|
|
|
+ sysUserDevice.setDeviceNum(deviceNum);
|
|
|
+ sysUserDevice.setBindTime(new Date());
|
|
|
+ sysUserDeviceService.insert(sysUserDevice);
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+ // 检查老师端、教务端设备号
|
|
|
+ try {
|
|
|
+ sysUserDeviceService.bindDevice(user.getId(), deviceNum);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BadCredentialsException("当前设备已绑定账号,请更换设备");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
if (!userInfo.getSysUser().getUserType().contains(clientId)) {
|
|
|
if (isRegister == false || StringUtils.equals("SYSTEM", clientId)) {
|
|
|
throw new LockedException("用户不存在");
|