use of com.stardata.starshop2.authcontext.domain.user.User in project starshop by beautautumn.
the class StarshopAuthLoginTests method after_set_openid_should_get_openid_correctly.
// 1.2. 设置新用户openid;(相关任务,"用户"聚合行为)
@Test
void after_set_openid_should_get_openid_correctly() {
// given: 准备好openid,并创建user对象
WxOpenId openId = WxOpenId.of("o9Nvx4gUq9dfO1KQy7LL-gXS_EkI");
User user = User.of("testUser", 1);
// when: 为user对象赋值openId
user.setOpenid(openId);
// then: 新用户的OpenId等于原先的OpenId
assertEquals(user.getOpenid(), openId);
}
use of com.stardata.starshop2.authcontext.domain.user.User in project starshop by beautautumn.
the class StarshopAuthLoginTests method should_update_token_to_different_if_refresh_twice_for_given_user.
// 2.2. 创建用户登录令牌;(相关任务,用户聚合行为,用户原来有令牌,更新令牌)
@Test
void should_update_token_to_different_if_refresh_twice_for_given_user() {
// given: 一个新用户
User newUser = User.of("testUser", 1);
String sessionKey = "testSessionKey";
// when: 调用User.refreshLoginToken创建两次令牌
UserToken tokenOld = newUser.refreshLoginToken(sessionKey);
UserToken tokenNew = newUser.refreshLoginToken(sessionKey);
// then: 两次用户令牌不一样
assertNotNull(tokenOld);
assertNotNull(tokenNew);
assertNotNull(newUser.currentToken());
assertNotEquals(tokenOld.getToken(), tokenNew.getToken());
}
use of com.stardata.starshop2.authcontext.domain.user.User 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.User 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.User in project starshop by beautautumn.
the class LoginLogService method recordLogin.
public LoginLog recordLogin(User user, String loginIp) {
LoginLog log = LoginLog.createFor(user, loginIp);
logRepository.add(log);
return log;
}
Aggregations