修改了返回用户的信息

This commit is contained in:
DESKTOP-4U0TDEF\20371 2021-07-15 14:31:07 +08:00
parent 4dd289d87d
commit c1adf0e28a
6 changed files with 50 additions and 16 deletions

View File

@ -3,6 +3,7 @@ package com.xkrs.common.account;
import com.xkrs.common.encapsulation.OutputEncapsulation;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.model.entity.SysUserEntity;
import com.xkrs.model.vo.SysUserVo;
import com.xkrs.service.SysUserService;
import com.xkrs.utils.IpUtil;
import org.slf4j.Logger;
@ -100,12 +101,12 @@ public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter {
}
//更新用户登录信息
sysUserService.updateSysUserLogin(auth.getName(), IpUtil.getIpAddr(req));
SysUserEntity sysUserByUserName = sysUserService.getSysUserByUserName(auth.getName());
SysUserVo userByUserName = sysUserService.getUserByUserName(auth.getName());
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Credentials", "false");
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
TokenAuthenticationService.addAuthentication(response, auth.getName(),auth.getAuthorities(),sysUserByUserName);
TokenAuthenticationService.addAuthentication(response, auth.getName(),auth.getAuthorities(),userByUserName);
}
/**

View File

@ -3,6 +3,7 @@ package com.xkrs.common.account;
import com.xkrs.common.encapsulation.OutputEncapsulation;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.model.entity.SysUserEntity;
import com.xkrs.model.vo.SysUserVo;
import com.xkrs.utils.DateTimeUtil;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
@ -55,7 +56,7 @@ public class TokenAuthenticationService {
* @param authorities
*/
static void addAuthentication(HttpServletResponse response, String userName,
Collection<? extends GrantedAuthority> authorities,SysUserEntity sysUserEntity) {
Collection<? extends GrantedAuthority> authorities, SysUserVo sysUserEntity) {
Locale locale = new Locale("zh", "CN");
Map map = new HashMap(3);
@ -75,10 +76,11 @@ public class TokenAuthenticationService {
LocalDateTime overTime = DateTimeUtil.stringToDateTime(sysUserEntity.getOverTime());
// 计算距离结束时间的天数作为token
Duration duration = Duration.between(LocalDateTime.now(), overTime);
System.out.println("-------"+duration.toDays());
/**
* 动态设置过期时间
*/
final long EXPIRATIONTIME = 60 * 60 * 24L * duration.toDays();
final long EXPIRATIONTIME = 60 * 60 * 24 * duration.toDays();
// 生成JWT
String jwt = Jwts.builder()

View File

@ -82,10 +82,19 @@ public interface SysUserDao extends JpaRepository<SysUserEntity,Integer> {
* 查询用户信息
* @return
*/
@Query(value = "select new com.xkrs.model.vo.SysUserVo (id,reallyName,telephone,countyCode,activeFlag,addTime) " +
@Query(value = "select new com.xkrs.model.vo.SysUserVo (id,reallyName,telephone,countyCode,activeFlag,addTime,dayNum,overTime) " +
"from SysUserEntity")
List<SysUserVo> selectAll();
/**
* 根据用户名查询实体信息
* @param userName
* @return
*/
@Query(value = "select new com.xkrs.model.vo.SysUserVo (id,reallyName,telephone,countyCode,activeFlag,addTime,dayNum,overTime) " +
"from SysUserEntity where userName = :userName")
SysUserVo selectUserByUserName(String userName);
/**
* 启用
* @param userId

View File

@ -20,13 +20,19 @@ public class SysUserVo implements Serializable {
private String addTime;
public SysUserVo(Integer id, String reallyName, String telephone, String countyCode, Integer activeFlag, String addTime) {
private Integer dayNum;
private String overTime;
public SysUserVo(Integer id, String reallyName, String telephone, String countyCode, Integer activeFlag, String addTime, Integer dayNum, String overTime) {
this.id = id;
this.reallyName = reallyName;
this.telephone = telephone;
this.countyCode = countyCode;
this.activeFlag = activeFlag;
this.addTime = addTime;
this.dayNum = dayNum;
this.overTime = overTime;
}
public Integer getId() {
@ -77,16 +83,20 @@ public class SysUserVo implements Serializable {
this.addTime = addTime;
}
@Override
public String toString() {
return "SysUserVo{" +
"id=" + id +
", reallyName='" + reallyName + '\'' +
", telephone='" + telephone + '\'' +
", countyCode='" + countyCode + '\'' +
", activeFlag=" + activeFlag +
", addTime='" + addTime + '\'' +
'}';
public Integer getDayNum() {
return dayNum;
}
public void setDayNum(Integer dayNum) {
this.dayNum = dayNum;
}
public String getOverTime() {
return overTime;
}
public void setOverTime(String overTime) {
this.overTime = overTime;
}
}

View File

@ -96,4 +96,11 @@ public interface SysUserService {
* @return
*/
String adminUpdatePassword(Integer userId,String newPassword,String confirmPassword);
/**
* 获取系统用户实体根据用户名
* @param userName
* @return
*/
SysUserVo getUserByUserName(String userName);
}

View File

@ -232,4 +232,9 @@ public class SysUserServiceImpl implements SysUserService {
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"密码修改成功",locale);
}
@Override
public SysUserVo getUserByUserName(String userName) {
return sysUserDao.selectUserByUserName(userName);
}
}