Search in sources :

Example 1 with IamUser

use of com.diboot.iam.entity.IamUser in project diboot by dibo-software.

the class WxMaUserAuthServiceImpl method bindWxMa.

@Override
public IamMember bindWxMa(WxMemberDTO wxInfoDTO) throws Exception {
    IamUser iamUser = IamSecurityUtils.getCurrentUser();
    if (V.isEmpty(iamUser)) {
        throw new BusinessException(Status.FAIL_OPERATION, "请登陆后绑定");
    }
    // 获取用户信息
    IamMember iamMember = iamMemberService.getSingleEntity(Wrappers.<IamMember>lambdaQuery().eq(IamMember::getUserType, IamUser.class.getSimpleName()).eq(IamMember::getUserId, iamUser.getId()));
    if (V.notEmpty(iamMember)) {
        throw new BusinessException(Status.FAIL_OPERATION, "用户已经绑定");
    }
    iamMember = maInfo2IamMemberEntity(wxInfoDTO).setUserId(iamUser.getId()).setOrgId(iamUser.getOrgId()).setUserType(IamUser.class.getSimpleName());
    boolean success = iamMemberService.createEntity(iamMember);
    if (!success) {
        throw new BusinessException(Status.FAIL_OPERATION, "绑定用户信息失败!");
    }
    // 创建当前用户的账户
    IamAccount iamAccount = createIamAccountEntity(iamMember, iamMember.getUserId(), IamUser.class);
    success = iamAccountService.createEntity(iamAccount);
    if (!success) {
        throw new BusinessException(Status.FAIL_OPERATION, "创建系统账户失败!");
    }
    return iamMember;
}
Also used : BusinessException(com.diboot.core.exception.BusinessException) IamAccount(com.diboot.iam.entity.IamAccount) IamUser(com.diboot.iam.entity.IamUser) IamMember(com.diboot.mobile.entity.IamMember)

Example 2 with IamUser

use of com.diboot.iam.entity.IamUser in project diboot by dibo-software.

the class WxMpUserAuthServiceImpl method bindWxMp.

@Override
public IamMember bindWxMp(String code, String state) throws Exception {
    // 校验STATE
    if (V.notEmpty(STATE) && !STATE.equals(state)) {
        throw new BusinessException(Status.FAIL_INVALID_PARAM, "非法来源");
    }
    if (V.isEmpty(code)) {
        log.error("请求参数有误: code = null");
        throw new BusinessException(Status.FAIL_INVALID_PARAM, "请求参数有误: code is null");
    }
    IamUser iamUser = IamSecurityUtils.getCurrentUser();
    if (V.isEmpty(iamUser)) {
        throw new BusinessException(Status.FAIL_OPERATION, "请登陆后绑定");
    }
    WxOAuth2AccessToken accessToken = wxMpService.getOAuth2Service().getAccessToken(code);
    // 获取用户信息
    IamMember iamMember = iamMemberService.getSingleEntity(Wrappers.<IamMember>lambdaQuery().eq(IamMember::getUserType, IamUser.class.getSimpleName()).eq(IamMember::getUserId, iamUser.getId()));
    if (V.notEmpty(iamMember)) {
        throw new BusinessException(Status.FAIL_OPERATION, "请勿重新绑定");
    }
    // 创建绑定
    WxOAuth2UserInfo userInfo = wxMpService.getOAuth2Service().getUserInfo(accessToken, null);
    iamMember = mpInfo2IamMemberEntity(userInfo).setUserId(iamUser.getId()).setOrgId(iamUser.getOrgId()).setUserType(IamUser.class.getSimpleName());
    iamMemberService.createEntity(iamMember);
    // 基于openId 创建iam_account账号
    IamAccount iamAccount = createIamAccountEntity(iamMember, iamMember.getUserId(), IamUser.class);
    iamAccountService.createEntity(iamAccount);
    return iamMember;
}
Also used : BusinessException(com.diboot.core.exception.BusinessException) IamAccount(com.diboot.iam.entity.IamAccount) IamUser(com.diboot.iam.entity.IamUser) IamMember(com.diboot.mobile.entity.IamMember) WxOAuth2AccessToken(me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken) WxOAuth2UserInfo(me.chanjar.weixin.common.bean.WxOAuth2UserInfo)

Aggregations

BusinessException (com.diboot.core.exception.BusinessException)2 IamAccount (com.diboot.iam.entity.IamAccount)2 IamUser (com.diboot.iam.entity.IamUser)2 IamMember (com.diboot.mobile.entity.IamMember)2 WxOAuth2UserInfo (me.chanjar.weixin.common.bean.WxOAuth2UserInfo)1 WxOAuth2AccessToken (me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken)1