Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion apps/files_sharing/src/views/SharingDetailsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,16 @@
<NcDateTimePickerNative
v-if="hasExpirationDate"
id="share-date-picker"
ref="expireDate"
:model-value="new Date(share.expireDate ?? dateTomorrow)"
:min="dateTomorrow"
:max="maxExpirationDateEnforced"
hide-label
:label="t('files_sharing', 'Expiration date')"
:placeholder="t('files_sharing', 'Expiration date')"
type="date"
@input="onExpirationChange" />
@update:model-value="onExpirationChange"
@change="checkExpirationDateValidity" />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not this this is needed, it should be enough to check this in saveShare no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@susnux That makes sense. But here is comment for the issue.
error message is displayed only after clicking update - should be displayed right away

That's why I check the validation on every input.

<NcCheckboxRadioSwitch
v-if="isPublicShare"
v-model="share.hideDownload"
Expand Down Expand Up @@ -878,6 +880,32 @@ export default {
},

methods: {
/**
* Check native `min` / `max` constraints on the expiration date field.
* Prefer the change event target when available (same pattern as SharingEntryLink).
*
* @param {Event} [event]
* @return {boolean}
*/
checkExpirationDateValidity(event) {
const fromEvent = event?.target
const fromRef = this.$refs.expireDate?.$el?.querySelector?.('input')
const input = fromEvent instanceof HTMLInputElement
? fromEvent
: (fromRef instanceof HTMLInputElement ? fromRef : null)

if (!input) {
return true
}

input.setCustomValidity('')
const isValid = input.checkValidity()
if (!isValid) {
input.reportValidity()
}
return isValid
},

/**
* Set a share attribute on the current share
*
Expand Down Expand Up @@ -1101,6 +1129,8 @@ export default {

if (!this.hasExpirationDate) {
this.share.expireDate = ''
} else if (!this.checkExpirationDateValidity()) {
return
}

if (this.isNewShare) {
Expand Down Expand Up @@ -1449,4 +1479,9 @@ export default {
}
}
}

:deep(input:user-invalid) {
--input-border-color: var(--color-border-error, var(--color-error)) !important;
border-color: var(--color-border-error, var(--color-error)) !important;
}
</style>
22 changes: 21 additions & 1 deletion apps/settings/src/components/Users/UserFormFields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
autocomplete="off"
spellcheck="false"
pattern="[a-zA-Z0-9 _\.@\-']+"
:required="fieldConfig.username?.required" />
:required="fieldConfig.username?.required"
@input="updateUsernameValidity"
@blur="updateUsernameValidity" />

<NcTextField
v-model="formData.displayName"
Expand Down Expand Up @@ -138,6 +140,24 @@ const password = ref<{ focus?: () => void } | null>(null)
const minPasswordLength = computed(() => store.getters.getPasswordPolicyMinLength)
/**
* Customize the browser-native constraint validation message.
*
* @param event Input/blur event from the underlying input element
*/
function updateUsernameValidity(event: Event) {
const input = event.target as HTMLInputElement | null
if (!input) {
return
}
// Clear first so native constraint flags are evaluated without a stale customError.
input.setCustomValidity('')
if (input.validity.patternMismatch) {
input.setCustomValidity(t('settings', 'Only letters, numbers, spaces, and _.@-\' are allowed'))
}
}
// Errors not bound to a dedicated input, shown in the catch-all live region.
const unhandledErrors = computed(() => {
const handled = new Set(['displayName', 'password', 'email'])
Expand Down
6 changes: 5 additions & 1 deletion core/src/components/login/LoginForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
:spellchecking="false"
:autocomplete="autoCompleteAllowed ? 'username' : 'off'"
required
:error="userNameInputLengthIs255"
:error="userNameError"
:helper-text="userInputHelperText"
data-login-form-input-user
@change="updateUsername" />
Expand Down Expand Up @@ -241,6 +241,10 @@ export default {
|| this.throttleDelay > 5000
},

userNameError() {
return this.isError || this.userNameInputLengthIs255
},

errorLabel() {
if (this.invalidPassword) {
return t('core', 'Wrong login or password.')
Expand Down
12 changes: 12 additions & 0 deletions core/src/tests/components/Login/LoginForm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ describe('core: LoginForm', () => {
expect(input.value).toBe('test-user')
})

it('marks username field as error when login credentials are invalid', () => {
const page = render(LoginForm, {
props: {
errors: ['invalidpassword'],
username: 'wrong-user',
},
})

const input = page.getByRole('textbox', { name: /Account name or email/ })
expect(input.closest('.input-field--error')).not.toBeNull()
})

describe('', () => {
beforeAll(() => {
vi.useFakeTimers()
Expand Down
13 changes: 8 additions & 5 deletions tests/playwright/e2e/login/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,26 @@ test.describe('Login', () => {
await expect(page).toHaveURL(/apps\/dashboard(\/|$)/)
})

test('wrong password shows error and marks password field invalid', async ({ page, user }) => {
test('wrong password shows error and marks both fields invalid', async ({ page, user }) => {
const loginPage = new LoginPage(page)
await loginPage.goto()
await loginPage.login(user.userId, `${user.password}--wrong`)

await expect(page).toHaveURL(/\/login/)
await expect(page.getByText(/Wrong login or password/i)).toBeVisible()
await expect(loginPage.passwordInput().and(page.locator(':invalid'))).toHaveCount(1)
await expect(page.locator('.input-field--error').filter({ has: loginPage.usernameInput() })).toBeVisible()
await expect(page.locator('.input-field--error').filter({ has: loginPage.passwordInput() })).toBeVisible()
})

test('wrong account name shows error and marks password field invalid', async ({ page, user }) => {
test('wrong account name shows error and marks both fields invalid', async ({ page, user }) => {
const loginPage = new LoginPage(page)
await loginPage.goto()
await loginPage.login(`${user.userId}--wrong`, user.password)

await expect(page).toHaveURL(/\/login/)
await expect(page.getByText(/Wrong login or password/i)).toBeVisible()
await expect(loginPage.passwordInput().and(page.locator(':invalid'))).toHaveCount(1)
await expect(page.locator('.input-field--error').filter({ has: loginPage.usernameInput() })).toBeVisible()
await expect(page.locator('.input-field--error').filter({ has: loginPage.passwordInput() })).toBeVisible()
})

test('disabled account shows disabled error', async ({ page, disabledUser }) => {
Expand All @@ -72,7 +74,8 @@ test.describe('Login', () => {

await expect(page).toHaveURL(/\/login/)
await expect(page.getByText(/Account.*disabled/i)).toBeVisible()
await expect(loginPage.passwordInput().and(page.locator(':invalid'))).toHaveCount(1)
await expect(page.locator('.input-field--error').filter({ has: loginPage.usernameInput() })).toBeVisible()
await expect(page.locator('.input-field--error').filter({ has: loginPage.passwordInput() })).toBeVisible()
})

test('logout redirects to the login page', async ({ page, context, user }) => {
Expand Down
Loading