Merge branch 'master' of https://git.dayouqiantu.cn/yshopb2c/yshop
This commit is contained in:
@ -150,7 +150,7 @@ public class OnlineUserService {
|
||||
for (OnlineUser user : all) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
map.put("用户名", user.getUserName());
|
||||
map.put("岗位", user.getJob());
|
||||
map.put("用户昵称", user.getNickName());
|
||||
map.put("登录IP", user.getIp());
|
||||
map.put("登录地点", user.getAddress());
|
||||
map.put("浏览器", user.getBrowser());
|
||||
|
@ -8,8 +8,10 @@ package co.yixiang.utils;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import co.yixiang.exception.BadRequestException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户
|
||||
@ -19,13 +21,16 @@ import org.springframework.security.core.userdetails.UserDetails;
|
||||
public class SecurityUtils {
|
||||
|
||||
public static UserDetails getUserDetails() {
|
||||
UserDetails userDetails;
|
||||
try {
|
||||
userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException(HttpStatus.UNAUTHORIZED, "登录状态过期");
|
||||
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication == null) {
|
||||
throw new BadRequestException(HttpStatus.UNAUTHORIZED, "当前登录状态过期");
|
||||
}
|
||||
return userDetails;
|
||||
if (authentication.getPrincipal() instanceof UserDetails) {
|
||||
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
|
||||
UserDetailsService userDetailsService = SpringContextHolder.getBean(UserDetailsService.class);
|
||||
return userDetailsService.loadUserByUsername(userDetails.getUsername());
|
||||
}
|
||||
throw new BadRequestException(HttpStatus.UNAUTHORIZED, "找不到当前登录的信息");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -33,8 +38,12 @@ public class SecurityUtils {
|
||||
* @return 系统用户名称
|
||||
*/
|
||||
public static String getUsername(){
|
||||
Object obj = getUserDetails();
|
||||
return new JSONObject(obj).get("username", String.class);
|
||||
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication == null) {
|
||||
throw new BadRequestException(HttpStatus.UNAUTHORIZED, "当前登录状态过期");
|
||||
}
|
||||
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
|
||||
return userDetails.getUsername();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,7 +81,7 @@ public interface UserBillMapper extends CoreMapper<YxUserBill> {
|
||||
"from yx_user_bill b left join yx_user u on u.uid=b.uid where 1=1 " +
|
||||
"<if test =\"category !=''\">and b.category=#{category}</if> " +
|
||||
"<if test =\"type !=''\">and b.type=#{type}</if> " +
|
||||
"<if test =\"nickname !=''\">and u.nickname= LIKE CONCAT('%',#{nickname},'%')</if> </script> ")
|
||||
"<if test =\"nickname !=''\">and u.nickname LIKE CONCAT('%',#{nickname},'%')</if> </script> ")
|
||||
List<YxUserBillDto> findAllByQueryCriteria(@Param("category") String category, @Param("type") String type,
|
||||
@Param("nickname") String nickname);
|
||||
}
|
||||
|
Reference in New Issue
Block a user