Search in sources :

Example 1 with UserOnlineDTO

use of com.ruoyi.common.core.domain.dto.UserOnlineDTO in project RuoYi-Flowable-Plus by KonBAI-Q.

the class UserActionListener method doLogin.

/**
 * 每次登录时触发
 */
@Override
public void doLogin(String loginType, Object loginId, SaLoginModel loginModel) {
    UserType userType = UserType.getUserType(loginId.toString());
    if (userType == UserType.SYS_USER) {
        UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent"));
        String ip = ServletUtils.getClientIP();
        LoginUser user = LoginHelper.getLoginUser();
        String tokenValue = StpUtil.getTokenValueByLoginId(loginId);
        UserOnlineDTO dto = new UserOnlineDTO();
        dto.setIpaddr(ip);
        dto.setLoginLocation(AddressUtils.getRealAddressByIP(ip));
        dto.setBrowser(userAgent.getBrowser().getName());
        dto.setOs(userAgent.getOs().getName());
        dto.setLoginTime(System.currentTimeMillis());
        dto.setTokenId(tokenValue);
        dto.setUserName(user.getUsername());
        dto.setDeptName(user.getDeptName());
        RedisUtils.setCacheObject(Constants.ONLINE_TOKEN_KEY + tokenValue, dto, tokenConfig.getTimeout(), TimeUnit.SECONDS);
        log.info("user doLogin, useId:{}, token:{}", loginId, tokenValue);
    } else if (userType == UserType.APP_USER) {
    // app端 自行根据业务编写
    }
}
Also used : UserOnlineDTO(com.ruoyi.common.core.domain.dto.UserOnlineDTO) UserAgent(cn.hutool.http.useragent.UserAgent) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) UserType(com.ruoyi.common.enums.UserType)

Example 2 with UserOnlineDTO

use of com.ruoyi.common.core.domain.dto.UserOnlineDTO in project RuoYi-Vue-Plus by JavaLionLi.

the class UserActionListener method doLogin.

/**
 * 每次登录时触发
 */
@Override
public void doLogin(String loginType, Object loginId, SaLoginModel loginModel) {
    UserType userType = UserType.getUserType(loginId.toString());
    if (userType == UserType.SYS_USER) {
        UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent"));
        String ip = ServletUtils.getClientIP();
        LoginUser user = LoginHelper.getLoginUser();
        String tokenValue = StpUtil.getTokenValueByLoginId(loginId);
        UserOnlineDTO dto = new UserOnlineDTO();
        dto.setIpaddr(ip);
        dto.setLoginLocation(AddressUtils.getRealAddressByIP(ip));
        dto.setBrowser(userAgent.getBrowser().getName());
        dto.setOs(userAgent.getOs().getName());
        dto.setLoginTime(System.currentTimeMillis());
        dto.setTokenId(tokenValue);
        dto.setUserName(user.getUsername());
        dto.setDeptName(user.getDeptName());
        RedisUtils.setCacheObject(Constants.ONLINE_TOKEN_KEY + tokenValue, dto, tokenConfig.getTimeout(), TimeUnit.SECONDS);
        log.info("user doLogin, useId:{}, token:{}", loginId, tokenValue);
    } else if (userType == UserType.APP_USER) {
    // app端 自行根据业务编写
    }
}
Also used : UserOnlineDTO(com.ruoyi.common.core.domain.dto.UserOnlineDTO) UserAgent(cn.hutool.http.useragent.UserAgent) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) UserType(com.ruoyi.common.enums.UserType)

Aggregations

UserAgent (cn.hutool.http.useragent.UserAgent)2 UserOnlineDTO (com.ruoyi.common.core.domain.dto.UserOnlineDTO)2 LoginUser (com.ruoyi.common.core.domain.model.LoginUser)2 UserType (com.ruoyi.common.enums.UserType)2