Search in sources :

Example 1 with UserType

use of com.ruoyi.common.enums.UserType 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 UserType

use of com.ruoyi.common.enums.UserType in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SaInterfaceImpl method getRoleList.

@Override
public List<String> getRoleList(Object loginId, String loginType) {
    LoginUser loginUser = LoginHelper.getLoginUser();
    UserType userType = UserType.getUserType(loginUser.getUserType());
    if (userType == UserType.SYS_USER) {
        return new ArrayList<>(loginUser.getRolePermission());
    } else if (userType == UserType.APP_USER) {
    // app端权限返回 自行根据业务编写
    }
    return new ArrayList<>();
}
Also used : ArrayList(java.util.ArrayList) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) UserType(com.ruoyi.common.enums.UserType)

Example 3 with UserType

use of com.ruoyi.common.enums.UserType in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SaInterfaceImpl method getPermissionList.

@Override
public List<String> getPermissionList(Object loginId, String loginType) {
    LoginUser loginUser = LoginHelper.getLoginUser();
    UserType userType = UserType.getUserType(loginUser.getUserType());
    if (userType == UserType.SYS_USER) {
        return new ArrayList<>(loginUser.getMenuPermission());
    } else if (userType == UserType.APP_USER) {
    // app端权限返回 自行根据业务编写
    }
    return new ArrayList<>();
}
Also used : ArrayList(java.util.ArrayList) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) UserType(com.ruoyi.common.enums.UserType)

Example 4 with UserType

use of com.ruoyi.common.enums.UserType 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)

Example 5 with UserType

use of com.ruoyi.common.enums.UserType in project RuoYi-Vue-Plus by JavaLionLi.

the class SaInterfaceImpl method getRoleList.

@Override
public List<String> getRoleList(Object loginId, String loginType) {
    LoginUser loginUser = LoginHelper.getLoginUser();
    UserType userType = UserType.getUserType(loginUser.getUserType());
    if (userType == UserType.SYS_USER) {
        return new ArrayList<>(loginUser.getRolePermission());
    } else if (userType == UserType.APP_USER) {
    // app端权限返回 自行根据业务编写
    }
    return new ArrayList<>();
}
Also used : ArrayList(java.util.ArrayList) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) UserType(com.ruoyi.common.enums.UserType)

Aggregations

LoginUser (com.ruoyi.common.core.domain.model.LoginUser)8 UserType (com.ruoyi.common.enums.UserType)8 ArrayList (java.util.ArrayList)4 UserAgent (cn.hutool.http.useragent.UserAgent)2 UserOnlineDTO (com.ruoyi.common.core.domain.dto.UserOnlineDTO)2 UtilException (com.ruoyi.common.exception.UtilException)2