Search in sources :

Example 1 with LoginLog

use of com.stardata.starshop2.authcontext.domain.loginlog.LoginLog in project starshop by beautautumn.

the class StarshopAuthLoginTests method should_create_and_save_login_log_correctly_given_login_log.

// 5.1. 记录用户登录日志;(组合任务,领域服务)
@Test
@Transactional
@Rollback(true)
void should_create_and_save_login_log_correctly_given_login_log() {
    // given:
    WxOpenId openId = WxOpenId.of("testOpenId");
    User user = User.of("testUser", 2).avatarUrl("testUrl").country("testCountry").province("testProvince").city("testCity").language("testLanguage");
    user.setOpenid(openId);
    userRepository.add(user);
    // when: 调用 loginLogService.recordLogin
    LoginLog loginLog = loginLogService.recordLogin(user, "testIp");
    entityManager.flush();
    LoginLog loadedLog = loginLogRepository.instanceOf(loginLog.getId());
    // then: 创建了有效的登录日志
    assertNotNull(loadedLog);
    assertNotNull(loadedLog.getLastLoginTime());
    LocalDateTime now = LocalDateTime.now();
    assertTrue(loadedLog.getLastLoginTime().isBefore(now.plusSeconds(1)));
}
Also used : LocalDateTime(java.time.LocalDateTime) LoginLog(com.stardata.starshop2.authcontext.domain.loginlog.LoginLog) User(com.stardata.starshop2.authcontext.domain.user.User) WxOpenId(com.stardata.starshop2.authcontext.domain.user.WxOpenId) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with LoginLog

use of com.stardata.starshop2.authcontext.domain.loginlog.LoginLog 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;
}
Also used : LoginLog(com.stardata.starshop2.authcontext.domain.loginlog.LoginLog)

Aggregations

LoginLog (com.stardata.starshop2.authcontext.domain.loginlog.LoginLog)2 User (com.stardata.starshop2.authcontext.domain.user.User)1 WxOpenId (com.stardata.starshop2.authcontext.domain.user.WxOpenId)1 LocalDateTime (java.time.LocalDateTime)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Rollback (org.springframework.test.annotation.Rollback)1 Transactional (org.springframework.transaction.annotation.Transactional)1