diff options
author | Vitaly Takmazov | 2018-09-26 22:19:55 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-09-26 22:19:55 +0300 |
commit | 3dd5abdfd328a9dc95152639cf1773336502a23b (patch) | |
tree | 50a2df323f83fa14971e2014574d6fd0d6d595a9 /juick-server/src/main/java | |
parent | 80ad470b209eb11dd0225bb8c4d053787d6e4b4a (diff) |
make SapeConfiguration conditional on sape token
Diffstat (limited to 'juick-server/src/main/java')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/configuration/SapeConfiguration.java | 4 | ||||
-rw-r--r-- | juick-server/src/main/java/com/juick/server/www/controllers/MessagesWWW.java | 19 |
2 files changed, 13 insertions, 10 deletions
diff --git a/juick-server/src/main/java/com/juick/server/configuration/SapeConfiguration.java b/juick-server/src/main/java/com/juick/server/configuration/SapeConfiguration.java index 53b29415..9727fbb1 100644 --- a/juick-server/src/main/java/com/juick/server/configuration/SapeConfiguration.java +++ b/juick-server/src/main/java/com/juick/server/configuration/SapeConfiguration.java @@ -18,6 +18,7 @@ package com.juick.server.configuration; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import ru.sape.Sape; @@ -26,8 +27,9 @@ import ru.sape.Sape; * Created by vitalyster on 29.03.2017. */ @Configuration +@ConditionalOnProperty("sape_user") public class SapeConfiguration { - @Value("${sape_user:secret}") + @Value("${sape_user:}") private String token; @Bean diff --git a/juick-server/src/main/java/com/juick/server/www/controllers/MessagesWWW.java b/juick-server/src/main/java/com/juick/server/www/controllers/MessagesWWW.java index 130e1990..47c52cb9 100644 --- a/juick-server/src/main/java/com/juick/server/www/controllers/MessagesWWW.java +++ b/juick-server/src/main/java/com/juick/server/www/controllers/MessagesWWW.java @@ -45,6 +45,7 @@ import java.io.IOException; import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; /** @@ -60,7 +61,7 @@ public class MessagesWWW { @Inject private MessagesService messagesService; @Inject - private Sape sape; + private Optional<Sape> sape; @Inject private PMQueriesService pmQueriesService; @Inject @@ -180,8 +181,8 @@ public class MessagesWWW { UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequestUri().build(); String queryString = builder.getQuery(); String requestURI = builder.toUri().getPath(); - if (sape != null && visitor.isAnonymous() && queryString == null) { - String links = sape.getPageLinks(requestURI, sapeCookie).render(); + if (sape.isPresent() && visitor.isAnonymous() && queryString == null) { + String links = sape.get().getPageLinks(requestURI, sapeCookie).render(); model.addAttribute("links", links); } return "views/index"; @@ -299,8 +300,8 @@ public class MessagesWWW { UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequestUri().build(); String queryString = builder.getQuery(); String requestURI = builder.toUri().getPath(); - if (sape != null && visitor.isAnonymous() && queryString == null) { - String links = sape.getPageLinks(requestURI, sapeCookie).render(); + if (sape.isPresent() && visitor.isAnonymous() && queryString == null) { + String links = sape.get().getPageLinks(requestURI, sapeCookie).render(); model.addAttribute("links", links); } return "views/blog"; @@ -439,8 +440,8 @@ public class MessagesWWW { UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequestUri().build(); String queryString = builder.getQuery(); String requestURI = builder.toUri().getPath(); - if (sape != null && visitor.isAnonymous() && queryString == null) { - String links = sape.getPageLinks(requestURI, sapeCookie).render(); + if (sape.isPresent() && visitor.isAnonymous() && queryString == null) { + String links = sape.get().getPageLinks(requestURI, sapeCookie).render(); model.addAttribute("links", links); } return "views/index"; @@ -576,8 +577,8 @@ public class MessagesWWW { UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequestUri().build(); String queryString = builder.getQuery(); String requestURI = builder.toUri().getPath(); - if (sape != null && visitor.isAnonymous() && queryString == null) { - String links = sape.getPageLinks(requestURI, sapeCookie).render(); + if (sape.isPresent() && visitor.isAnonymous() && queryString == null) { + String links = sape.get().getPageLinks(requestURI, sapeCookie).render(); model.addAttribute("links", links); } return "views/thread"; |