From 091d66a1928d3c69a11eab2a789b4639b5ba9817 Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Wed, 9 Jun 2021 23:56:33 -0400 Subject: [PATCH] fix: check that application URL and email agent are configured for password reset/generation (#1724) * fix: check that application URL and email agent are configured for password reset/generation * refactor: reverse flex direction instead of conditionally changing justify --- server/interfaces/api/settingsInterfaces.ts | 2 ++ server/lib/settings.ts | 4 +++ src/components/Login/LocalLogin.tsx | 32 ++++++++++++------- .../ResetPassword/RequestResetLink.tsx | 2 +- src/components/ResetPassword/index.tsx | 2 +- .../Notifications/NotificationsEmail.tsx | 3 +- src/components/UserList/index.tsx | 32 +++++++++---------- src/context/SettingsContext.tsx | 2 ++ src/i18n/locale/en.json | 2 +- src/pages/_app.tsx | 2 ++ 10 files changed, 51 insertions(+), 32 deletions(-) diff --git a/server/interfaces/api/settingsInterfaces.ts b/server/interfaces/api/settingsInterfaces.ts index a55b71b3..924023d4 100644 --- a/server/interfaces/api/settingsInterfaces.ts +++ b/server/interfaces/api/settingsInterfaces.ts @@ -22,6 +22,7 @@ export interface SettingsAboutResponse { export interface PublicSettingsResponse { initialized: boolean; applicationTitle: string; + applicationUrl: string; hideAvailable: boolean; localLogin: boolean; movie4kEnabled: boolean; @@ -33,6 +34,7 @@ export interface PublicSettingsResponse { vapidPublic: string; enablePushRegistration: boolean; locale: string; + emailEnabled: boolean; } export interface CacheItem { diff --git a/server/lib/settings.ts b/server/lib/settings.ts index 6c91dabc..656be868 100644 --- a/server/lib/settings.ts +++ b/server/lib/settings.ts @@ -98,6 +98,7 @@ interface PublicSettings { interface FullPublicSettings extends PublicSettings { applicationTitle: string; + applicationUrl: string; hideAvailable: boolean; localLogin: boolean; movie4kEnabled: boolean; @@ -109,6 +110,7 @@ interface FullPublicSettings extends PublicSettings { vapidPublic: string; enablePushRegistration: boolean; locale: string; + emailEnabled: boolean; } export interface NotificationAgentConfig { @@ -396,6 +398,7 @@ class Settings { return { ...this.data.public, applicationTitle: this.data.main.applicationTitle, + applicationUrl: this.data.main.applicationUrl, hideAvailable: this.data.main.hideAvailable, localLogin: this.data.main.localLogin, movie4kEnabled: this.data.radarr.some( @@ -411,6 +414,7 @@ class Settings { vapidPublic: this.vapidPublic, enablePushRegistration: this.data.notifications.agents.webpush.enabled, locale: this.data.main.locale, + emailEnabled: this.data.notifications.agents.email.enabled, }; } diff --git a/src/components/Login/LocalLogin.tsx b/src/components/Login/LocalLogin.tsx index 71b815fd..ece109fe 100644 --- a/src/components/Login/LocalLogin.tsx +++ b/src/components/Login/LocalLogin.tsx @@ -5,6 +5,7 @@ import Link from 'next/link'; import React, { useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import * as Yup from 'yup'; +import useSettings from '../../hooks/useSettings'; import Button from '../Common/Button'; import SensitiveInput from '../Common/SensitiveInput'; @@ -25,6 +26,7 @@ interface LocalLoginProps { const LocalLogin: React.FC = ({ revalidate }) => { const intl = useIntl(); + const settings = useSettings(); const [loginError, setLoginError] = useState(null); const LoginSchema = Yup.object().shape({ @@ -36,6 +38,10 @@ const LocalLogin: React.FC = ({ revalidate }) => { ), }); + const passwordResetEnabled = + settings.currentSettings.applicationUrl && + settings.currentSettings.emailEnabled; + return ( = ({ revalidate }) => { return ( <>
-
+
@@ -101,17 +107,7 @@ const LocalLogin: React.FC = ({ revalidate }) => { )}
-
- - - - - +
+ {passwordResetEnabled && ( + + + + + + )}
diff --git a/src/components/ResetPassword/RequestResetLink.tsx b/src/components/ResetPassword/RequestResetLink.tsx index 0cf20abb..49fc5afe 100644 --- a/src/components/ResetPassword/RequestResetLink.tsx +++ b/src/components/ResetPassword/RequestResetLink.tsx @@ -94,7 +94,7 @@ const ResetPassword: React.FC = () => { {({ errors, touched, isSubmitting, isValid }) => { return (
-
+