diff --git a/Moonlight/App/Configuration/ConfigV1.cs b/Moonlight/App/Configuration/ConfigV1.cs index 053aa1c1..4c07e7d4 100644 --- a/Moonlight/App/Configuration/ConfigV1.cs +++ b/Moonlight/App/Configuration/ConfigV1.cs @@ -17,6 +17,8 @@ public class ConfigV1 [Description("The url moonlight is accesible with from the internet")] public string AppUrl { get; set; } = "http://your-moonlight-url-without-slash"; + [JsonProperty("Auth")] public AuthData Auth { get; set; } = new(); + [JsonProperty("Database")] public DatabaseData Database { get; set; } = new(); [JsonProperty("DiscordBotApi")] public DiscordBotApiData DiscordBotApi { get; set; } = new(); @@ -39,8 +41,7 @@ public class ConfigV1 [JsonProperty("Subscriptions")] public SubscriptionsData Subscriptions { get; set; } = new(); - [JsonProperty("DiscordNotifications")] - public DiscordNotificationsData DiscordNotifications { get; set; } = new(); + [JsonProperty("DiscordNotifications")] public DiscordNotificationsData DiscordNotifications { get; set; } = new(); [JsonProperty("Statistics")] public StatisticsData Statistics { get; set; } = new(); @@ -50,6 +51,17 @@ public class ConfigV1 [JsonProperty("Sentry")] public SentryData Sentry { get; set; } = new(); } + + public class AuthData + { + [JsonProperty("DenyLogin")] + [Description("Prevent every new login")] + public bool DenyLogin { get; set; } = false; + + [JsonProperty("DenyRegister")] + [Description("Prevent every new user to register")] + public bool DenyRegister { get; set; } = false; + } public class CleanupData { diff --git a/Moonlight/App/Services/UserService.cs b/Moonlight/App/Services/UserService.cs index 0869c3c8..2a611cb9 100644 --- a/Moonlight/App/Services/UserService.cs +++ b/Moonlight/App/Services/UserService.cs @@ -18,6 +18,7 @@ public class UserService private readonly IdentityService IdentityService; private readonly IpLocateService IpLocateService; private readonly DateTimeService DateTimeService; + private readonly ConfigService ConfigService; private readonly string JwtSecret; @@ -32,6 +33,7 @@ public class UserService { UserRepository = userRepository; TotpService = totpService; + ConfigService = configService; MailService = mailService; IdentityService = identityService; IpLocateService = ipLocateService; @@ -44,6 +46,9 @@ public class UserService public async Task Register(string email, string password, string firstname, string lastname) { + if (ConfigService.Get().Moonlight.Auth.DenyRegister) + throw new DisplayException("This operation was disabled"); + // Check if the email is already taken var emailTaken = UserRepository.Get().FirstOrDefault(x => x.Email == email) != null; @@ -108,6 +113,9 @@ public class UserService public async Task Login(string email, string password, string totpCode = "") { + if (ConfigService.Get().Moonlight.Auth.DenyLogin) + throw new DisplayException("This operation was disabled"); + // First password check and check if totp is enabled var needTotp = await CheckTotp(email, password);