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