|
@ -3,6 +3,7 @@ package com.example.demo.serviceImpl; |
|
|
|
|
|
|
|
|
import com.example.demo.domain.entity.Admin; |
|
|
import com.example.demo.domain.entity.Admin; |
|
|
import com.example.demo.mapper.AdminMapper; |
|
|
import com.example.demo.mapper.AdminMapper; |
|
|
|
|
|
import com.example.demo.mapper.UserMapper; |
|
|
import com.example.demo.security.SecurityConfig; |
|
|
import com.example.demo.security.SecurityConfig; |
|
|
import com.example.demo.sevice.AdminService; |
|
|
import com.example.demo.sevice.AdminService; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageHelper; |
|
@ -25,6 +26,8 @@ import org.springframework.util.ObjectUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
@Transactional |
|
|
@Transactional |
|
|
@Service |
|
|
@Service |
|
|
@RequiredArgsConstructor |
|
|
@RequiredArgsConstructor |
|
@ -37,6 +40,8 @@ public class AdminServiceImpl implements AdminService { |
|
|
private AuthenticationManager authenticationManager; |
|
|
private AuthenticationManager authenticationManager; |
|
|
@Autowired |
|
|
@Autowired |
|
|
private PasswordEncoder passwordEncoder; |
|
|
private PasswordEncoder passwordEncoder; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private UserMapper userMapper; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public int add(Admin admin) { |
|
|
public int add(Admin admin) { |
|
@ -83,30 +88,37 @@ public class AdminServiceImpl implements AdminService { |
|
|
} |
|
|
} |
|
|
@Override |
|
|
@Override |
|
|
public Admin login(Admin admin) throws Exception { |
|
|
public Admin login(Admin admin) throws Exception { |
|
|
|
|
|
try { |
|
|
|
|
|
Admin admin1 = adminMapper.selectByJwcode(admin.getJwcode()); |
|
|
|
|
|
String[] machineIds = admin1.getMachineId().split(","); |
|
|
|
|
|
|
|
|
|
|
|
boolean flag = false; |
|
|
|
|
|
for (String machineId : machineIds) { |
|
|
|
|
|
if (admin.getMachineId() != null && admin.getMachineId().equals(machineId)) |
|
|
|
|
|
flag = true; |
|
|
|
|
|
} |
|
|
|
|
|
if (!flag) { |
|
|
|
|
|
throw new RuntimeException("你没有使用该机器的权限!"); |
|
|
|
|
|
} |
|
|
|
|
|
System.out.println(admin.getJwcode()); |
|
|
|
|
|
System.out.println(admin.getPassword()); |
|
|
|
|
|
UsernamePasswordAuthenticationToken token = |
|
|
|
|
|
new UsernamePasswordAuthenticationToken(admin.getJwcode(),admin.getPassword()); |
|
|
|
|
|
|
|
|
|
|
|
Authentication authentication = authenticationManager.authenticate(token); |
|
|
|
|
|
Admin loginAdmin = (Admin) authentication.getPrincipal(); |
|
|
|
|
|
|
|
|
|
|
|
return loginAdmin; |
|
|
|
|
|
|
|
|
|
|
|
}catch (NullPointerException e){ |
|
|
|
|
|
throw new RuntimeException("无此精网号"); |
|
|
|
|
|
}catch(BadCredentialsException exception){ |
|
|
|
|
|
throw new BadCredentialsException("密码错误"); |
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
throw new RuntimeException("你没有使用该机器的权限!"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Admin admin1=adminMapper.selectByJwcode(admin.getJwcode()); |
|
|
|
|
|
String[] machineIds = admin1.getMachineId().split(","); |
|
|
|
|
|
boolean flag = false; |
|
|
|
|
|
for(String machineId:machineIds) { |
|
|
|
|
|
if (admin.getMachineId() != null && admin.getMachineId().equals(machineId)) |
|
|
|
|
|
flag = true; |
|
|
|
|
|
} |
|
|
|
|
|
if (!flag) { |
|
|
|
|
|
throw new RuntimeException("你没有使用该机器的权限!"); |
|
|
|
|
|
} |
|
|
|
|
|
System.out.println(admin.getJwcode()); |
|
|
|
|
|
System.out.println(admin.getPassword()); |
|
|
|
|
|
UsernamePasswordAuthenticationToken token = |
|
|
|
|
|
new UsernamePasswordAuthenticationToken(admin.getJwcode(),admin.getPassword()); |
|
|
|
|
|
try { |
|
|
|
|
|
Authentication authentication = authenticationManager.authenticate(token); |
|
|
|
|
|
Admin loginAdmin = (Admin) authentication.getPrincipal(); |
|
|
|
|
|
|
|
|
|
|
|
return loginAdmin; |
|
|
|
|
|
}catch (BadCredentialsException exception){ |
|
|
|
|
|
throw new BadCredentialsException("用户或密码错误"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|