1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Merge pull request #5904 from GabrielGavrilov/master

Add empty password save error message
This commit is contained in:
Bill Thornton 2024-08-21 13:01:42 -04:00 committed by GitHub
commit 302ea0b6b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 6 deletions

View file

@ -1,4 +1,5 @@
import React, { FunctionComponent, useCallback, useEffect, useRef } from 'react'; import React, { FunctionComponent, useCallback, useEffect, useRef } from 'react';
import type { UserDto } from '@jellyfin/sdk/lib/generated-client';
import Dashboard from '../../../utils/dashboard'; import Dashboard from '../../../utils/dashboard';
import globalize from '../../../lib/globalize'; import globalize from '../../../lib/globalize';
import LibraryMenu from '../../../scripts/libraryMenu'; import LibraryMenu from '../../../scripts/libraryMenu';
@ -14,6 +15,7 @@ type IProps = {
const UserPasswordForm: FunctionComponent<IProps> = ({ userId }: IProps) => { const UserPasswordForm: FunctionComponent<IProps> = ({ userId }: IProps) => {
const element = useRef<HTMLDivElement>(null); const element = useRef<HTMLDivElement>(null);
const user = useRef<UserDto>();
const loadUser = useCallback(async () => { const loadUser = useCallback(async () => {
const page = element.current; const page = element.current;
@ -28,17 +30,17 @@ const UserPasswordForm: FunctionComponent<IProps> = ({ userId }: IProps) => {
return; return;
} }
const user = await window.ApiClient.getUser(userId); user.current = await window.ApiClient.getUser(userId);
const loggedInUser = await Dashboard.getCurrentUser(); const loggedInUser = await Dashboard.getCurrentUser();
if (!user.Policy || !user.Configuration) { if (!user.current.Policy || !user.current.Configuration) {
throw new Error('Unexpected null user policy or configuration'); throw new Error('Unexpected null user policy or configuration');
} }
LibraryMenu.setTitle(user.Name); LibraryMenu.setTitle(user.current.Name);
if (user.HasConfiguredPassword) { if (user.current.HasConfiguredPassword) {
if (!user.Policy?.IsAdministrator) { if (!user.current.Policy?.IsAdministrator) {
(page.querySelector('#btnResetPassword') as HTMLDivElement).classList.remove('hide'); (page.querySelector('#btnResetPassword') as HTMLDivElement).classList.remove('hide');
} }
(page.querySelector('#fldCurrentPassword') as HTMLDivElement).classList.remove('hide'); (page.querySelector('#fldCurrentPassword') as HTMLDivElement).classList.remove('hide');
@ -47,7 +49,7 @@ const UserPasswordForm: FunctionComponent<IProps> = ({ userId }: IProps) => {
(page.querySelector('#fldCurrentPassword') as HTMLDivElement).classList.add('hide'); (page.querySelector('#fldCurrentPassword') as HTMLDivElement).classList.add('hide');
} }
const canChangePassword = loggedInUser?.Policy?.IsAdministrator || user.Policy.EnableUserPreferenceAccess; const canChangePassword = loggedInUser?.Policy?.IsAdministrator || user.current.Policy.EnableUserPreferenceAccess;
(page.querySelector('.passwordSection') as HTMLDivElement).classList.toggle('hide', !canChangePassword); (page.querySelector('.passwordSection') as HTMLDivElement).classList.toggle('hide', !canChangePassword);
import('../../autoFocuser').then(({ default: autoFocuser }) => { import('../../autoFocuser').then(({ default: autoFocuser }) => {
@ -76,6 +78,8 @@ const UserPasswordForm: FunctionComponent<IProps> = ({ userId }: IProps) => {
const onSubmit = (e: Event) => { const onSubmit = (e: Event) => {
if ((page.querySelector('#txtNewPassword') as HTMLInputElement).value != (page.querySelector('#txtNewPasswordConfirm') as HTMLInputElement).value) { if ((page.querySelector('#txtNewPassword') as HTMLInputElement).value != (page.querySelector('#txtNewPasswordConfirm') as HTMLInputElement).value) {
toast(globalize.translate('PasswordMatchError')); toast(globalize.translate('PasswordMatchError'));
} else if ((page.querySelector('#txtNewPassword') as HTMLInputElement).value == '' && user.current?.Policy?.IsAdministrator) {
toast(globalize.translate('PasswordMissingSaveError'));
} else { } else {
loading.show(); loading.show();
savePassword(); savePassword();

View file

@ -1255,6 +1255,7 @@
"PasswordResetComplete": "The password has been reset.", "PasswordResetComplete": "The password has been reset.",
"PasswordResetConfirmation": "Are you sure you wish to reset the password?", "PasswordResetConfirmation": "Are you sure you wish to reset the password?",
"PasswordResetProviderHelp": "Pick a password reset provider to be used when this user requests a password reset.", "PasswordResetProviderHelp": "Pick a password reset provider to be used when this user requests a password reset.",
"PasswordMissingSaveError": "New password cannot be empty.",
"PasswordSaved": "Password saved.", "PasswordSaved": "Password saved.",
"PathNotFound": "The path could not be found. Please ensure the path is valid and try again.", "PathNotFound": "The path could not be found. Please ensure the path is valid and try again.",
"Penciller": "Penciler", "Penciller": "Penciler",