use of com.fujieid.jap.core.JapUser in project ddd by EricFoxz.
the class ApplicationOauth2Service method getByPlatformAndUid.
/**
* 根据第三方平台标识(platform)和第三方平台的用户 uid 查询数据库
*
* @param platform 第三方平台标识
* @param uid 第三方平台的用户 uid
* @return JapUser
*/
@Override
public JapUser getByPlatformAndUid(String platform, String uid) {
SysUserEntity entity = new SysUserEntity();
entity.set_condition(SimpleCondition.newInstance().equals(SysUser.STRUCTURE.uuid, uid));
SysUserEntity sysUserEntity = sysUserService.findFirst(entity);
if (sysUserEntity == null) {
log.error("用户不存在platform:{}, uid: {}", platform, uid);
return null;
}
JapUser japUser = new JapUser();
japUser.setUsername(entity.getUsername());
japUser.setUserId(entity.getId().toString());
// japUser.setPassword(entity.get)
return japUser;
}
use of com.fujieid.jap.core.JapUser in project ddd by EricFoxz.
the class ApplicationOauth2Service method createAndGetOauth2User.
/**
* 创建并获取第三方用户,相当于第三方登录成功后,将授权关系保存到数据库
* (开发者业务系统中 oauth2 user -> sys user 的绑定关系)
*
* @param platform 第三方平台标识
* @param userInfo 第三方返回的用户信息
* @param tokenInfo token 信息,可以强制转换为 com.fujieid.jap.oauth2.token.AccessToken
* @return JapUser
*/
@Override
public JapUser createAndGetOauth2User(String platform, Map<String, Object> userInfo, Object tokenInfo) {
// FIXME 业务端可以对 tokenInfo 进行保存或其他操作
AccessToken accessToken = (AccessToken) tokenInfo;
System.out.println(JsonUtil.toJsonString(accessToken));
// FIXME 注意:此处仅作演示用,不同的 oauth 平台用户id都不一样,
// 此处需要开发者自己分析第三方平台的用户信息,提取出用户的唯一ID
String uid = (String) userInfo.get("userId");
// 查询绑定关系,确定当前用户是否已经登录过业务系统
JapUser japUser = this.getByPlatformAndUid(platform, uid);
if (null == japUser) {
// 保存用户
SysUserEntity sysUserEntity = new SysUserEntity();
sysUserService.register(sysUserEntity);
japUser = new JapUser();
japUser.setAdditional(userInfo);
// userData.add(japUser);
}
return japUser;
}
use of com.fujieid.jap.core.JapUser in project OneBlog by zhangyd-c.
the class OAuthController method renderAuth.
@RequestMapping("/social/{source}")
public ModelAndView renderAuth(@PathVariable("source") String source, HttpServletResponse response, HttpServletRequest request) {
SocialConfig socialConfig = sysSocialConfigService.getByPlatform(source);
if (null == socialConfig) {
throw new ZhydException(source + " 平台的配置尚未完成,暂时不支持登录!");
}
SocialStrategy socialStrategy = new SocialStrategy(japUserService, new JapConfig());
JapResponse japResponse = socialStrategy.authenticate(JapUtil.blogSocialConfig2JapSocialConfig(socialConfig, source), request, response);
if (!japResponse.isSuccess()) {
throw new ZhydException(japResponse.getMessage());
}
if (japResponse.isRedirectUrl()) {
return ResultUtil.redirect((String) japResponse.getData());
} else {
JapUser japUser = (JapUser) japResponse.getData();
User user = (User) japUser.getAdditional();
SessionUtil.setUser(user);
return ResultUtil.redirect("/");
}
}
use of com.fujieid.jap.core.JapUser in project OneBlog by zhangyd-c.
the class JapSocialUserServiceImpl method createAndGetSocialUser.
/**
* Save the social login user information to the database and return JapUser
* <p>
* It is suitable for the {@code jap-social} module
*
* @param userInfo User information obtained through justauth third-party login, type {@code me.zhyd.oauth.model.AuthUser}
* @return When saving successfully, return {@code JapUser}, otherwise return {@code null}
*/
@Override
public JapUser createAndGetSocialUser(Object userInfo) {
AuthUser authUser = (AuthUser) userInfo;
User newUser = BeanConvertUtil.doConvert(authUser, User.class);
newUser.setSource(authUser.getSource());
if (null != authUser.getGender()) {
newUser.setGender(Integer.valueOf(authUser.getGender().getCode()));
}
User user = userService.getByUuidAndSource(authUser.getUuid(), authUser.getSource());
newUser.setUserType(UserTypeEnum.USER);
if (null != user) {
newUser.setId(user.getId());
userService.updateSelective(newUser);
} else {
userService.insert(newUser);
}
try {
userService.updateUserLastLoginInfo(user);
} catch (Exception e) {
e.printStackTrace();
}
return new JapUser().setUserId(newUser.getId() + "").setUsername(newUser.getUsername()).setAdditional(newUser);
}
Aggregations