Add configuration property to disable registration.

This commit is contained in:
FireMaskterK 2021-11-09 06:27:29 +00:00
parent 2a87b7946d
commit ced7b0ee9e
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD
4 changed files with 17 additions and 0 deletions

View file

@ -23,6 +23,9 @@ FRONTEND_URL: https://piped.kavin.rocks
# Enable haveibeenpwned compromised password API # Enable haveibeenpwned compromised password API
COMPROMISED_PASSWORD_CHECK: true COMPROMISED_PASSWORD_CHECK: true
# Disable Registration
DISABLE_REGISTRATION: false
# Hibernate properties # Hibernate properties
hibernate.connection.url: jdbc:postgresql://postgres:5432/piped hibernate.connection.url: jdbc:postgresql://postgres:5432/piped
hibernate.connection.driver_class: org.postgresql.Driver hibernate.connection.driver_class: org.postgresql.Driver

View file

@ -43,6 +43,8 @@ public class Constants {
public static final boolean COMPROMISED_PASSWORD_CHECK; 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 ObjectMapper mapper = new ObjectMapper().addMixIn(Page.class, PageMixin.class);
public static final Object2ObjectOpenHashMap<String, String> hibernateProperties = new Object2ObjectOpenHashMap<>(); public static final Object2ObjectOpenHashMap<String, String> hibernateProperties = new Object2ObjectOpenHashMap<>();
@ -62,6 +64,7 @@ public class Constants {
HTTP_PROXY = prop.getProperty("HTTP_PROXY"); HTTP_PROXY = prop.getProperty("HTTP_PROXY");
FRONTEND_URL = prop.getProperty("FRONTEND_URL", "https://pipedapi.kavin.rocks"); FRONTEND_URL = prop.getProperty("FRONTEND_URL", "https://pipedapi.kavin.rocks");
COMPROMISED_PASSWORD_CHECK = Boolean.parseBoolean(prop.getProperty("COMPROMISED_PASSWORD_CHECK", "true")); COMPROMISED_PASSWORD_CHECK = Boolean.parseBoolean(prop.getProperty("COMPROMISED_PASSWORD_CHECK", "true"));
DISABLE_REGISTRATION = Boolean.parseBoolean(prop.getProperty("DISABLE_REGISTRATION", "false"));
prop.forEach((_key, _value) -> { prop.forEach((_key, _value) -> {
String key = String.valueOf(_key), value = String.valueOf(_value); String key = String.valueOf(_key), value = String.valueOf(_value);
if (key.startsWith("hibernate")) if (key.startsWith("hibernate"))

View file

@ -95,6 +95,7 @@ import me.kavin.piped.utils.resp.AcceptedResponse;
import me.kavin.piped.utils.resp.AlreadyRegisteredResponse; import me.kavin.piped.utils.resp.AlreadyRegisteredResponse;
import me.kavin.piped.utils.resp.AuthenticationFailureResponse; import me.kavin.piped.utils.resp.AuthenticationFailureResponse;
import me.kavin.piped.utils.resp.CompromisedPasswordResponse; 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.IncorrectCredentialsResponse;
import me.kavin.piped.utils.resp.InvalidRequestResponse; import me.kavin.piped.utils.resp.InvalidRequestResponse;
import me.kavin.piped.utils.resp.LoginResponse; 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, public static final byte[] registerResponse(String user, String pass) throws IOException, NoSuchAlgorithmException,
InvalidKeySpecException, InterruptedException, URISyntaxException { InvalidKeySpecException, InterruptedException, URISyntaxException {
if (Constants.DISABLE_REGISTRATION)
return Constants.mapper.writeValueAsBytes(new DisabledRegistrationResponse());
if (user == null || pass == null) if (user == null || pass == null)
return Constants.mapper.writeValueAsBytes(new InvalidRequestResponse()); return Constants.mapper.writeValueAsBytes(new InvalidRequestResponse());

View file

@ -0,0 +1,7 @@
package me.kavin.piped.utils.resp;
public class DisabledRegistrationResponse {
public String error = "This instance has registrations disabled.";
}