use of com.stardata.starshop2.authcontext.domain.user.WxOpenId in project starshop by beautautumn.
the class StarshopAuthLoginTests method should_load_exists_user_correctly_by_openid.
// 1.3. 根据openid查找用户记录;(相关任务,资源库端口,访问数据库)
@Test
@Transactional
@Rollback(true)
void should_load_exists_user_correctly_by_openid() {
// given: 创建新用户,并设置其openid后保存
WxOpenId openId = WxOpenId.of("testOpenIdX");
User user = User.of("testUserX", 1);
user.setOpenid(openId);
userRepository.add(user);
// when: 向资源库加入该用户,并重新从资源库根据openid重建用户对象
User loadedUser = userRepository.findByOpenId(openId);
// then: 重建的用户对象存在且OpenId等于给定的openid
assertNotNull(loadedUser);
assertEquals(openId, loadedUser.getOpenid());
}
use of com.stardata.starshop2.authcontext.domain.user.WxOpenId in project starshop by beautautumn.
the class WxLoginWithTokenService method loginWithToken.
public User loginWithToken(String code, WxAuthInfo wxAuthInfo, User loginUser) {
WxOpenId openid = wxLoginService.wxLogin(code, wxAuthInfo);
User user = userExistenceService.ensureUser(openid, loginUser);
userTokenService.generateLoginToken(user, wxAuthInfo.getSessionKey());
return user;
}
use of com.stardata.starshop2.authcontext.domain.user.WxOpenId in project starshop by beautautumn.
the class UserExistenceService method ensureUser.
public User ensureUser(WxOpenId openId, User userToEnsure) {
User user = userRepository.findByOpenId(openId);
if (user == null) {
userToEnsure.setOpenid(openId);
user = userToEnsure;
userRepository.add(user);
} else {
user.copyMiniAppInfoFrom(userToEnsure);
userRepository.update(user);
}
return user;
}
Aggregations