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);
}
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;
}
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;
}
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);
}
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);
}
}
Aggregations