mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
feat: 更新信任设备逻辑,支持多设备检查及用户验证
This commit is contained in:
@@ -251,6 +251,11 @@ public class SessionService {
|
|||||||
userService
|
userService
|
||||||
.findByUsername(dto.getUsername())
|
.findByUsername(dto.getUsername())
|
||||||
.orElseThrow(() -> new BizException("用户名或者密码错误"));
|
.orElseThrow(() -> new BizException("用户名或者密码错误"));
|
||||||
|
|
||||||
|
|
||||||
|
if (!userService.isValidPassword(dto.getPassword(), user.getPassword())) {
|
||||||
|
throw new BizException("用户名或者密码错误");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.equalsIgnoreCase(dto.getLoginType(), "1")) {
|
if (StringUtils.equalsIgnoreCase(dto.getLoginType(), "1")) {
|
||||||
@@ -290,6 +295,10 @@ public class SessionService {
|
|||||||
user = trustDevice.get().getUser();
|
user = trustDevice.get().getUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (user == null){
|
||||||
|
throw new BizException("用户不存在");
|
||||||
|
}
|
||||||
|
|
||||||
if (user.isDisabled()) {
|
if (user.isDisabled()) {
|
||||||
throw new BizException("用户被禁用");
|
throw new BizException("用户被禁用");
|
||||||
}
|
}
|
||||||
@@ -304,9 +313,7 @@ public class SessionService {
|
|||||||
throw new BizException("用户所在机构已过期");
|
throw new BizException("用户所在机构已过期");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userService.isValidPassword(dto.getPassword(), user.getPassword())) {
|
|
||||||
throw new BizException("用户名或者密码错误");
|
|
||||||
}
|
|
||||||
|
|
||||||
LoginUserEntity entity = new LoginUserEntity();
|
LoginUserEntity entity = new LoginUserEntity();
|
||||||
entity.setEnv(dto.getEnv());
|
entity.setEnv(dto.getEnv());
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import org.springframework.data.jpa.domain.Specification;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -94,8 +95,8 @@ public class TrustDeviceService extends BaseService<TrustDeviceEntity, TrustDevi
|
|||||||
|
|
||||||
UserEntity userEntity = userService.get(user.getId());
|
UserEntity userEntity = userService.get(user.getId());
|
||||||
|
|
||||||
Optional<TrustDeviceEntity> one =
|
List<TrustDeviceEntity> all =
|
||||||
this.repository.findOne(
|
this.repository.findAll(
|
||||||
new Specification<TrustDeviceEntity>() {
|
new Specification<TrustDeviceEntity>() {
|
||||||
@Override
|
@Override
|
||||||
public Predicate toPredicate(
|
public Predicate toPredicate(
|
||||||
@@ -104,14 +105,17 @@ public class TrustDeviceService extends BaseService<TrustDeviceEntity, TrustDevi
|
|||||||
CriteriaBuilder criteriaBuilder) {
|
CriteriaBuilder criteriaBuilder) {
|
||||||
|
|
||||||
return criteriaBuilder.and(
|
return criteriaBuilder.and(
|
||||||
criteriaBuilder.equal(
|
|
||||||
root.get("user").get("id"), userEntity.getId()),
|
|
||||||
criteriaBuilder.equal(root.get("code"), dto.getCode()));
|
criteriaBuilder.equal(root.get("code"), dto.getCode()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (one.isPresent()) {
|
if (!all.isEmpty()) {
|
||||||
|
|
||||||
|
if (all.stream().allMatch(x -> x.getUser().getId().equals(userEntity.getId()))) {
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
throw new BizException("设备已被其他人添加,无法重复添加");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TrustDeviceEntity entity = new TrustDeviceEntity();
|
TrustDeviceEntity entity = new TrustDeviceEntity();
|
||||||
@@ -125,10 +129,7 @@ public class TrustDeviceService extends BaseService<TrustDeviceEntity, TrustDevi
|
|||||||
|
|
||||||
public Optional<TrustDeviceEntity> getByCode(String trustDeviceCode) {
|
public Optional<TrustDeviceEntity> getByCode(String trustDeviceCode) {
|
||||||
|
|
||||||
|
return this.repository.findOne(
|
||||||
|
|
||||||
return this.repository
|
|
||||||
.findOne(
|
|
||||||
new Specification<TrustDeviceEntity>() {
|
new Specification<TrustDeviceEntity>() {
|
||||||
@Override
|
@Override
|
||||||
public Predicate toPredicate(
|
public Predicate toPredicate(
|
||||||
@@ -138,7 +139,5 @@ public class TrustDeviceService extends BaseService<TrustDeviceEntity, TrustDevi
|
|||||||
return criteriaBuilder.equal(root.get("code"), trustDeviceCode);
|
return criteriaBuilder.equal(root.get("code"), trustDeviceCode);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user