From 9d0d5b86aae025e4647bb664c6412d42192e2fe7 Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Tue, 2 Feb 2021 20:16:44 -0500 Subject: [PATCH] feat(ui): Add local login setting (#817) --- overseerr-api.yml | 3 ++ server/interfaces/api/settingsInterfaces.ts | 1 + server/lib/settings.ts | 4 ++ server/routes/auth.ts | 5 ++- src/components/Login/index.tsx | 40 ++++++++++++------- src/components/Settings/SettingsMain.tsx | 27 +++++++++++-- .../Settings/SettingsNotifications.tsx | 4 +- src/components/Settings/SettingsPlex.tsx | 2 +- src/context/SettingsContext.tsx | 1 + src/i18n/locale/en.json | 2 + src/pages/_app.tsx | 1 + 11 files changed, 68 insertions(+), 22 deletions(-) diff --git a/overseerr-api.yml b/overseerr-api.yml index 56ae1916..c8e7cea4 100644 --- a/overseerr-api.yml +++ b/overseerr-api.yml @@ -71,6 +71,9 @@ components: hideAvailable: type: boolean example: false + localLogin: + type: boolean + example: true defaultPermissions: type: number example: 32 diff --git a/server/interfaces/api/settingsInterfaces.ts b/server/interfaces/api/settingsInterfaces.ts index 41abaf91..ba46e66b 100644 --- a/server/interfaces/api/settingsInterfaces.ts +++ b/server/interfaces/api/settingsInterfaces.ts @@ -10,6 +10,7 @@ export interface PublicSettingsResponse { movie4kEnabled: boolean; series4kEnabled: boolean; hideAvailable: boolean; + localLogin: boolean; } export interface CacheItem { diff --git a/server/lib/settings.ts b/server/lib/settings.ts index 1209ec30..9312ee37 100644 --- a/server/lib/settings.ts +++ b/server/lib/settings.ts @@ -54,6 +54,7 @@ export interface MainSettings { csrfProtection: boolean; defaultPermissions: number; hideAvailable: boolean; + localLogin: boolean; trustProxy: boolean; } @@ -65,6 +66,7 @@ interface FullPublicSettings extends PublicSettings { movie4kEnabled: boolean; series4kEnabled: boolean; hideAvailable: boolean; + localLogin: boolean; } export interface NotificationAgentConfig { @@ -162,6 +164,7 @@ class Settings { csrfProtection: false, defaultPermissions: Permission.REQUEST, hideAvailable: false, + localLogin: true, trustProxy: false, }, plex: { @@ -296,6 +299,7 @@ class Settings { (sonarr) => sonarr.is4k && sonarr.isDefault ), hideAvailable: this.data.main.hideAvailable, + localLogin: this.data.main.localLogin, }; } diff --git a/server/routes/auth.ts b/server/routes/auth.ts index f1b68d34..1fd21dac 100644 --- a/server/routes/auth.ts +++ b/server/routes/auth.ts @@ -134,10 +134,13 @@ authRoutes.post('/login', async (req, res, next) => { }); authRoutes.post('/local', async (req, res, next) => { + const settings = getSettings(); const userRepository = getRepository(User); const body = req.body as { email?: string; password?: string }; - if (!body.email || !body.password) { + if (!settings.main.localLogin) { + return res.status(500).json({ error: 'Local user login is disabled' }); + } else if (!body.email || !body.password) { return res .status(500) .json({ error: 'You must provide an email and a password' }); diff --git a/src/components/Login/index.tsx b/src/components/Login/index.tsx index ea4d2f41..bfd88997 100644 --- a/src/components/Login/index.tsx +++ b/src/components/Login/index.tsx @@ -9,6 +9,7 @@ import Transition from '../Transition'; import LanguagePicker from '../Layout/LanguagePicker'; import LocalLogin from './LocalLogin'; import Accordion from '../Common/Accordion'; +import useSettings from '../../hooks/useSettings'; const messages = defineMessages({ signinheader: 'Sign in to continue', @@ -23,6 +24,7 @@ const Login: React.FC = () => { const [authToken, setAuthToken] = useState(undefined); const { user, revalidate } = useUser(); const router = useRouter(); + const settings = useSettings(); // Effect that is triggered when the `authToken` comes back from the Plex OAuth // We take the token and attempt to login. If we get a success message, we will @@ -124,10 +126,14 @@ const Login: React.FC = () => { {({ openIndexes, handleClick, AccordionContent }) => ( <> @@ -139,21 +145,25 @@ const Login: React.FC = () => { /> - - -
- + {settings.currentSettings.localLogin && ( +
+ + +
+ +
+
- + )} )} diff --git a/src/components/Settings/SettingsMain.tsx b/src/components/Settings/SettingsMain.tsx index 2092470a..16f6d69f 100644 --- a/src/components/Settings/SettingsMain.tsx +++ b/src/components/Settings/SettingsMain.tsx @@ -35,6 +35,9 @@ const messages = defineMessages({ trustProxy: 'Enable Proxy Support', trustProxyTip: 'Allows Overseerr to correctly register client IP addresses behind a proxy (Overseerr must be reloaded for changes to take effect)', + localLogin: 'Enable Local User Sign-In', + localLoginTip: + 'Disabling this option only prevents new sign-ins (no user data is deleted)', }); const SettingsMain: React.FC = () => { @@ -83,6 +86,7 @@ const SettingsMain: React.FC = () => { csrfProtection: data?.csrfProtection, defaultPermissions: data?.defaultPermissions ?? 0, hideAvailable: data?.hideAvailable, + localLogin: data?.localLogin, trustProxy: data?.trustProxy, }} enableReinitialize @@ -93,6 +97,7 @@ const SettingsMain: React.FC = () => { csrfProtection: values.csrfProtection, defaultPermissions: values.defaultPermissions, hideAvailable: values.hideAvailable, + localLogin: values.localLogin, trustProxy: values.trustProxy, }); @@ -172,9 +177,7 @@ const SettingsMain: React.FC = () => {
+
+ +
+ { + setFieldValue('localLogin', !values.localLogin); + }} + /> +
+
{
@@ -222,7 +222,7 @@ const SettingsNotifications: React.FC = ({ children }) => {
diff --git a/src/components/Settings/SettingsPlex.tsx b/src/components/Settings/SettingsPlex.tsx index 6d7afed8..a39b31c3 100644 --- a/src/components/Settings/SettingsPlex.tsx +++ b/src/components/Settings/SettingsPlex.tsx @@ -351,7 +351,7 @@ const SettingsPlex: React.FC = ({ onComplete }) => {