feat: remove email requirement for jellyfin/emby non-admin users

This commit is contained in:
notfakie
2022-04-24 14:58:25 +12:00
parent 791106a7f5
commit 3e1e11d9d9
2 changed files with 20 additions and 34 deletions

View File

@@ -1,4 +1,4 @@
import React, { useState } from 'react'; import React from 'react';
import { defineMessages, useIntl } from 'react-intl'; import { defineMessages, useIntl } from 'react-intl';
import Button from '../Common/Button'; import Button from '../Common/Button';
@@ -7,7 +7,6 @@ import * as Yup from 'yup';
import axios from 'axios'; import axios from 'axios';
import { useToasts } from 'react-toast-notifications'; import { useToasts } from 'react-toast-notifications';
import useSettings from '../../hooks/useSettings'; import useSettings from '../../hooks/useSettings';
import AddEmailModal from './AddEmailModal';
const messages = defineMessages({ const messages = defineMessages({
username: 'Username', username: 'Username',
@@ -38,9 +37,6 @@ const JellyfinLogin: React.FC<JellyfinLoginProps> = ({
revalidate, revalidate,
initial, initial,
}) => { }) => {
const [requiresEmail, setRequiresEmail] = useState<number>(0);
const [username, setUsername] = useState<string>();
const [password, setPassword] = useState<string>();
const toasts = useToasts(); const toasts = useToasts();
const intl = useIntl(); const intl = useIntl();
const settings = useSettings(); const settings = useSettings();
@@ -195,14 +191,6 @@ const JellyfinLogin: React.FC<JellyfinLoginProps> = ({
}); });
return ( return (
<div> <div>
{requiresEmail == 1 && (
<AddEmailModal
username={username ?? ''}
password={password ?? ''}
onSave={revalidate}
onClose={() => setRequiresEmail(0)}
></AddEmailModal>
)}
<Formik <Formik
initialValues={{ initialValues={{
username: '', username: '',
@@ -214,13 +202,9 @@ const JellyfinLogin: React.FC<JellyfinLoginProps> = ({
await axios.post('/api/v1/auth/jellyfin', { await axios.post('/api/v1/auth/jellyfin', {
username: values.username, username: values.username,
password: values.password, password: values.password,
email: values.username,
}); });
} catch (e) { } catch (e) {
if (e.message === 'Request failed with status code 406') {
setUsername(values.username);
setPassword(values.password);
setRequiresEmail(1);
} else {
toasts.addToast( toasts.addToast(
intl.formatMessage( intl.formatMessage(
e.message == 'Request failed with status code 401' e.message == 'Request failed with status code 401'
@@ -232,7 +216,6 @@ const JellyfinLogin: React.FC<JellyfinLoginProps> = ({
appearance: 'error', appearance: 'error',
} }
); );
}
} finally { } finally {
revalidate(); revalidate();
} }

View File

@@ -10,6 +10,7 @@ import Button from '../Common/Button';
import SensitiveInput from '../Common/SensitiveInput'; import SensitiveInput from '../Common/SensitiveInput';
const messages = defineMessages({ const messages = defineMessages({
username: 'Username',
email: 'Email Address', email: 'Email Address',
password: 'Password', password: 'Password',
validationemailrequired: 'You must provide a valid email address', validationemailrequired: 'You must provide a valid email address',
@@ -30,9 +31,9 @@ const LocalLogin: React.FC<LocalLoginProps> = ({ revalidate }) => {
const [loginError, setLoginError] = useState<string | null>(null); const [loginError, setLoginError] = useState<string | null>(null);
const LoginSchema = Yup.object().shape({ const LoginSchema = Yup.object().shape({
email: Yup.string() email: Yup.string().required(
.email() intl.formatMessage(messages.validationemailrequired)
.required(intl.formatMessage(messages.validationemailrequired)), ),
password: Yup.string().required( password: Yup.string().required(
intl.formatMessage(messages.validationpasswordrequired) intl.formatMessage(messages.validationpasswordrequired)
), ),
@@ -68,7 +69,9 @@ const LocalLogin: React.FC<LocalLoginProps> = ({ revalidate }) => {
<Form> <Form>
<div> <div>
<label htmlFor="email" className="text-label"> <label htmlFor="email" className="text-label">
{intl.formatMessage(messages.email)} {intl.formatMessage(messages.email) +
' / ' +
intl.formatMessage(messages.username)}
</label> </label>
<div className="mt-1 mb-2 sm:col-span-2 sm:mt-0"> <div className="mt-1 mb-2 sm:col-span-2 sm:mt-0">
<div className="form-input-field"> <div className="form-input-field">