diff --git a/src/main/java/run/halo/app/controller/admin/api/InstallController.java b/src/main/java/run/halo/app/controller/admin/api/InstallController.java index fadac944a..b3ab6146d 100644 --- a/src/main/java/run/halo/app/controller/admin/api/InstallController.java +++ b/src/main/java/run/halo/app/controller/admin/api/InstallController.java @@ -43,6 +43,7 @@ import run.halo.app.service.PostCommentService; import run.halo.app.service.PostService; import run.halo.app.service.SheetService; import run.halo.app.service.UserService; +import run.halo.app.utils.DateUtils; import run.halo.app.utils.ValidationUtils; /** @@ -296,6 +297,7 @@ public class InstallController { StringUtils.isBlank(installParam.getUrl()) ? optionService.getBlogBaseUrl() : installParam.getUrl()); properties.put(OtherProperties.GLOBAL_ABSOLUTE_PATH_ENABLED, Boolean.FALSE.toString()); + properties.put(PrimaryProperties.BIRTHDAY, String.valueOf(DateUtils.now().getTime())); // Create properties optionService.saveProperties(properties); diff --git a/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java b/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java index 52d890c3f..55446e02b 100644 --- a/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java @@ -1,8 +1,6 @@ package run.halo.app.service.impl; -import com.qiniu.common.Zone; import com.qiniu.storage.Region; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; @@ -10,7 +8,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Optional; import java.util.Set; import javax.persistence.criteria.Predicate; import lombok.extern.slf4j.Slf4j; @@ -28,28 +25,22 @@ import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.event.options.OptionUpdatedEvent; -import run.halo.app.exception.MissingPropertyException; -import run.halo.app.model.dto.OptionDTO; import run.halo.app.model.dto.OptionSimpleDTO; import run.halo.app.model.entity.Option; import run.halo.app.model.enums.PostPermalinkType; import run.halo.app.model.enums.SheetPermalinkType; -import run.halo.app.model.enums.ValueEnum; import run.halo.app.model.params.OptionParam; import run.halo.app.model.params.OptionQuery; import run.halo.app.model.properties.BlogProperties; import run.halo.app.model.properties.CommentProperties; -import run.halo.app.model.properties.OtherProperties; import run.halo.app.model.properties.PermalinkProperties; import run.halo.app.model.properties.PostProperties; import run.halo.app.model.properties.PrimaryProperties; import run.halo.app.model.properties.PropertyEnum; import run.halo.app.model.properties.QiniuOssProperties; -import run.halo.app.model.properties.SeoProperties; import run.halo.app.repository.OptionRepository; import run.halo.app.service.OptionService; import run.halo.app.service.base.AbstractCrudService; -import run.halo.app.utils.DateUtils; import run.halo.app.utils.ServiceUtils; import run.halo.app.utils.ValidationUtils; @@ -373,11 +364,7 @@ public class OptionServiceImpl extends AbstractCrudService @Override public long getBirthday() { - return getByProperty(PrimaryProperties.BIRTHDAY, Long.class).orElseGet(() -> { - long currentTime = DateUtils.now().getTime(); - saveProperty(PrimaryProperties.BIRTHDAY, String.valueOf(currentTime)); - return currentTime; - }); + return Long.parseLong(getByPropertyOrDefault(PrimaryProperties.BIRTHDAY, String.class)); } @Override diff --git a/src/test/java/run/halo/app/security/OneTimeTokenTest.java b/src/test/java/run/halo/app/security/OneTimeTokenTest.java index be1e783a1..8d6a599d0 100644 --- a/src/test/java/run/halo/app/security/OneTimeTokenTest.java +++ b/src/test/java/run/halo/app/security/OneTimeTokenTest.java @@ -7,7 +7,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static run.halo.app.service.OptionService.OPTIONS_KEY; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -16,7 +20,10 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; +import run.halo.app.cache.AbstractStringCacheStore; +import run.halo.app.model.properties.PrimaryProperties; import run.halo.app.security.service.OneTimeTokenService; +import run.halo.app.utils.DateUtils; @SpringBootTest(webEnvironment = RANDOM_PORT) @ActiveProfiles("test") @@ -31,6 +38,20 @@ class OneTimeTokenTest { @Autowired OneTimeTokenService oneTimeTokenService; + @Autowired + AbstractStringCacheStore cacheStore; + + Map map = new HashMap<>(); + + { + map.put(PrimaryProperties.BIRTHDAY.getValue(), String.valueOf(DateUtils.now().getTime())); + } + + @BeforeEach + void setUp() { + cacheStore.putAny(OPTIONS_KEY, map); + } + @Test void provideNonExistOneTimeTokenTest() throws Exception { mvc.perform(get(REQUEST_URI + "?ott={ott}", "one-time-token-value"))