@ -3,14 +3,13 @@ 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 ;
import com.github.pagehelper.PageInfo ;
import com.github.pagehelper.PageInfo ;
import lombok.RequiredArgsConstructor ;
import lombok.RequiredArgsConstructor ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.cache.annotation.CacheConfig ;
import org.springframework.cache.annotation.CacheConfig ;
import org.springframework.cache.annotation.CacheEvict ;
import org.springframework.cache.annotation.CacheEvict ;
import org.springframework.cache.annotation.Cacheable ;
import org.springframework.cache.annotation.Cacheable ;
@ -23,8 +22,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.util.ObjectUtils ;
import org.springframework.util.ObjectUtils ;
import java.util.List ;
import java.util.List ;
@Transactional
@Transactional
@Service
@Service
@RequiredArgsConstructor
@RequiredArgsConstructor
@ -37,6 +36,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 ) {
@ -81,11 +82,13 @@ public class AdminServiceImpl implements AdminService {
return new PageInfo < > ( list ) ;
return new PageInfo < > ( list ) ;
}
}
/ / 修改登录方法
@Override
@Override
public Admin login ( Admin admin ) throws Exception {
public Admin login ( Admin admin ) throws Exception {
try {
Admin admin1 = adminMapper . selectByJwcode ( admin . getJwcode ( ) ) ;
Admin admin1 = adminMapper . selectByJwcode ( admin . getJwcode ( ) ) ;
String [ ] machineIds = admin1 . getMachineId ( ) . split ( "," ) ;
String [ ] machineIds = admin1 . getMachineId ( ) . split ( "," ) ;
boolean flag = false ;
boolean flag = false ;
for ( String machineId : machineIds ) {
for ( String machineId : machineIds ) {
if ( admin . getMachineId ( ) ! = null & & admin . getMachineId ( ) . equals ( machineId ) )
if ( admin . getMachineId ( ) ! = null & & admin . getMachineId ( ) . equals ( machineId ) )
@ -98,15 +101,21 @@ public class AdminServiceImpl implements AdminService {
System . out . println ( admin . getPassword ( ) ) ;
System . out . println ( admin . getPassword ( ) ) ;
UsernamePasswordAuthenticationToken token =
UsernamePasswordAuthenticationToken token =
new UsernamePasswordAuthenticationToken ( admin . getJwcode ( ) , admin . getPassword ( ) ) ;
new UsernamePasswordAuthenticationToken ( admin . getJwcode ( ) , admin . getPassword ( ) ) ;
try {
Authentication authentication = authenticationManager . authenticate ( token ) ;
Authentication authentication = authenticationManager . authenticate ( token ) ;
Admin loginAdmin = ( Admin ) authentication . getPrincipal ( ) ;
Admin loginAdmin = ( Admin ) authentication . getPrincipal ( ) ;
return loginAdmin ;
return loginAdmin ;
} catch ( BadCredentialsException exception ) {
throw new BadCredentialsException ( "用户或密码错误" ) ;
} catch ( NullPointerException e ) {
throw new RuntimeException ( "无此精网号" ) ;
} catch ( BadCredentialsException exception ) {
throw new BadCredentialsException ( "密码错误" ) ;
} catch ( Exception e ) {
throw new RuntimeException ( "你没有使用该机器的权限!" ) ;
}
}
}
}
@Override
@Override