mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Add configuration property to disable registration.
This commit is contained in:
parent
2a87b7946d
commit
ced7b0ee9e
4 changed files with 17 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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<String, String> 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"))
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package me.kavin.piped.utils.resp;
|
||||
|
||||
public class DisabledRegistrationResponse {
|
||||
|
||||
public String error = "This instance has registrations disabled.";
|
||||
|
||||
}
|
Loading…
Reference in a new issue