-
Notifications
You must be signed in to change notification settings - Fork 5
[stable6] feat: add guest auth prompt component #1759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| <!-- | ||
| - SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
| - SPDX-License-Identifier: AGPL-3.0-or-later | ||
| --> | ||
|
|
||
| <template> | ||
| <NcDialog :buttons="dialogButtons" | ||
| class="public-auth-prompt" | ||
| data-cy-public-auth-prompt-dialog | ||
| is-form | ||
| no-close | ||
| :name="title" | ||
| @submit="onSubmit"> | ||
| <p v-if="text" class="public-auth-prompt__text"> | ||
| {{ text }} | ||
| </p> | ||
|
|
||
| <!-- Header --> | ||
| <NcNoteCard class="public-auth-prompt__header" | ||
| :text="notice" | ||
| type="info" /> | ||
|
|
||
| <!-- Form --> | ||
| <NcTextField ref="input" | ||
| class="public-auth-prompt__input" | ||
| data-cy-public-auth-prompt-dialog-name | ||
| :label="t('Name')" | ||
| :placeholder="t('Enter your name')" | ||
| :required="!cancellable" | ||
| v-model="name" | ||
| minlength="2" | ||
| name="name" /> | ||
| </NcDialog> | ||
| </template> | ||
|
|
||
| <script lang="ts"> | ||
| import { defineComponent } from 'vue' | ||
| import { getBuilder } from '@nextcloud/browser-storage' | ||
| import { setGuestNickname } from '@nextcloud/auth' | ||
| import { showError } from '@nextcloud/dialogs' | ||
|
|
||
| import NcButton from '@nextcloud/vue/components/NcButton' | ||
| import NcDialog from '@nextcloud/vue/components/NcDialog' | ||
| import NcNoteCard from '@nextcloud/vue/components/NcNoteCard' | ||
| import NcTextField from '@nextcloud/vue/components/NcTextField' | ||
|
|
||
| import { t } from '../utils/l10n.ts' | ||
|
|
||
| const storage = getBuilder('public').build() | ||
|
|
||
| export default defineComponent({ | ||
| name: 'PublicAuthPrompt', | ||
|
|
||
| components: { | ||
| NcDialog, | ||
| NcNoteCard, | ||
| NcTextField, | ||
| }, | ||
|
|
||
| props: { | ||
| /** | ||
| * Preselected nickname | ||
| * @default '' No name preselected by default | ||
| */ | ||
| nickname: { | ||
| type: String, | ||
| default: '', | ||
| }, | ||
|
|
||
| /** | ||
| * Dialog title | ||
| */ | ||
| title: { | ||
| type: String, | ||
| default: t('Guest identification'), | ||
| }, | ||
|
|
||
| /** | ||
| * Dialog text under the dialog title | ||
| * e.g 'Enter your name to access the file' | ||
| * @default '' Not shown by default | ||
| */ | ||
| text: { | ||
| type: String, | ||
| default: '', | ||
| }, | ||
|
|
||
| /** | ||
| * Dialog notice | ||
| * @default 'You are currently not identified.' | ||
| */ | ||
| notice: { | ||
| type: String, | ||
| default: t('You are currently not identified.'), | ||
| }, | ||
|
|
||
| /** | ||
| * Dialog submit button label | ||
| * @default 'Submit name' | ||
| */ | ||
| submitLabel: { | ||
| type: String, | ||
| default: t('Submit name'), | ||
| }, | ||
skjnldsv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Whether the dialog is cancellable | ||
| * @default false | ||
| */ | ||
| cancellable: { | ||
| type: Boolean, | ||
| default: false, | ||
| }, | ||
| }, | ||
|
|
||
| setup() { | ||
| return { | ||
| t, | ||
| } | ||
| }, | ||
|
|
||
| emits: ['close'], | ||
|
|
||
| data() { | ||
| return { | ||
| name: '', | ||
| } | ||
| }, | ||
|
|
||
| computed: { | ||
| dialogButtons() { | ||
| const cancelButton = { | ||
| label: t('Cancel'), | ||
| variant: 'tertiary', | ||
| callback: () => this.$emit('close'), | ||
| } | ||
|
|
||
| const submitButton = { | ||
| label: this.submitLabel, | ||
| type: 'submit', | ||
| variant: 'primary', | ||
| } | ||
|
|
||
| // If the dialog is cancellable, add a cancel button | ||
| if (this.cancellable) { | ||
| return [cancelButton, submitButton] | ||
| } | ||
|
|
||
| return [submitButton] | ||
| }, | ||
| }, | ||
|
|
||
| watch: { | ||
| /** Reset name to pre-selected nickname (e.g. Talk / Collabora ) */ | ||
| nickname: { | ||
| handler() { | ||
| this.name = this.nickname | ||
| }, | ||
| immediate: true, | ||
| }, | ||
| }, | ||
|
|
||
| methods: { | ||
| onSubmit() { | ||
| const input = this.$refs.input as HTMLInputElement | ||
| const nickname = this.name.trim() | ||
|
|
||
| if (nickname === '') { | ||
| // Show error if the nickname is empty | ||
| input.setCustomValidity(t('You cannot leave the name empty.')) | ||
| input.reportValidity() | ||
| input.focus() | ||
| return | ||
| } | ||
|
|
||
| if (nickname.length < 2) { | ||
| // Show error if the nickname is too short | ||
| input.setCustomValidity(t('Please enter a name with at least 2 characters.')) | ||
| input.reportValidity() | ||
| input.focus() | ||
| return | ||
| } | ||
|
|
||
| try { | ||
| // Set the nickname | ||
| setGuestNickname(nickname) | ||
| } catch (e) { | ||
| showError(t('Failed to set nickname.')) | ||
| console.error('Failed to set nickname', e) | ||
| input.focus() | ||
| return | ||
| } | ||
|
|
||
| // Set the dialog as shown | ||
| storage.setItem('public-auth-prompt-shown', 'true') | ||
|
|
||
| // Close the dialog | ||
| this.$emit('close', this.name) | ||
| }, | ||
| }, | ||
| }) | ||
| </script> | ||
| <style scoped lang="scss"> | ||
| .public-auth-prompt { | ||
| &__text { | ||
| // Smaller than dialog title | ||
| font-size: 1.25em; | ||
| margin-block: 0 calc(3 * var(--default-grid-baseline)); | ||
| } | ||
|
|
||
| &__header { | ||
| margin-block: 0 calc(3 * var(--default-grid-baseline)); | ||
| // No extra top margin for the first child | ||
| &:first-child { | ||
| margin-top: 0; | ||
| } | ||
| } | ||
|
|
||
| &__input { | ||
| margin-block: calc(4 * var(--default-grid-baseline)) calc(2 * var(--default-grid-baseline)); | ||
| } | ||
| } | ||
| </style> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| import type { ComponentProps } from 'vue-component-type-helpers' | ||
| import { defineAsyncComponent } from 'vue' | ||
| import { spawnDialog } from '@nextcloud/vue/functions/dialog' | ||
|
|
||
| import type PublicAuthPrompt from './components/PublicAuthPrompt.vue' | ||
|
|
||
| type PublicAuthPromptProps = ComponentProps<typeof PublicAuthPrompt> | ||
skjnldsv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Show the public auth prompt dialog | ||
| * This is used to ask the current user their nickname | ||
| * as well as show some additional contextual information | ||
| * @param props The props to pass to the dialog, see PublicAuthPrompt.vue for details | ||
| */ | ||
| export function showGuestUserPrompt(props: PublicAuthPromptProps) { | ||
| return new Promise((resolve) => { | ||
| spawnDialog( | ||
| defineAsyncComponent(() => import('./components/PublicAuthPrompt.vue')), | ||
| props, | ||
| resolve, | ||
| ) | ||
| }) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.