diff --git a/config.properties b/config.properties index 39bd40a..fd063d7 100644 --- a/config.properties +++ b/config.properties @@ -23,6 +23,9 @@ FRONTEND_URL: https://piped.kavin.rocks # Enable haveibeenpwned compromised password API COMPROMISED_PASSWORD_CHECK: true +# Disable Registration +DISABLE_REGISTRATION: false + # Hibernate properties hibernate.connection.url: jdbc:postgresql://postgres:5432/piped hibernate.connection.driver_class: org.postgresql.Driver diff --git a/src/main/java/me/kavin/piped/consts/Constants.java b/src/main/java/me/kavin/piped/consts/Constants.java index 434bbb0..604554b 100644 --- a/src/main/java/me/kavin/piped/consts/Constants.java +++ b/src/main/java/me/kavin/piped/consts/Constants.java @@ -43,6 +43,8 @@ public class Constants { public static final boolean COMPROMISED_PASSWORD_CHECK; + public static final boolean DISABLE_REGISTRATION; + public static final ObjectMapper mapper = new ObjectMapper().addMixIn(Page.class, PageMixin.class); public static final Object2ObjectOpenHashMap hibernateProperties = new Object2ObjectOpenHashMap<>(); @@ -62,6 +64,7 @@ public class Constants { HTTP_PROXY = prop.getProperty("HTTP_PROXY"); FRONTEND_URL = prop.getProperty("FRONTEND_URL", "https://pipedapi.kavin.rocks"); COMPROMISED_PASSWORD_CHECK = Boolean.parseBoolean(prop.getProperty("COMPROMISED_PASSWORD_CHECK", "true")); + DISABLE_REGISTRATION = Boolean.parseBoolean(prop.getProperty("DISABLE_REGISTRATION", "false")); prop.forEach((_key, _value) -> { String key = String.valueOf(_key), value = String.valueOf(_value); if (key.startsWith("hibernate")) diff --git a/src/main/java/me/kavin/piped/utils/ResponseHelper.java b/src/main/java/me/kavin/piped/utils/ResponseHelper.java index 5ed568d..b5d75da 100644 --- a/src/main/java/me/kavin/piped/utils/ResponseHelper.java +++ b/src/main/java/me/kavin/piped/utils/ResponseHelper.java @@ -95,6 +95,7 @@ import me.kavin.piped.utils.resp.AcceptedResponse; import me.kavin.piped.utils.resp.AlreadyRegisteredResponse; import me.kavin.piped.utils.resp.AuthenticationFailureResponse; import me.kavin.piped.utils.resp.CompromisedPasswordResponse; +import me.kavin.piped.utils.resp.DisabledRegistrationResponse; import me.kavin.piped.utils.resp.IncorrectCredentialsResponse; import me.kavin.piped.utils.resp.InvalidRequestResponse; import me.kavin.piped.utils.resp.LoginResponse; @@ -546,6 +547,9 @@ public class ResponseHelper { public static final byte[] registerResponse(String user, String pass) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, InterruptedException, URISyntaxException { + if (Constants.DISABLE_REGISTRATION) + return Constants.mapper.writeValueAsBytes(new DisabledRegistrationResponse()); + if (user == null || pass == null) return Constants.mapper.writeValueAsBytes(new InvalidRequestResponse()); diff --git a/src/main/java/me/kavin/piped/utils/resp/DisabledRegistrationResponse.java b/src/main/java/me/kavin/piped/utils/resp/DisabledRegistrationResponse.java new file mode 100644 index 0000000..af53f0b --- /dev/null +++ b/src/main/java/me/kavin/piped/utils/resp/DisabledRegistrationResponse.java @@ -0,0 +1,7 @@ +package me.kavin.piped.utils.resp; + +public class DisabledRegistrationResponse { + + public String error = "This instance has registrations disabled."; + +}