Search in sources :

Example 1 with IamMember

use of com.diboot.mobile.entity.IamMember in project diboot by dibo-software.

the class WxMaMemberAuthServiceImpl method getAndSaveWxMember.

@Override
public IamMemberVO getAndSaveWxMember(WxMemberDTO wxInfoDTO) {
    // 校验用户是否存在,如果已经存在,那么直接返回数据
    IamMember iamMember = iamMemberService.getSingleEntity(Wrappers.<IamMember>lambdaQuery().eq(IamMember::getOpenid, wxInfoDTO.getOpenid()).eq(IamMember::getStatus, Cons.DICTCODE_ACCOUNT_STATUS.A.name()));
    if (V.notEmpty(iamMember)) {
        return Binder.convertAndBindRelations(iamMember, IamMemberVO.class);
    }
    // 创建微信用户基本信息
    IamMember wxMember = maInfo2IamMemberEntity(wxInfoDTO).setUserId(0L).setOrgId(0L).setUserType(IamMember.class.getSimpleName());
    boolean success = iamMemberService.createEntity(wxMember);
    if (!success) {
        throw new BusinessException(Status.FAIL_OPERATION, "创建用户信息失败!");
    }
    // 创建当前用户的账户
    IamAccount iamAccount = createIamAccountEntity(wxMember, wxMember.getId(), IamMember.class);
    success = iamAccountService.createEntity(iamAccount);
    if (!success) {
        throw new BusinessException(Status.FAIL_OPERATION, "创建系统账户失败!");
    }
    return Binder.convertAndBindRelations(wxMember, IamMemberVO.class);
}
Also used : BusinessException(com.diboot.core.exception.BusinessException) IamAccount(com.diboot.iam.entity.IamAccount) IamMember(com.diboot.mobile.entity.IamMember)

Example 2 with IamMember

use of com.diboot.mobile.entity.IamMember 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 3 with IamMember

use of com.diboot.mobile.entity.IamMember 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)

Example 4 with IamMember

use of com.diboot.mobile.entity.IamMember in project diboot by dibo-software.

the class WxMpMemberAuthServiceImpl method applyToken.

@Override
@Transactional(rollbackFor = Exception.class)
public String applyToken(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");
    }
    WxOAuth2AccessToken accessToken = wxMpService.getOAuth2Service().getAccessToken(code);
    // 获取用户信息
    IamAccount account = iamAccountService.getSingleEntity(Wrappers.<IamAccount>lambdaQuery().eq(IamAccount::getUserType, IamMember.class.getSimpleName()).eq(IamAccount::getAuthAccount, accessToken.getOpenId()).eq(IamAccount::getAuthType, Cons.DICTCODE_AUTH_TYPE.WX_MP.name()));
    MobileCredential credential = new MobileCredential(accessToken.getOpenId());
    credential.setAuthType(Cons.DICTCODE_AUTH_TYPE.WX_MP.name());
    credential.setUserTypeClass(IamMember.class);
    // 账户存在,直接登陆
    if (V.notEmpty(account)) {
        return AuthServiceFactory.getAuthService(Cons.DICTCODE_AUTH_TYPE.WX_MP.name()).applyToken(credential);
    }
    // 账户不存在,表示首次进入,那么需要存储信息
    WxOAuth2UserInfo userInfo = wxMpService.getOAuth2Service().getUserInfo(accessToken, null);
    IamMember iamMember = mpInfo2IamMemberEntity(userInfo).setUserId(0L).setOrgId(0L).setUserType(IamMember.class.getSimpleName());
    iamMemberService.createEntity(iamMember);
    // 创建iam_account账号
    IamAccount iamAccount = createIamAccountEntity(iamMember, iamMember.getId(), IamMember.class);
    iamAccountService.createEntity(iamAccount);
    return AuthServiceFactory.getAuthService(Cons.DICTCODE_AUTH_TYPE.WX_MP.name()).applyToken(credential);
}
Also used : MobileCredential(com.diboot.mobile.dto.MobileCredential) BusinessException(com.diboot.core.exception.BusinessException) IamAccount(com.diboot.iam.entity.IamAccount) IamMember(com.diboot.mobile.entity.IamMember) WxOAuth2AccessToken(me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken) WxOAuth2UserInfo(me.chanjar.weixin.common.bean.WxOAuth2UserInfo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with IamMember

use of com.diboot.mobile.entity.IamMember in project diboot by dibo-software.

the class MobilePluginInitializer method insertInitData.

/**
 * 插入初始化数据
 */
private synchronized void insertInitData() {
    // 插入mobile组件所需的数据字典
    // 插入iam组件所需的数据字典
    DictionaryService dictionaryService = ContextHelper.getBean(DictionaryService.class);
    if (dictionaryService != null && !dictionaryService.exists(Dictionary::getType, "MEMBER_STATUS")) {
        String[] DICT_INIT_DATA = { "{\"type\":\"MEMBER_STATUS\", \"itemName\":\"用户状态\", \"description\":\"Member用户状态\", \"children\":[{\"itemName\":\"有效\", \"itemValue\":\"A\", \"sortId\":1},{\"itemName\":\"无效\", \"itemValue\":\"I\", \"sortId\":2}]}" };
        // 插入数据字典
        for (String dictJson : DICT_INIT_DATA) {
            DictionaryVO dictVo = JSON.toJavaObject(dictJson, DictionaryVO.class);
            dictionaryService.createDictAndChildren(dictVo);
        }
        DICT_INIT_DATA = null;
    }
    IamMemberService iamMemberService = ContextHelper.getBean(IamMemberService.class);
    if (iamMemberService != null && iamMemberService.getEntityListCount(null) == 0) {
        IamMember iamMember = new IamMember();
        iamMember.setOrgId(0L).setNickname("DIBOOT-Mobile").setStatus(Cons.DICTCODE_ACCOUNT_STATUS.A.name()).setUserType(IamMember.class.getSimpleName()).setUserId(0L).setGender("M").setOpenid(S.newUuid());
        iamMemberService.createEntity(iamMember);
        // 创建账号
        IamAccount iamAccount = new IamAccount();
        iamAccount.setUserType(IamMember.class.getSimpleName()).setUserId(iamMember.getId()).setAuthType(Cons.DICTCODE_AUTH_TYPE.PWD.name()).setAuthAccount("admin").setAuthSecret("123456");
        ContextHelper.getBean(IamAccountService.class).createEntity(iamAccount);
    }
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) DictionaryService(com.diboot.core.service.DictionaryService) DictionaryVO(com.diboot.core.vo.DictionaryVO) IamMember(com.diboot.mobile.entity.IamMember) IamMemberService(com.diboot.mobile.service.IamMemberService)

Aggregations

IamMember (com.diboot.mobile.entity.IamMember)5 BusinessException (com.diboot.core.exception.BusinessException)4 IamAccount (com.diboot.iam.entity.IamAccount)4 IamUser (com.diboot.iam.entity.IamUser)2 WxOAuth2UserInfo (me.chanjar.weixin.common.bean.WxOAuth2UserInfo)2 WxOAuth2AccessToken (me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken)2 Dictionary (com.diboot.core.entity.Dictionary)1 DictionaryService (com.diboot.core.service.DictionaryService)1 DictionaryVO (com.diboot.core.vo.DictionaryVO)1 MobileCredential (com.diboot.mobile.dto.MobileCredential)1 IamMemberService (com.diboot.mobile.service.IamMemberService)1 Transactional (org.springframework.transaction.annotation.Transactional)1