Search in sources :

Example 1 with SocialUser

use of com.ruoyi.iot.domain.SocialUser in project wumei-smart by kerwincui.

the class SocialLoginServiceImpl method createOrUpdateSocialUser.

public void createOrUpdateSocialUser(SocialUser socialUser, AuthUser authUser) {
    if (socialUser != null) {
        // 更新数据
        SocialUser updateSocialUser = new SocialUser();
        updateSocialUser.setSocialUserId(socialUser.getSocialUserId());
        replaceSocialUser(updateSocialUser, authUser);
        updateSocialUser.setUpdateBy("System");
        updateSocialUser.setUpdateTime(DateUtils.getNowDate());
        iSocialUserService.updateSocialUser(updateSocialUser);
    } else {
        // 创建
        SocialUser saveSocialUser = new SocialUser();
        replaceSocialUser(saveSocialUser, authUser);
        saveSocialUser.setDelFlag("0");
        saveSocialUser.setStatus("0");
        saveSocialUser.setCreateBy("System");
        saveSocialUser.setCreateTime(DateUtils.getNowDate());
        iSocialUserService.insertSocialUser(saveSocialUser);
    }
}
Also used : SocialUser(com.ruoyi.iot.domain.SocialUser)

Example 2 with SocialUser

use of com.ruoyi.iot.domain.SocialUser in project wumei-smart by kerwincui.

the class SocialLoginServiceImpl method callback.

@Override
public String callback(String source, AuthCallback authCallback, HttpServletRequest httpServletRequest) {
    AuthRequestWrap authRequestWrap = null;
    try {
        authRequestWrap = iAuthRequestFactory.getAuthRequest(source);
        checkSocialPlatform(authRequestWrap.getSocialPlatform());
        AuthResponse<AuthUser> authResponse = authRequestWrap.getAuthRequest().login(authCallback);
        String bindId = null;
        String loginId = null;
        if (authResponse.ok()) {
            SocialUser socialUser = findSocialUser(authResponse.getData().getUuid(), authResponse.getData().getSource());
            createOrUpdateSocialUser(socialUser, authResponse.getData());
            if (socialUser == null) {
                // 第一次登录
                bindId = genBindId(authResponse.getData());
            } else if (socialUser.getSysUserId() == null || socialUser.getSysUserId() <= 0) {
                // 初次绑定
                bindId = genBindId(authResponse.getData());
            } else {
                // 查看是否已经绑定
                SysUser sysUser = iSysUserService.selectUserById(socialUser.getSysUserId());
                if (sysUser == null) {
                    bindId = genBindId(authResponse.getData());
                } else {
                    // 直接登录跳转
                    loginId = genLoginId(sysUser);
                }
            }
            if (StringUtils.isNotEmpty(bindId)) {
                return authRequestWrap.getSocialPlatform().getBindUri() + bindId;
            } else {
                return authRequestWrap.getSocialPlatform().getRedirectLoginUri() + loginId;
            }
        } else {
            log.error("登录授权异常,code:{}, msg:{}", authResponse.getCode(), authResponse.getMsg());
            String errorId = genErrorId(authResponse.getMsg());
            return authRequestWrap.getSocialPlatform().getErrorMsgUri() + errorId;
        }
    } catch (AuthException authException) {
        // 返回错误信息
        log.error("", authException);
        if (authRequestWrap != null) {
            String errorId = genErrorId(authException.getMessage());
            return authRequestWrap.getSocialPlatform().getErrorMsgUri() + errorId;
        } else {
            return httpServletRequest.getServerName() + httpServletRequest.getServerPort();
        }
    } catch (Exception exception) {
        log.error("", exception);
        return HTTPS + httpServletRequest.getServerName();
    }
}
Also used : AuthRequestWrap(com.ruoyi.iot.model.login.AuthRequestWrap) SysUser(com.ruoyi.common.core.domain.entity.SysUser) SocialUser(com.ruoyi.iot.domain.SocialUser) AuthException(me.zhyd.oauth.exception.AuthException) AuthUser(me.zhyd.oauth.model.AuthUser) AuthException(me.zhyd.oauth.exception.AuthException)

Example 3 with SocialUser

use of com.ruoyi.iot.domain.SocialUser in project wumei-smart by kerwincui.

the class UserSocialProfileServiceImpl method selectUserSocialProfile.

@Override
public List<UserSocialProfile> selectUserSocialProfile(Long sysUserId) {
    SocialUser selectSocialUser = new SocialUser();
    selectSocialUser.setSysUserId(sysUserId);
    List<SocialUser> socialUserList = iSocialUserService.selectSocialUserList(selectSocialUser);
    List<UserSocialProfile> userSocialProfileList = new ArrayList<>();
    for (SocialUser socialUser : socialUserList) {
        // 如果是删除的标记
        if (socialUser.getDelFlag().equals("1")) {
            continue;
        }
        UserSocialProfile userSocialProfile = new UserSocialProfile();
        userSocialProfile.setSocialUserId(socialUser.getSocialUserId());
        userSocialProfile.setAvatar(socialUser.getAvatar());
        userSocialProfile.setSource(socialUser.getSource());
        userSocialProfile.setUsername(socialUser.getUsername());
        userSocialProfile.setNickname(socialUser.getNickname());
        userSocialProfile.setStatus(socialUser.getStatus());
        userSocialProfileList.add(userSocialProfile);
    }
    return userSocialProfileList;
}
Also used : SocialUser(com.ruoyi.iot.domain.SocialUser) ArrayList(java.util.ArrayList) UserSocialProfile(com.ruoyi.iot.domain.UserSocialProfile)

Example 4 with SocialUser

use of com.ruoyi.iot.domain.SocialUser in project wumei-smart by kerwincui.

the class UserSocialProfileServiceImpl method findSocialUser.

public SocialUser findSocialUser(String uuid, String source) {
    SocialUser socialUser = new SocialUser();
    socialUser.setSource(source);
    socialUser.setUuid(uuid);
    List<SocialUser> socialUserList = iSocialUserService.selectSocialUserList(socialUser);
    return socialUserList == null || socialUserList.isEmpty() ? null : socialUserList.get(0);
}
Also used : SocialUser(com.ruoyi.iot.domain.SocialUser)

Example 5 with SocialUser

use of com.ruoyi.iot.domain.SocialUser in project wumei-smart by kerwincui.

the class UserSocialProfileServiceImpl method bindUser.

@Override
public AjaxResult bindUser(String bindId, Long sysUserId) {
    BindIdValue bindValue = redisCache.getCacheObject(BIND_REDIS_KEY + bindId);
    if (bindValue == null) {
        // 不作提示
        return AjaxResult.error(HttpStatus.NO_MESSAGE_ALERT, "未知异常");
    }
    SocialUser socialUser = findSocialUser(bindValue.getUuid(), bindValue.getSource());
    SocialUser updateSocialUser = new SocialUser();
    updateSocialUser.setSocialUserId(socialUser.getSocialUserId());
    updateSocialUser.setSysUserId(sysUserId);
    iSocialUserService.updateSocialUser(updateSocialUser);
    redisCache.deleteObject(BIND_REDIS_KEY + bindId);
    return AjaxResult.success("绑定成功!");
}
Also used : SocialUser(com.ruoyi.iot.domain.SocialUser) BindIdValue(com.ruoyi.iot.model.login.BindIdValue)

Aggregations

SocialUser (com.ruoyi.iot.domain.SocialUser)8 BindIdValue (com.ruoyi.iot.model.login.BindIdValue)3 AjaxResult (com.ruoyi.common.core.domain.AjaxResult)2 SysUser (com.ruoyi.common.core.domain.entity.SysUser)2 LoginUser (com.ruoyi.common.core.domain.model.LoginUser)1 UserSocialProfile (com.ruoyi.iot.domain.UserSocialProfile)1 AuthRequestWrap (com.ruoyi.iot.model.login.AuthRequestWrap)1 ArrayList (java.util.ArrayList)1 AuthException (me.zhyd.oauth.exception.AuthException)1 AuthUser (me.zhyd.oauth.model.AuthUser)1