katecms 0.0.0-stage → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/module.d.mts +93 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +579 -0
- package/dist/runtime/assets/img/katecms-logo.svg +17 -0
- package/dist/runtime/composables/getCollection.d.ts +62 -0
- package/dist/runtime/composables/getCollection.js +167 -0
- package/dist/runtime/composables/getOptions.d.ts +22 -0
- package/dist/runtime/composables/getOptions.js +22 -0
- package/dist/runtime/composables/getQueryCollection.d.ts +95 -0
- package/dist/runtime/composables/getQueryCollection.js +199 -0
- package/dist/runtime/composables/getTerms.d.ts +79 -0
- package/dist/runtime/composables/getTerms.js +148 -0
- package/dist/runtime/composables/useAuth.d.ts +14 -0
- package/dist/runtime/composables/useAuth.js +33 -0
- package/dist/runtime/composables/useAuthCooldown.d.ts +6 -0
- package/dist/runtime/composables/useAuthCooldown.js +44 -0
- package/dist/runtime/composables/useCmsPaths.d.ts +15 -0
- package/dist/runtime/composables/useCmsPaths.js +21 -0
- package/dist/runtime/composables/useKateCmsExtensions.d.ts +49 -0
- package/dist/runtime/composables/useKateCmsExtensions.js +29 -0
- package/dist/runtime/composables/useMediaLibrary.d.ts +84 -0
- package/dist/runtime/composables/useMediaLibrary.js +140 -0
- package/dist/runtime/composables/useMenuAccess.d.ts +8 -0
- package/dist/runtime/composables/useMenuAccess.js +16 -0
- package/dist/runtime/internal/admin/AdminHeader.d.vue.ts +24 -0
- package/dist/runtime/internal/admin/AdminHeader.vue +91 -0
- package/dist/runtime/internal/admin/AdminHeader.vue.d.ts +24 -0
- package/dist/runtime/internal/admin/AppMenu.d.vue.ts +3 -0
- package/dist/runtime/internal/admin/AppMenu.vue +244 -0
- package/dist/runtime/internal/admin/AppMenu.vue.d.ts +3 -0
- package/dist/runtime/internal/admin/AppUser.d.vue.ts +3 -0
- package/dist/runtime/internal/admin/AppUser.vue +227 -0
- package/dist/runtime/internal/admin/AppUser.vue.d.ts +3 -0
- package/dist/runtime/internal/admin/CollectionEntryForm.d.vue.ts +41 -0
- package/dist/runtime/internal/admin/CollectionEntryForm.vue +916 -0
- package/dist/runtime/internal/admin/CollectionEntryForm.vue.d.ts +41 -0
- package/dist/runtime/internal/admin/ConfirmDialog.d.vue.ts +28 -0
- package/dist/runtime/internal/admin/ConfirmDialog.vue +136 -0
- package/dist/runtime/internal/admin/ConfirmDialog.vue.d.ts +28 -0
- package/dist/runtime/internal/admin/DictionaryTermForm.d.vue.ts +33 -0
- package/dist/runtime/internal/admin/DictionaryTermForm.vue +328 -0
- package/dist/runtime/internal/admin/DictionaryTermForm.vue.d.ts +33 -0
- package/dist/runtime/internal/admin/EntryRevisions.d.vue.ts +15 -0
- package/dist/runtime/internal/admin/EntryRevisions.vue +125 -0
- package/dist/runtime/internal/admin/EntryRevisions.vue.d.ts +15 -0
- package/dist/runtime/internal/admin/MediaLibraryFilters.d.vue.ts +16 -0
- package/dist/runtime/internal/admin/MediaLibraryFilters.vue +153 -0
- package/dist/runtime/internal/admin/MediaLibraryFilters.vue.d.ts +16 -0
- package/dist/runtime/internal/admin/MediaLibraryModal.d.vue.ts +65 -0
- package/dist/runtime/internal/admin/MediaLibraryModal.vue +451 -0
- package/dist/runtime/internal/admin/MediaLibraryModal.vue.d.ts +65 -0
- package/dist/runtime/internal/admin/OptionPageForm.d.vue.ts +26 -0
- package/dist/runtime/internal/admin/OptionPageForm.vue +222 -0
- package/dist/runtime/internal/admin/OptionPageForm.vue.d.ts +26 -0
- package/dist/runtime/internal/admin/UserAvatarField.d.vue.ts +12 -0
- package/dist/runtime/internal/admin/UserAvatarField.vue +305 -0
- package/dist/runtime/internal/admin/UserAvatarField.vue.d.ts +12 -0
- package/dist/runtime/internal/fields/AccordionField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/AccordionField.vue +220 -0
- package/dist/runtime/internal/fields/AccordionField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/ButtonGroupField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/ButtonGroupField.vue +109 -0
- package/dist/runtime/internal/fields/ButtonGroupField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/CheckboxField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/CheckboxField.vue +190 -0
- package/dist/runtime/internal/fields/CheckboxField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/ColorPickerField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/ColorPickerField.vue +791 -0
- package/dist/runtime/internal/fields/ColorPickerField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/DatePickerField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/DatePickerField.vue +26 -0
- package/dist/runtime/internal/fields/DatePickerField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/DateTimePickerField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/DateTimePickerField.vue +26 -0
- package/dist/runtime/internal/fields/DateTimePickerField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/DictionaryField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/DictionaryField.vue +345 -0
- package/dist/runtime/internal/fields/DictionaryField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/EmailField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/EmailField.vue +21 -0
- package/dist/runtime/internal/fields/EmailField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/FileField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/FileField.vue +408 -0
- package/dist/runtime/internal/fields/FileField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/FlexibleContentField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/FlexibleContentField.vue +1114 -0
- package/dist/runtime/internal/fields/FlexibleContentField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/GalleryField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/GalleryField.vue +584 -0
- package/dist/runtime/internal/fields/GalleryField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/GroupField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/GroupField.vue +111 -0
- package/dist/runtime/internal/fields/GroupField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/ImageField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/ImageField.vue +638 -0
- package/dist/runtime/internal/fields/ImageField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/ImageSelectField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/ImageSelectField.vue +179 -0
- package/dist/runtime/internal/fields/ImageSelectField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/LinkField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/LinkField.vue +303 -0
- package/dist/runtime/internal/fields/LinkField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/NumberField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/NumberField.vue +25 -0
- package/dist/runtime/internal/fields/NumberField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/OembedField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/OembedField.vue +161 -0
- package/dist/runtime/internal/fields/OembedField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/OpenStreetMapField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/OpenStreetMapField.vue +1502 -0
- package/dist/runtime/internal/fields/OpenStreetMapField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/PageLinkField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/PageLinkField.vue +153 -0
- package/dist/runtime/internal/fields/PageLinkField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/PasswordField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/PasswordField.vue +108 -0
- package/dist/runtime/internal/fields/PasswordField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/PostObjectField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/PostObjectField.vue +151 -0
- package/dist/runtime/internal/fields/PostObjectField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/RadioField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/RadioField.vue +163 -0
- package/dist/runtime/internal/fields/RadioField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/RangeField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/RangeField.vue +48 -0
- package/dist/runtime/internal/fields/RangeField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/RelationshipField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/RelationshipField.vue +525 -0
- package/dist/runtime/internal/fields/RelationshipField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/RepeaterField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/RepeaterField.vue +856 -0
- package/dist/runtime/internal/fields/RepeaterField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/SelectField.d.vue.ts +21 -0
- package/dist/runtime/internal/fields/SelectField.vue +101 -0
- package/dist/runtime/internal/fields/SelectField.vue.d.ts +21 -0
- package/dist/runtime/internal/fields/SeparatorField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/SeparatorField.vue +63 -0
- package/dist/runtime/internal/fields/SeparatorField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/TabField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/TabField.vue +210 -0
- package/dist/runtime/internal/fields/TabField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/TextField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/TextField.vue +22 -0
- package/dist/runtime/internal/fields/TextField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/TextareaField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/TextareaField.vue +62 -0
- package/dist/runtime/internal/fields/TextareaField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/TimePickerField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/TimePickerField.vue +24 -0
- package/dist/runtime/internal/fields/TimePickerField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/TrueFalseField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/TrueFalseField.vue +151 -0
- package/dist/runtime/internal/fields/TrueFalseField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/UrlField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/UrlField.vue +21 -0
- package/dist/runtime/internal/fields/UrlField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/UserField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/UserField.vue +164 -0
- package/dist/runtime/internal/fields/UserField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/WysiwygField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/WysiwygField.vue +971 -0
- package/dist/runtime/internal/fields/WysiwygField.vue.d.ts +0 -0
- package/dist/runtime/internal/parts/DateTimeControl.d.vue.ts +90 -0
- package/dist/runtime/internal/parts/DateTimeControl.vue +568 -0
- package/dist/runtime/internal/parts/DateTimeControl.vue.d.ts +90 -0
- package/dist/runtime/internal/parts/FieldAddon.d.vue.ts +0 -0
- package/dist/runtime/internal/parts/FieldAddon.vue +43 -0
- package/dist/runtime/internal/parts/FieldAddon.vue.d.ts +0 -0
- package/dist/runtime/internal/parts/FieldInstructions.d.vue.ts +0 -0
- package/dist/runtime/internal/parts/FieldInstructions.vue +24 -0
- package/dist/runtime/internal/parts/FieldInstructions.vue.d.ts +0 -0
- package/dist/runtime/internal/parts/FieldLabel.d.vue.ts +0 -0
- package/dist/runtime/internal/parts/FieldLabel.vue +40 -0
- package/dist/runtime/internal/parts/FieldLabel.vue.d.ts +0 -0
- package/dist/runtime/internal/parts/FieldWrapper.d.vue.ts +0 -0
- package/dist/runtime/internal/parts/FieldWrapper.vue +47 -0
- package/dist/runtime/internal/parts/FieldWrapper.vue.d.ts +0 -0
- package/dist/runtime/internal/parts/ImageCropper.d.vue.ts +17 -0
- package/dist/runtime/internal/parts/ImageCropper.vue +363 -0
- package/dist/runtime/internal/parts/ImageCropper.vue.d.ts +17 -0
- package/dist/runtime/internal/parts/InputControl.d.vue.ts +0 -0
- package/dist/runtime/internal/parts/InputControl.vue +163 -0
- package/dist/runtime/internal/parts/InputControl.vue.d.ts +0 -0
- package/dist/runtime/internal/ui/UiButton.d.vue.ts +35 -0
- package/dist/runtime/internal/ui/UiButton.vue +204 -0
- package/dist/runtime/internal/ui/UiButton.vue.d.ts +35 -0
- package/dist/runtime/internal/ui/UiNotice.d.vue.ts +40 -0
- package/dist/runtime/internal/ui/UiNotice.vue +253 -0
- package/dist/runtime/internal/ui/UiNotice.vue.d.ts +40 -0
- package/dist/runtime/internal/ui/UiSelect.d.vue.ts +61 -0
- package/dist/runtime/internal/ui/UiSelect.vue +1212 -0
- package/dist/runtime/internal/ui/UiSelect.vue.d.ts +61 -0
- package/dist/runtime/middleware/auth-guard.d.ts +9 -0
- package/dist/runtime/middleware/auth-guard.js +37 -0
- package/dist/runtime/pages/admin/collections/[id].d.vue.ts +3 -0
- package/dist/runtime/pages/admin/collections/[id].vue +423 -0
- package/dist/runtime/pages/admin/collections/[id].vue.d.ts +3 -0
- package/dist/runtime/pages/admin/collections/create.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/collections/create.vue +179 -0
- package/dist/runtime/pages/admin/collections/create.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/collections/index.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/collections/index.vue +828 -0
- package/dist/runtime/pages/admin/collections/index.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/demo-fields.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/demo-fields.vue +1327 -0
- package/dist/runtime/pages/admin/demo-fields.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/dictionaries/[id].d.vue.ts +3 -0
- package/dist/runtime/pages/admin/dictionaries/[id].vue +213 -0
- package/dist/runtime/pages/admin/dictionaries/[id].vue.d.ts +3 -0
- package/dist/runtime/pages/admin/dictionaries/index.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/dictionaries/index.vue +387 -0
- package/dist/runtime/pages/admin/dictionaries/index.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/index.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/index.vue +138 -0
- package/dist/runtime/pages/admin/index.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/login.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/login.vue +373 -0
- package/dist/runtime/pages/admin/login.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/media.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/media.vue +1054 -0
- package/dist/runtime/pages/admin/media.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/options/[page].d.vue.ts +3 -0
- package/dist/runtime/pages/admin/options/[page].vue +151 -0
- package/dist/runtime/pages/admin/options/[page].vue.d.ts +3 -0
- package/dist/runtime/pages/admin/register.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/register.vue +391 -0
- package/dist/runtime/pages/admin/register.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/users/[id].d.vue.ts +3 -0
- package/dist/runtime/pages/admin/users/[id].vue +337 -0
- package/dist/runtime/pages/admin/users/[id].vue.d.ts +3 -0
- package/dist/runtime/pages/admin/users/create.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/users/create.vue +201 -0
- package/dist/runtime/pages/admin/users/create.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/users/index.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/users/index.vue +329 -0
- package/dist/runtime/pages/admin/users/index.vue.d.ts +3 -0
- package/dist/runtime/pages/index.d.vue.ts +3 -0
- package/dist/runtime/pages/index.vue +399 -0
- package/dist/runtime/pages/index.vue.d.ts +3 -0
- package/dist/runtime/server/api/_katecms/auth/login.post.d.ts +5 -0
- package/dist/runtime/server/api/_katecms/auth/login.post.js +44 -0
- package/dist/runtime/server/api/_katecms/auth/logout.post.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/auth/logout.post.js +6 -0
- package/dist/runtime/server/api/_katecms/auth/register.post.d.ts +19 -0
- package/dist/runtime/server/api/_katecms/auth/register.post.js +83 -0
- package/dist/runtime/server/api/_katecms/auth/state.get.d.ts +9 -0
- package/dist/runtime/server/api/_katecms/auth/state.get.js +12 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/[id].delete.d.ts +15 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/[id].delete.js +59 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/[id].get.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/[id].get.js +50 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/[id].patch.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/[id].patch.js +130 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/revisions/[revisionId].post.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/revisions/[revisionId].post.js +123 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/revisions.get.d.ts +6 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/revisions.get.js +31 -0
- package/dist/runtime/server/api/_katecms/collections/[collection].get.d.ts +8 -0
- package/dist/runtime/server/api/_katecms/collections/[collection].get.js +135 -0
- package/dist/runtime/server/api/_katecms/collections/[collection].post.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/collections/[collection].post.js +91 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].delete.d.ts +7 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].delete.js +31 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].get.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].get.js +45 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].patch.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].patch.js +83 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary].get.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary].get.js +38 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary].post.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary].post.js +64 -0
- package/dist/runtime/server/api/_katecms/media/[id]/regenerate.post.d.ts +8 -0
- package/dist/runtime/server/api/_katecms/media/[id]/regenerate.post.js +30 -0
- package/dist/runtime/server/api/_katecms/media/[id].delete.d.ts +7 -0
- package/dist/runtime/server/api/_katecms/media/[id].delete.js +22 -0
- package/dist/runtime/server/api/_katecms/media/[id].get.d.ts +9 -0
- package/dist/runtime/server/api/_katecms/media/[id].get.js +17 -0
- package/dist/runtime/server/api/_katecms/media/[id].patch.d.ts +6 -0
- package/dist/runtime/server/api/_katecms/media/[id].patch.js +48 -0
- package/dist/runtime/server/api/_katecms/media/index.get.d.ts +5 -0
- package/dist/runtime/server/api/_katecms/media/index.get.js +75 -0
- package/dist/runtime/server/api/_katecms/media/index.post.d.ts +9 -0
- package/dist/runtime/server/api/_katecms/media/index.post.js +84 -0
- package/dist/runtime/server/api/_katecms/media/regenerate.post.d.ts +7 -0
- package/dist/runtime/server/api/_katecms/media/regenerate.post.js +30 -0
- package/dist/runtime/server/api/_katecms/menu.get.d.ts +8 -0
- package/dist/runtime/server/api/_katecms/menu.get.js +14 -0
- package/dist/runtime/server/api/_katecms/oembed.get.d.ts +2 -0
- package/dist/runtime/server/api/_katecms/oembed.get.js +53 -0
- package/dist/runtime/server/api/_katecms/options/[page].get.d.ts +7 -0
- package/dist/runtime/server/api/_katecms/options/[page].get.js +28 -0
- package/dist/runtime/server/api/_katecms/options/[page].patch.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/options/[page].patch.js +36 -0
- package/dist/runtime/server/api/_katecms/query.get.d.ts +24 -0
- package/dist/runtime/server/api/_katecms/query.get.js +270 -0
- package/dist/runtime/server/api/_katecms/relation/entries.get.d.ts +17 -0
- package/dist/runtime/server/api/_katecms/relation/entries.get.js +74 -0
- package/dist/runtime/server/api/_katecms/relation/terms.get.d.ts +17 -0
- package/dist/runtime/server/api/_katecms/relation/terms.get.js +51 -0
- package/dist/runtime/server/api/_katecms/resolve.get.d.ts +17 -0
- package/dist/runtime/server/api/_katecms/resolve.get.js +116 -0
- package/dist/runtime/server/api/_katecms/terms.get.d.ts +20 -0
- package/dist/runtime/server/api/_katecms/terms.get.js +201 -0
- package/dist/runtime/server/api/_katecms/users/[id].delete.d.ts +11 -0
- package/dist/runtime/server/api/_katecms/users/[id].delete.js +45 -0
- package/dist/runtime/server/api/_katecms/users/[id].patch.d.ts +19 -0
- package/dist/runtime/server/api/_katecms/users/[id].patch.js +129 -0
- package/dist/runtime/server/api/_katecms/users.get.d.ts +10 -0
- package/dist/runtime/server/api/_katecms/users.get.js +34 -0
- package/dist/runtime/server/api/_katecms/users.post.d.ts +10 -0
- package/dist/runtime/server/api/_katecms/users.post.js +62 -0
- package/dist/runtime/server/api/uploads/[...key].get.d.ts +3 -0
- package/dist/runtime/server/api/uploads/[...key].get.js +28 -0
- package/dist/runtime/server/kit.d.ts +5 -0
- package/dist/runtime/server/kit.js +5 -0
- package/dist/runtime/server/middleware/admin-headers.d.ts +3 -0
- package/dist/runtime/server/middleware/admin-headers.js +12 -0
- package/dist/runtime/server/plugins/auto-migrate.d.ts +2 -0
- package/dist/runtime/server/plugins/auto-migrate.js +45 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/server/utils/auth-attempts.d.ts +22 -0
- package/dist/runtime/server/utils/auth-attempts.js +42 -0
- package/dist/runtime/server/utils/auth-rate-limit.d.ts +11 -0
- package/dist/runtime/server/utils/auth-rate-limit.js +36 -0
- package/dist/runtime/server/utils/client-address.d.ts +16 -0
- package/dist/runtime/server/utils/client-address.js +23 -0
- package/dist/runtime/server/utils/collections.d.ts +42 -0
- package/dist/runtime/server/utils/collections.js +300 -0
- package/dist/runtime/server/utils/db.d.ts +3 -0
- package/dist/runtime/server/utils/db.js +25 -0
- package/dist/runtime/server/utils/dictionaries.d.ts +53 -0
- package/dist/runtime/server/utils/dictionaries.js +301 -0
- package/dist/runtime/server/utils/media-list.d.ts +18 -0
- package/dist/runtime/server/utils/media-list.js +84 -0
- package/dist/runtime/server/utils/media.d.ts +12 -0
- package/dist/runtime/server/utils/media.js +77 -0
- package/dist/runtime/server/utils/oembed-fetch.d.ts +4 -0
- package/dist/runtime/server/utils/oembed-fetch.js +142 -0
- package/dist/runtime/server/utils/options.d.ts +17 -0
- package/dist/runtime/server/utils/options.js +66 -0
- package/dist/runtime/server/utils/permissions.d.ts +13 -0
- package/dist/runtime/server/utils/permissions.js +20 -0
- package/dist/runtime/server/utils/public-fields-query.d.ts +6 -0
- package/dist/runtime/server/utils/public-fields-query.js +8 -0
- package/dist/runtime/server/utils/public-term.d.ts +8 -0
- package/dist/runtime/server/utils/public-term.js +80 -0
- package/dist/runtime/server/utils/regenerate.d.ts +12 -0
- package/dist/runtime/server/utils/regenerate.js +40 -0
- package/dist/runtime/server/utils/relation.d.ts +18 -0
- package/dist/runtime/server/utils/relation.js +77 -0
- package/dist/runtime/server/utils/request-address.d.ts +6 -0
- package/dist/runtime/server/utils/request-address.js +10 -0
- package/dist/runtime/server/utils/revisions.d.ts +20 -0
- package/dist/runtime/server/utils/revisions.js +172 -0
- package/dist/runtime/server/utils/session.d.ts +18 -0
- package/dist/runtime/server/utils/session.js +71 -0
- package/dist/runtime/server/utils/upload-headers.d.ts +2 -0
- package/dist/runtime/server/utils/upload-headers.js +30 -0
- package/dist/runtime/server/utils/users.d.ts +13 -0
- package/dist/runtime/server/utils/users.js +47 -0
- package/dist/runtime/utils/admin-users.d.ts +20 -0
- package/dist/runtime/utils/admin-users.js +19 -0
- package/dist/runtime/utils/auth-error.d.ts +6 -0
- package/dist/runtime/utils/auth-error.js +11 -0
- package/dist/runtime/utils/cms-paths.d.ts +5 -0
- package/dist/runtime/utils/cms-paths.js +13 -0
- package/dist/runtime/utils/collections.d.ts +176 -0
- package/dist/runtime/utils/collections.js +30 -0
- package/dist/runtime/utils/dictionaries.d.ts +65 -0
- package/dist/runtime/utils/dictionaries.js +14 -0
- package/dist/runtime/utils/field-errors.d.ts +4 -0
- package/dist/runtime/utils/field-errors.js +9 -0
- package/dist/runtime/utils/field-values.d.ts +19 -0
- package/dist/runtime/utils/field-values.js +82 -0
- package/dist/runtime/utils/helpers.d.ts +4 -0
- package/dist/runtime/utils/helpers.js +20 -0
- package/dist/runtime/utils/media-library-query.d.ts +54 -0
- package/dist/runtime/utils/media-library-query.js +190 -0
- package/dist/runtime/utils/options.d.ts +19 -0
- package/dist/runtime/utils/options.js +3 -0
- package/dist/runtime/utils/preview.d.ts +22 -0
- package/dist/runtime/utils/preview.js +33 -0
- package/dist/runtime/utils/relation.d.ts +33 -0
- package/dist/runtime/utils/relation.js +23 -0
- package/dist/runtime/utils/slugify.d.ts +2 -0
- package/dist/runtime/utils/slugify.js +4 -0
- package/dist/types.d.mts +7 -0
- package/package.json +84 -3
- package/src/admin-components.ts +124 -0
- package/src/module.ts +592 -0
- package/src/runtime/assets/img/katecms-logo.svg +17 -0
- package/src/runtime/assets/styles/_functions.scss +70 -0
- package/src/runtime/assets/styles/_index.scss +3 -0
- package/src/runtime/assets/styles/_mixins.scss +256 -0
- package/src/runtime/assets/styles/_variables.scss +35 -0
- package/src/runtime/composables/getCollection.ts +253 -0
- package/src/runtime/composables/getOptions.ts +42 -0
- package/src/runtime/composables/getQueryCollection.ts +325 -0
- package/src/runtime/composables/getTerms.ts +231 -0
- package/src/runtime/composables/useAuth.ts +43 -0
- package/src/runtime/composables/useAuthCooldown.ts +52 -0
- package/src/runtime/composables/useCmsPaths.ts +24 -0
- package/src/runtime/composables/useKateCmsExtensions.ts +81 -0
- package/src/runtime/composables/useMediaLibrary.ts +168 -0
- package/src/runtime/composables/useMenuAccess.ts +25 -0
- package/src/runtime/internal/admin/AdminHeader.vue +106 -0
- package/src/runtime/internal/admin/AppMenu.vue +290 -0
- package/src/runtime/internal/admin/AppUser.vue +260 -0
- package/src/runtime/internal/admin/CollectionEntryForm.vue +1044 -0
- package/src/runtime/internal/admin/ConfirmDialog.vue +164 -0
- package/src/runtime/internal/admin/DictionaryTermForm.vue +400 -0
- package/src/runtime/internal/admin/EntryRevisions.vue +145 -0
- package/src/runtime/internal/admin/MediaLibraryFilters.vue +186 -0
- package/src/runtime/internal/admin/MediaLibraryModal.vue +526 -0
- package/src/runtime/internal/admin/OptionPageForm.vue +277 -0
- package/src/runtime/internal/admin/UserAvatarField.vue +337 -0
- package/src/runtime/internal/fields/AccordionField.vue +258 -0
- package/src/runtime/internal/fields/ButtonGroupField.vue +144 -0
- package/src/runtime/internal/fields/CheckboxField.vue +228 -0
- package/src/runtime/internal/fields/ColorPickerField.vue +926 -0
- package/src/runtime/internal/fields/DatePickerField.vue +33 -0
- package/src/runtime/internal/fields/DateTimePickerField.vue +33 -0
- package/src/runtime/internal/fields/DictionaryField.vue +403 -0
- package/src/runtime/internal/fields/EmailField.vue +28 -0
- package/src/runtime/internal/fields/FileField.vue +480 -0
- package/src/runtime/internal/fields/FlexibleContentField.vue +1296 -0
- package/src/runtime/internal/fields/GalleryField.vue +677 -0
- package/src/runtime/internal/fields/GroupField.vue +136 -0
- package/src/runtime/internal/fields/ImageField.vue +730 -0
- package/src/runtime/internal/fields/ImageSelectField.vue +213 -0
- package/src/runtime/internal/fields/LinkField.vue +338 -0
- package/src/runtime/internal/fields/NumberField.vue +32 -0
- package/src/runtime/internal/fields/OembedField.vue +187 -0
- package/src/runtime/internal/fields/OpenStreetMapField.vue +1716 -0
- package/src/runtime/internal/fields/PageLinkField.vue +186 -0
- package/src/runtime/internal/fields/PasswordField.vue +127 -0
- package/src/runtime/internal/fields/PostObjectField.vue +187 -0
- package/src/runtime/internal/fields/RadioField.vue +195 -0
- package/src/runtime/internal/fields/RangeField.vue +62 -0
- package/src/runtime/internal/fields/RelationshipField.vue +604 -0
- package/src/runtime/internal/fields/RepeaterField.vue +999 -0
- package/src/runtime/internal/fields/SelectField.vue +118 -0
- package/src/runtime/internal/fields/SeparatorField.vue +77 -0
- package/src/runtime/internal/fields/TabField.vue +249 -0
- package/src/runtime/internal/fields/TextField.vue +29 -0
- package/src/runtime/internal/fields/TextareaField.vue +61 -0
- package/src/runtime/internal/fields/TimePickerField.vue +31 -0
- package/src/runtime/internal/fields/TrueFalseField.vue +181 -0
- package/src/runtime/internal/fields/UrlField.vue +28 -0
- package/src/runtime/internal/fields/UserField.vue +203 -0
- package/src/runtime/internal/fields/WysiwygField.vue +1061 -0
- package/src/runtime/internal/parts/DateTimeControl.vue +657 -0
- package/src/runtime/internal/parts/FieldAddon.vue +60 -0
- package/src/runtime/internal/parts/FieldInstructions.vue +38 -0
- package/src/runtime/internal/parts/FieldLabel.vue +56 -0
- package/src/runtime/internal/parts/FieldWrapper.vue +63 -0
- package/src/runtime/internal/parts/ImageCropper.vue +415 -0
- package/src/runtime/internal/parts/InputControl.vue +189 -0
- package/src/runtime/internal/ui/UiButton.vue +274 -0
- package/src/runtime/internal/ui/UiNotice.vue +302 -0
- package/src/runtime/internal/ui/UiSelect.vue +1420 -0
- package/src/runtime/middleware/auth-guard.ts +52 -0
- package/src/runtime/pages/admin/collections/[id].vue +486 -0
- package/src/runtime/pages/admin/collections/create.vue +208 -0
- package/src/runtime/pages/admin/collections/index.vue +955 -0
- package/src/runtime/pages/admin/demo-fields.vue +1354 -0
- package/src/runtime/pages/admin/dictionaries/[id].vue +246 -0
- package/src/runtime/pages/admin/dictionaries/index.vue +438 -0
- package/src/runtime/pages/admin/index.vue +155 -0
- package/src/runtime/pages/admin/login.vue +159 -0
- package/src/runtime/pages/admin/media.vue +1176 -0
- package/src/runtime/pages/admin/options/[page].vue +174 -0
- package/src/runtime/pages/admin/register.vue +179 -0
- package/src/runtime/pages/admin/users/[id].vue +382 -0
- package/src/runtime/pages/admin/users/create.vue +232 -0
- package/src/runtime/pages/admin/users/index.vue +374 -0
- package/src/runtime/pages/index.vue +265 -0
- package/src/runtime/server/api/_katecms/auth/login.post.ts +62 -0
- package/src/runtime/server/api/_katecms/auth/logout.post.ts +7 -0
- package/src/runtime/server/api/_katecms/auth/register.post.ts +112 -0
- package/src/runtime/server/api/_katecms/auth/state.get.ts +19 -0
- package/src/runtime/server/api/_katecms/collections/[collection]/[id].delete.ts +77 -0
- package/src/runtime/server/api/_katecms/collections/[collection]/[id].get.ts +57 -0
- package/src/runtime/server/api/_katecms/collections/[collection]/[id].patch.ts +157 -0
- package/src/runtime/server/api/_katecms/collections/[collection]/revisions/[revisionId].post.ts +133 -0
- package/src/runtime/server/api/_katecms/collections/[collection]/revisions.get.ts +35 -0
- package/src/runtime/server/api/_katecms/collections/[collection].get.ts +177 -0
- package/src/runtime/server/api/_katecms/collections/[collection].post.ts +111 -0
- package/src/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].delete.ts +37 -0
- package/src/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].get.ts +51 -0
- package/src/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].patch.ts +101 -0
- package/src/runtime/server/api/_katecms/dictionaries/[dictionary].get.ts +43 -0
- package/src/runtime/server/api/_katecms/dictionaries/[dictionary].post.ts +78 -0
- package/src/runtime/server/api/_katecms/media/[id]/regenerate.post.ts +39 -0
- package/src/runtime/server/api/_katecms/media/[id].delete.ts +28 -0
- package/src/runtime/server/api/_katecms/media/[id].get.ts +25 -0
- package/src/runtime/server/api/_katecms/media/[id].patch.ts +60 -0
- package/src/runtime/server/api/_katecms/media/index.get.ts +96 -0
- package/src/runtime/server/api/_katecms/media/index.post.ts +104 -0
- package/src/runtime/server/api/_katecms/media/regenerate.post.ts +38 -0
- package/src/runtime/server/api/_katecms/menu.get.ts +19 -0
- package/src/runtime/server/api/_katecms/oembed.get.ts +62 -0
- package/src/runtime/server/api/_katecms/options/[page].get.ts +35 -0
- package/src/runtime/server/api/_katecms/options/[page].patch.ts +46 -0
- package/src/runtime/server/api/_katecms/query.get.ts +332 -0
- package/src/runtime/server/api/_katecms/relation/entries.get.ts +98 -0
- package/src/runtime/server/api/_katecms/relation/terms.get.ts +61 -0
- package/src/runtime/server/api/_katecms/resolve.get.ts +148 -0
- package/src/runtime/server/api/_katecms/terms.get.ts +258 -0
- package/src/runtime/server/api/_katecms/users/[id].delete.ts +57 -0
- package/src/runtime/server/api/_katecms/users/[id].patch.ts +177 -0
- package/src/runtime/server/api/_katecms/users.get.ts +48 -0
- package/src/runtime/server/api/_katecms/users.post.ts +85 -0
- package/src/runtime/server/api/uploads/[...key].get.ts +33 -0
- package/src/runtime/server/kit.ts +5 -0
- package/src/runtime/server/middleware/admin-headers.ts +14 -0
- package/src/runtime/server/plugins/auto-migrate.ts +53 -0
- package/src/runtime/server/tsconfig.json +3 -0
- package/src/runtime/server/utils/auth-attempts.ts +71 -0
- package/src/runtime/server/utils/auth-rate-limit.ts +48 -0
- package/src/runtime/server/utils/client-address.ts +41 -0
- package/src/runtime/server/utils/collections.ts +381 -0
- package/src/runtime/server/utils/db.ts +36 -0
- package/src/runtime/server/utils/dictionaries.ts +397 -0
- package/src/runtime/server/utils/media-list.ts +131 -0
- package/src/runtime/server/utils/media.ts +94 -0
- package/src/runtime/server/utils/oembed-fetch.ts +157 -0
- package/src/runtime/server/utils/options.ts +86 -0
- package/src/runtime/server/utils/permissions.ts +44 -0
- package/src/runtime/server/utils/public-fields-query.ts +14 -0
- package/src/runtime/server/utils/public-term.ts +98 -0
- package/src/runtime/server/utils/regenerate.ts +56 -0
- package/src/runtime/server/utils/relation.ts +96 -0
- package/src/runtime/server/utils/request-address.ts +16 -0
- package/src/runtime/server/utils/revisions.ts +256 -0
- package/src/runtime/server/utils/session.ts +112 -0
- package/src/runtime/server/utils/upload-headers.ts +35 -0
- package/src/runtime/server/utils/users.ts +67 -0
- package/src/runtime/utils/admin-users.ts +43 -0
- package/src/runtime/utils/auth-error.ts +22 -0
- package/src/runtime/utils/cms-paths.ts +17 -0
- package/src/runtime/utils/collections.ts +228 -0
- package/src/runtime/utils/dictionaries.ts +89 -0
- package/src/runtime/utils/field-errors.ts +12 -0
- package/src/runtime/utils/field-values.ts +101 -0
- package/src/runtime/utils/helpers.ts +33 -0
- package/src/runtime/utils/media-library-query.ts +263 -0
- package/src/runtime/utils/options.ts +25 -0
- package/src/runtime/utils/preview.ts +56 -0
- package/src/runtime/utils/relation.ts +60 -0
- package/src/runtime/utils/slugify.ts +10 -0
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onMounted, ref } from 'vue'
|
|
3
|
+
import { $fetch, useHead } from '#imports'
|
|
4
|
+
import { OWNER_ROLE } from '@katecms/core'
|
|
5
|
+
import { parseAuthError } from '../../../utils/auth-error'
|
|
6
|
+
import { avatarSrc, userInitials } from '../../../utils/admin-users'
|
|
7
|
+
import type { AdminUser, RoleOption, UsersResponse } from '../../../utils/admin-users'
|
|
8
|
+
import { useCmsPaths } from '../../../composables/useCmsPaths'
|
|
9
|
+
|
|
10
|
+
useHead({ title: 'Users' })
|
|
11
|
+
|
|
12
|
+
const rootClass = 'katecms-users'
|
|
13
|
+
const paths = useCmsPaths()
|
|
14
|
+
|
|
15
|
+
const users = ref<AdminUser[]>([])
|
|
16
|
+
const roles = ref<RoleOption[]>([])
|
|
17
|
+
const currentUserId = ref<number | null>(null)
|
|
18
|
+
const canCreate = ref(false)
|
|
19
|
+
const canUpdate = ref(false)
|
|
20
|
+
const canDelete = ref(false)
|
|
21
|
+
const deletingId = ref<number | null>(null)
|
|
22
|
+
|
|
23
|
+
const loading = ref(true)
|
|
24
|
+
const error = ref<string | null>(null)
|
|
25
|
+
|
|
26
|
+
function roleLabel(slug: string): string {
|
|
27
|
+
return roles.value.find(role => role.slug === slug)?.label ?? slug
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function statusLabel(status: AdminUser['status']): string {
|
|
31
|
+
return status === 'banned' ? 'Banned' : 'Active'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function formatDate(iso: string): string {
|
|
35
|
+
const date = new Date(iso)
|
|
36
|
+
if (Number.isNaN(date.getTime())) {
|
|
37
|
+
return iso
|
|
38
|
+
}
|
|
39
|
+
return date.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' })
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Whether the actor may open the editor for a given row. */
|
|
43
|
+
function canEditRow(user: AdminUser): boolean {
|
|
44
|
+
if (user.id === currentUserId.value) {
|
|
45
|
+
return true
|
|
46
|
+
}
|
|
47
|
+
return canUpdate.value && user.role !== OWNER_ROLE
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function canDeleteRow(user: AdminUser): boolean {
|
|
51
|
+
if (!canDelete.value || user.id === currentUserId.value) {
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
if (user.role !== OWNER_ROLE) {
|
|
55
|
+
return true
|
|
56
|
+
}
|
|
57
|
+
return users.value.some(entry => entry.id === currentUserId.value && entry.role === OWNER_ROLE)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function remove(user: AdminUser) {
|
|
61
|
+
if (!canDeleteRow(user) || deletingId.value != null) {
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
const label = user.name?.trim() || user.email
|
|
65
|
+
if (!window.confirm(`Delete “${label}” permanently? This cannot be undone.`)) {
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
deletingId.value = user.id
|
|
69
|
+
error.value = null
|
|
70
|
+
try {
|
|
71
|
+
await $fetch(`/api/_katecms/users/${user.id}`, { method: 'DELETE' })
|
|
72
|
+
users.value = users.value.filter(entry => entry.id !== user.id)
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
error.value = parseAuthError(err, 'Could not delete the user.').message
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
deletingId.value = null
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function load() {
|
|
83
|
+
loading.value = true
|
|
84
|
+
error.value = null
|
|
85
|
+
try {
|
|
86
|
+
const res = await $fetch<UsersResponse>('/api/_katecms/users')
|
|
87
|
+
users.value = res.users
|
|
88
|
+
roles.value = res.roles
|
|
89
|
+
currentUserId.value = res.currentUserId
|
|
90
|
+
canCreate.value = res.canCreate
|
|
91
|
+
canUpdate.value = res.canUpdate
|
|
92
|
+
canDelete.value = res.canDelete
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
error.value = parseAuthError(err, 'Could not load users.').message
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
loading.value = false
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
onMounted(load)
|
|
103
|
+
</script>
|
|
104
|
+
|
|
105
|
+
<template>
|
|
106
|
+
<div :class="rootClass">
|
|
107
|
+
<KateCmsAdminHeader title="Users">
|
|
108
|
+
<KateCmsUiButton
|
|
109
|
+
tag="a"
|
|
110
|
+
:disabled="!canCreate"
|
|
111
|
+
:link="{ url: `${paths.users}/create`, title: 'Add user' }"
|
|
112
|
+
>
|
|
113
|
+
Add user
|
|
114
|
+
</KateCmsUiButton>
|
|
115
|
+
</KateCmsAdminHeader>
|
|
116
|
+
|
|
117
|
+
<KateCmsUiNotice
|
|
118
|
+
v-if="loading"
|
|
119
|
+
placement="static"
|
|
120
|
+
variant="info"
|
|
121
|
+
message="Loading…"
|
|
122
|
+
:closable="false"
|
|
123
|
+
/>
|
|
124
|
+
<KateCmsUiNotice
|
|
125
|
+
v-else-if="error"
|
|
126
|
+
placement="static"
|
|
127
|
+
variant="danger"
|
|
128
|
+
:message="error"
|
|
129
|
+
@close="error = null"
|
|
130
|
+
/>
|
|
131
|
+
<KateCmsUiNotice
|
|
132
|
+
v-else-if="!users.length"
|
|
133
|
+
placement="static"
|
|
134
|
+
variant="info"
|
|
135
|
+
message="No users yet."
|
|
136
|
+
:closable="false"
|
|
137
|
+
/>
|
|
138
|
+
|
|
139
|
+
<div
|
|
140
|
+
v-else
|
|
141
|
+
:class="`${rootClass}__table-wrap`"
|
|
142
|
+
>
|
|
143
|
+
<div
|
|
144
|
+
:class="[`${rootClass}__columns`, `${rootClass}__columns--head`]"
|
|
145
|
+
role="row"
|
|
146
|
+
>
|
|
147
|
+
<span
|
|
148
|
+
role="columnheader"
|
|
149
|
+
aria-label="Avatar"
|
|
150
|
+
/>
|
|
151
|
+
<span role="columnheader">Email</span>
|
|
152
|
+
<span role="columnheader">Name</span>
|
|
153
|
+
<span role="columnheader">Role</span>
|
|
154
|
+
<span role="columnheader">Status</span>
|
|
155
|
+
<span role="columnheader">Created</span>
|
|
156
|
+
<span
|
|
157
|
+
role="columnheader"
|
|
158
|
+
aria-label="Actions"
|
|
159
|
+
/>
|
|
160
|
+
</div>
|
|
161
|
+
<div :class="`${rootClass}__rows`">
|
|
162
|
+
<div
|
|
163
|
+
v-for="user in users"
|
|
164
|
+
:key="user.id"
|
|
165
|
+
:class="[`${rootClass}__columns`, { [`${rootClass}__row--banned`]: user.status === 'banned' }]"
|
|
166
|
+
role="row"
|
|
167
|
+
>
|
|
168
|
+
<div role="cell">
|
|
169
|
+
<span :class="`${rootClass}__avatar`">
|
|
170
|
+
<img
|
|
171
|
+
v-if="avatarSrc(user.avatar)"
|
|
172
|
+
:src="avatarSrc(user.avatar)!"
|
|
173
|
+
:alt="user.avatar?.alt || ''"
|
|
174
|
+
>
|
|
175
|
+
<span
|
|
176
|
+
v-else
|
|
177
|
+
:class="`${rootClass}__avatar-initials`"
|
|
178
|
+
>{{ userInitials(user) }}</span>
|
|
179
|
+
</span>
|
|
180
|
+
</div>
|
|
181
|
+
<div role="cell">
|
|
182
|
+
{{ user.email }}
|
|
183
|
+
<span
|
|
184
|
+
v-if="user.id === currentUserId"
|
|
185
|
+
:class="`${rootClass}__badge`"
|
|
186
|
+
>you</span>
|
|
187
|
+
</div>
|
|
188
|
+
<div role="cell">
|
|
189
|
+
{{ user.name || '—' }}
|
|
190
|
+
</div>
|
|
191
|
+
<div role="cell">
|
|
192
|
+
{{ roleLabel(user.role) }}
|
|
193
|
+
</div>
|
|
194
|
+
<div role="cell">
|
|
195
|
+
<span
|
|
196
|
+
:class="[`${rootClass}__status`, `${rootClass}__status--${user.status}`]"
|
|
197
|
+
>
|
|
198
|
+
{{ statusLabel(user.status) }}
|
|
199
|
+
</span>
|
|
200
|
+
</div>
|
|
201
|
+
<div role="cell">
|
|
202
|
+
{{ formatDate(user.created_at) }}
|
|
203
|
+
</div>
|
|
204
|
+
<div
|
|
205
|
+
role="cell"
|
|
206
|
+
:class="`${rootClass}__actions`"
|
|
207
|
+
>
|
|
208
|
+
<KateCmsUiButton
|
|
209
|
+
v-if="canEditRow(user)"
|
|
210
|
+
tag="a"
|
|
211
|
+
:variant="['secondary', 'small']"
|
|
212
|
+
:link="{ url: `${paths.users}/${user.id}`, title: 'Edit' }"
|
|
213
|
+
>
|
|
214
|
+
Edit
|
|
215
|
+
</KateCmsUiButton>
|
|
216
|
+
<KateCmsUiButton
|
|
217
|
+
v-if="canDeleteRow(user)"
|
|
218
|
+
tag="button"
|
|
219
|
+
type="button"
|
|
220
|
+
:variant="['red', 'small']"
|
|
221
|
+
:disabled="deletingId === user.id"
|
|
222
|
+
:aria-label="`Delete ${user.name || user.email}`"
|
|
223
|
+
@click="remove(user)"
|
|
224
|
+
>
|
|
225
|
+
{{ deletingId === user.id ? 'Deleting…' : 'Delete' }}
|
|
226
|
+
</KateCmsUiButton>
|
|
227
|
+
</div>
|
|
228
|
+
</div>
|
|
229
|
+
</div>
|
|
230
|
+
</div>
|
|
231
|
+
</div>
|
|
232
|
+
</template>
|
|
233
|
+
|
|
234
|
+
<style scoped lang="scss">
|
|
235
|
+
@use "../../../assets/styles" as *;
|
|
236
|
+
|
|
237
|
+
$root: '.katecms-users';
|
|
238
|
+
|
|
239
|
+
@include katecms-wrapper {
|
|
240
|
+
#{$root} {
|
|
241
|
+
display: flex;
|
|
242
|
+
flex: 1;
|
|
243
|
+
flex-direction: column;
|
|
244
|
+
gap: math-rem(16);
|
|
245
|
+
min-height: 0;
|
|
246
|
+
padding: 0 math-rem(8) math-rem(8);
|
|
247
|
+
overflow: hidden;
|
|
248
|
+
|
|
249
|
+
&__table {
|
|
250
|
+
&-wrap {
|
|
251
|
+
display: flex;
|
|
252
|
+
flex: 1;
|
|
253
|
+
flex-direction: column;
|
|
254
|
+
min-height: 0;
|
|
255
|
+
overflow-x: auto;
|
|
256
|
+
overflow-y: hidden;
|
|
257
|
+
background: $color-surface;
|
|
258
|
+
border: 1px solid $color-border;
|
|
259
|
+
border-radius: $border-radius;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
&__columns {
|
|
264
|
+
display: grid;
|
|
265
|
+
grid-template-columns: math-rem(56) minmax(math-rem(180), 1.6fr) minmax(math-rem(120), 1.2fr) math-rem(140) math-rem(110) math-rem(180) minmax(math-rem(148), auto);
|
|
266
|
+
align-items: center;
|
|
267
|
+
min-width: math-rem(860);
|
|
268
|
+
|
|
269
|
+
> [role='columnheader'],
|
|
270
|
+
> [role='cell'] {
|
|
271
|
+
min-width: 0;
|
|
272
|
+
padding: math-rem(10) math-rem(14);
|
|
273
|
+
overflow-wrap: anywhere;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
&--head {
|
|
277
|
+
flex-shrink: 0;
|
|
278
|
+
background: $color-bg;
|
|
279
|
+
border-bottom: 1px solid $color-border;
|
|
280
|
+
|
|
281
|
+
> [role='columnheader'] {
|
|
282
|
+
font-size: math-rem(12);
|
|
283
|
+
font-weight: 600;
|
|
284
|
+
text-transform: uppercase;
|
|
285
|
+
letter-spacing: 0.03em;
|
|
286
|
+
color: $color-muted;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
&__rows {
|
|
292
|
+
flex: 1;
|
|
293
|
+
min-height: 0;
|
|
294
|
+
overflow-x: hidden;
|
|
295
|
+
overflow-y: auto;
|
|
296
|
+
|
|
297
|
+
#{$root}__columns {
|
|
298
|
+
border-bottom: 1px solid $color-border;
|
|
299
|
+
|
|
300
|
+
&:last-child {
|
|
301
|
+
border-bottom: none;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
&__avatar {
|
|
307
|
+
display: flex;
|
|
308
|
+
align-items: center;
|
|
309
|
+
justify-content: center;
|
|
310
|
+
width: math-rem(32);
|
|
311
|
+
height: math-rem(32);
|
|
312
|
+
border-radius: 50%;
|
|
313
|
+
overflow: hidden;
|
|
314
|
+
background: $color-accent-wash;
|
|
315
|
+
|
|
316
|
+
img {
|
|
317
|
+
display: block;
|
|
318
|
+
width: 100%;
|
|
319
|
+
height: 100%;
|
|
320
|
+
max-width: none;
|
|
321
|
+
object-fit: cover;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
&-initials {
|
|
325
|
+
font-size: math-rem(11);
|
|
326
|
+
font-weight: 700;
|
|
327
|
+
color: $color-accent;
|
|
328
|
+
line-height: 1;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
&__row {
|
|
333
|
+
&--banned {
|
|
334
|
+
opacity: 0.6;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
&__badge {
|
|
339
|
+
margin-left: math-rem(6);
|
|
340
|
+
padding: math-rem(1) math-rem(6);
|
|
341
|
+
border-radius: $border-radius-inter;
|
|
342
|
+
background: $color-accent-wash;
|
|
343
|
+
color: $color-accent;
|
|
344
|
+
font-size: math-rem(11);
|
|
345
|
+
font-weight: 600;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
&__status {
|
|
349
|
+
display: inline-block;
|
|
350
|
+
padding: math-rem(2) math-rem(8);
|
|
351
|
+
border-radius: $border-radius-inter;
|
|
352
|
+
font-size: math-rem(12);
|
|
353
|
+
font-weight: 600;
|
|
354
|
+
|
|
355
|
+
&--active {
|
|
356
|
+
background: $color-success-bg;
|
|
357
|
+
color: $color-success;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
&--banned {
|
|
361
|
+
background: $color-danger-bg;
|
|
362
|
+
color: $color-danger;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
&__actions {
|
|
367
|
+
display: flex;
|
|
368
|
+
justify-content: flex-end;
|
|
369
|
+
gap: math-rem(8);
|
|
370
|
+
white-space: nowrap;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
</style>
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import { useCookie, useHead, useRoute } from '#imports'
|
|
4
|
+
import { useCmsPaths } from '../composables/useCmsPaths'
|
|
5
|
+
|
|
6
|
+
type ThemeMode = 'system' | 'light' | 'dark'
|
|
7
|
+
|
|
8
|
+
const themeOrder: ThemeMode[] = ['system', 'light', 'dark']
|
|
9
|
+
|
|
10
|
+
const theme = useCookie<ThemeMode>('katecms-theme', {
|
|
11
|
+
default: () => 'system',
|
|
12
|
+
maxAge: 60 * 60 * 24 * 365,
|
|
13
|
+
sameSite: 'lax',
|
|
14
|
+
watch: true,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const themeMode = computed<ThemeMode>(() => themeOrder.includes(theme.value) ? theme.value : 'system')
|
|
18
|
+
|
|
19
|
+
const themeClass = computed(() => themeMode.value === 'system' ? '' : `katecms-theme-${themeMode.value}`)
|
|
20
|
+
|
|
21
|
+
const themeLabel = computed(() => {
|
|
22
|
+
if (themeMode.value === 'light') {
|
|
23
|
+
return 'Light theme. Switch to dark'
|
|
24
|
+
}
|
|
25
|
+
if (themeMode.value === 'dark') {
|
|
26
|
+
return 'Dark theme. Switch to system'
|
|
27
|
+
}
|
|
28
|
+
return 'System theme. Switch to light'
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
useHead(() => ({
|
|
32
|
+
bodyAttrs: {
|
|
33
|
+
id: 'katecms-body',
|
|
34
|
+
class: themeClass.value,
|
|
35
|
+
},
|
|
36
|
+
titleTemplate: (title?: string) => title ? `${title} - KateCMS` : 'KateCMS',
|
|
37
|
+
}))
|
|
38
|
+
|
|
39
|
+
function cycleTheme() {
|
|
40
|
+
const index = themeOrder.indexOf(themeMode.value)
|
|
41
|
+
theme.value = themeOrder[(index + 1) % themeOrder.length] ?? 'system'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const route = useRoute()
|
|
45
|
+
const paths = useCmsPaths()
|
|
46
|
+
const rootClass = 'katecms'
|
|
47
|
+
const isAuthPage = computed(() => {
|
|
48
|
+
const path = route.path.length > 1 ? route.path.replace(/\/+$/, '') : route.path
|
|
49
|
+
return path === paths.login || path === paths.register
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const sidebarHidden = useCookie<boolean>('katecms-sidebar-hidden', {
|
|
53
|
+
default: () => false,
|
|
54
|
+
maxAge: 60 * 60 * 24 * 365,
|
|
55
|
+
sameSite: 'lax',
|
|
56
|
+
watch: true,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
function toggleSidebar() {
|
|
60
|
+
sidebarHidden.value = !sidebarHidden.value
|
|
61
|
+
}
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<template>
|
|
65
|
+
<NuxtPage v-if="isAuthPage" />
|
|
66
|
+
<div
|
|
67
|
+
v-else
|
|
68
|
+
:class="[rootClass, { 'is-sidebar-hidden': sidebarHidden }]"
|
|
69
|
+
>
|
|
70
|
+
<div :class="[`${rootClass}-header`]">
|
|
71
|
+
<KateCmsUiButton
|
|
72
|
+
tag="button"
|
|
73
|
+
:class="`${rootClass}-sidebar-toggle`"
|
|
74
|
+
:variant="['tertiary', 'icon']"
|
|
75
|
+
:title="sidebarHidden ? 'Show sidebar' : 'Hide sidebar'"
|
|
76
|
+
:aria-label="sidebarHidden ? 'Show sidebar' : 'Hide sidebar'"
|
|
77
|
+
:aria-expanded="sidebarHidden ? 'false' : 'true'"
|
|
78
|
+
aria-controls="katecms-sidebar"
|
|
79
|
+
@click="toggleSidebar"
|
|
80
|
+
>
|
|
81
|
+
<svg
|
|
82
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
83
|
+
viewBox="0 0 24 24"
|
|
84
|
+
fill="none"
|
|
85
|
+
aria-hidden="true"
|
|
86
|
+
>
|
|
87
|
+
<path
|
|
88
|
+
d="M5 4.75h14c.69 0 1.25.56 1.25 1.25v12c0 .69-.56 1.25-1.25 1.25H5c-.69 0-1.25-.56-1.25-1.25V6c0-.69.56-1.25 1.25-1.25Z"
|
|
89
|
+
stroke="currentColor"
|
|
90
|
+
stroke-width="1.6"
|
|
91
|
+
/>
|
|
92
|
+
<path
|
|
93
|
+
d="M9 4.75v14.5"
|
|
94
|
+
stroke="currentColor"
|
|
95
|
+
stroke-width="1.6"
|
|
96
|
+
/>
|
|
97
|
+
</svg>
|
|
98
|
+
</KateCmsUiButton>
|
|
99
|
+
<KateCmsUiButton
|
|
100
|
+
tag="button"
|
|
101
|
+
:class="`${rootClass}-theme-toggle`"
|
|
102
|
+
:variant="['tertiary', 'icon']"
|
|
103
|
+
:title="themeLabel"
|
|
104
|
+
:aria-label="themeLabel"
|
|
105
|
+
@click="cycleTheme"
|
|
106
|
+
>
|
|
107
|
+
<svg
|
|
108
|
+
v-if="themeMode === 'system'"
|
|
109
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
110
|
+
viewBox="0 0 24 24"
|
|
111
|
+
fill="none"
|
|
112
|
+
aria-hidden="true"
|
|
113
|
+
>
|
|
114
|
+
<rect
|
|
115
|
+
x="3.75"
|
|
116
|
+
y="4.75"
|
|
117
|
+
width="16.5"
|
|
118
|
+
height="11.5"
|
|
119
|
+
rx="1.5"
|
|
120
|
+
stroke="currentColor"
|
|
121
|
+
stroke-width="1.6"
|
|
122
|
+
/>
|
|
123
|
+
<path
|
|
124
|
+
d="M8.5 19.75h7M12 16.25v3.5"
|
|
125
|
+
stroke="currentColor"
|
|
126
|
+
stroke-width="1.6"
|
|
127
|
+
stroke-linecap="round"
|
|
128
|
+
/>
|
|
129
|
+
</svg>
|
|
130
|
+
<svg
|
|
131
|
+
v-else-if="themeMode === 'light'"
|
|
132
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
133
|
+
viewBox="0 0 24 24"
|
|
134
|
+
fill="none"
|
|
135
|
+
aria-hidden="true"
|
|
136
|
+
>
|
|
137
|
+
<circle
|
|
138
|
+
cx="12"
|
|
139
|
+
cy="12"
|
|
140
|
+
r="4"
|
|
141
|
+
stroke="currentColor"
|
|
142
|
+
stroke-width="1.6"
|
|
143
|
+
/>
|
|
144
|
+
<path
|
|
145
|
+
d="M12 2.5v2.2M12 19.3v2.2M2.5 12h2.2M19.3 12h2.2M5.1 5.1l1.6 1.6M17.3 17.3l1.6 1.6M18.9 5.1l-1.6 1.6M6.7 17.3l-1.6 1.6"
|
|
146
|
+
stroke="currentColor"
|
|
147
|
+
stroke-width="1.6"
|
|
148
|
+
stroke-linecap="round"
|
|
149
|
+
/>
|
|
150
|
+
</svg>
|
|
151
|
+
<svg
|
|
152
|
+
v-else
|
|
153
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
154
|
+
viewBox="0 0 24 24"
|
|
155
|
+
fill="none"
|
|
156
|
+
aria-hidden="true"
|
|
157
|
+
>
|
|
158
|
+
<path
|
|
159
|
+
d="M16.2 14.8A6.2 6.2 0 0 1 9.4 4.6 6.4 6.4 0 1 0 16.2 14.8Z"
|
|
160
|
+
stroke="currentColor"
|
|
161
|
+
stroke-width="1.6"
|
|
162
|
+
stroke-linejoin="round"
|
|
163
|
+
/>
|
|
164
|
+
</svg>
|
|
165
|
+
</KateCmsUiButton>
|
|
166
|
+
<KateCmsAppUser />
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
<div
|
|
170
|
+
id="katecms-sidebar"
|
|
171
|
+
:class="[`${rootClass}-sidebar`]"
|
|
172
|
+
:inert="sidebarHidden || undefined"
|
|
173
|
+
:aria-hidden="sidebarHidden ? 'true' : undefined"
|
|
174
|
+
>
|
|
175
|
+
<div :class="[`${rootClass}-sidebar-wrap`]">
|
|
176
|
+
<KateCmsAppMenu />
|
|
177
|
+
</div>
|
|
178
|
+
</div>
|
|
179
|
+
|
|
180
|
+
<div :class="[`${rootClass}-main`]">
|
|
181
|
+
<NuxtPage />
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
</template>
|
|
185
|
+
|
|
186
|
+
<style lang="scss">
|
|
187
|
+
@use "../assets/styles" as *;
|
|
188
|
+
|
|
189
|
+
@include katecms-document;
|
|
190
|
+
</style>
|
|
191
|
+
|
|
192
|
+
<style scoped lang="scss">
|
|
193
|
+
@use "../assets/styles" as *;
|
|
194
|
+
|
|
195
|
+
$root: '.katecms';
|
|
196
|
+
|
|
197
|
+
@include katecms-wrapper {
|
|
198
|
+
#{$root} {
|
|
199
|
+
display: grid;
|
|
200
|
+
grid-template-columns: $sidebar-w minmax(0, 1fr);
|
|
201
|
+
grid-template-rows: auto 1fr;
|
|
202
|
+
gap: 0;
|
|
203
|
+
grid-template-areas:
|
|
204
|
+
"sidebar header"
|
|
205
|
+
"sidebar main";
|
|
206
|
+
width: 100%;
|
|
207
|
+
height: 100vh;
|
|
208
|
+
|
|
209
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
210
|
+
transition: grid-template-columns .3s ease;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
&.is-sidebar-hidden {
|
|
214
|
+
grid-template-columns: 0 minmax(0, 1fr);
|
|
215
|
+
|
|
216
|
+
#{$root}-sidebar {
|
|
217
|
+
border-right-width: 0;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
&-header {
|
|
222
|
+
grid-area: header;
|
|
223
|
+
display: flex;
|
|
224
|
+
align-items: center;
|
|
225
|
+
justify-content: flex-end;
|
|
226
|
+
gap: math-rem(12);
|
|
227
|
+
padding: 0 math-rem(12);
|
|
228
|
+
border-bottom: 1px solid $color-border;
|
|
229
|
+
box-shadow: $shadow-sm;
|
|
230
|
+
min-height: $topbar-h;
|
|
231
|
+
|
|
232
|
+
:deep(.katecms-btn.katecms-sidebar-toggle) {
|
|
233
|
+
margin-right: auto;
|
|
234
|
+
color: $color-ink;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
:deep(.katecms-btn.katecms-theme-toggle) {
|
|
238
|
+
color: $color-ink;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
&-sidebar {
|
|
243
|
+
grid-area: sidebar;
|
|
244
|
+
min-width: 0;
|
|
245
|
+
overflow: hidden;
|
|
246
|
+
border-right: 1px solid $color-border;
|
|
247
|
+
background-color: $color-bg;
|
|
248
|
+
|
|
249
|
+
&-wrap {
|
|
250
|
+
width: $sidebar-w;
|
|
251
|
+
min-height: 100%;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
&-main {
|
|
256
|
+
grid-area: main;
|
|
257
|
+
display: flex;
|
|
258
|
+
flex-direction: column;
|
|
259
|
+
min-width: 0;
|
|
260
|
+
min-height: 0;
|
|
261
|
+
overflow: hidden;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
</style>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createError, defineEventHandler, readBody } from 'h3'
|
|
2
|
+
import {
|
|
3
|
+
MAX_PASSWORD_LENGTH,
|
|
4
|
+
findUserByEmail,
|
|
5
|
+
toSafeUser,
|
|
6
|
+
verifyPassword,
|
|
7
|
+
} from '@katecms/core'
|
|
8
|
+
import type { SafeUser } from '@katecms/core'
|
|
9
|
+
import { getDb } from '../../../utils/db'
|
|
10
|
+
import { setUserSession } from '../../../utils/session'
|
|
11
|
+
import {
|
|
12
|
+
assertAuthAttemptAllowed,
|
|
13
|
+
getAuthAttemptKeys,
|
|
14
|
+
invalidCredentialsError,
|
|
15
|
+
recordAuthAttemptFailure,
|
|
16
|
+
recordAuthAttemptSuccess,
|
|
17
|
+
} from '../../../utils/auth-rate-limit'
|
|
18
|
+
|
|
19
|
+
interface LoginBody {
|
|
20
|
+
email?: unknown
|
|
21
|
+
password?: unknown
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default defineEventHandler(async (event): Promise<{ user: SafeUser }> => {
|
|
25
|
+
const body = await readBody<LoginBody>(event)
|
|
26
|
+
const email = typeof body?.email === 'string' ? body.email.trim() : ''
|
|
27
|
+
const password = typeof body?.password === 'string' ? body.password : ''
|
|
28
|
+
|
|
29
|
+
if (!email || !password) {
|
|
30
|
+
throw createError({ statusCode: 422, statusMessage: 'Unprocessable Entity', message: 'Enter email and password.' })
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const attemptKeys = getAuthAttemptKeys(event, 'login', email)
|
|
34
|
+
assertAuthAttemptAllowed(event, attemptKeys)
|
|
35
|
+
|
|
36
|
+
// Same generic error for "no such user", "banned" and "wrong password" so the
|
|
37
|
+
// endpoint doesn't reveal which emails are registered.
|
|
38
|
+
function fail(): never {
|
|
39
|
+
const { retryAfterMs } = recordAuthAttemptFailure(attemptKeys)
|
|
40
|
+
throw invalidCredentialsError(retryAfterMs)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// An over-long password can never match a stored hash; reject before scrypt
|
|
44
|
+
// so it can't be abused as a CPU-bound denial-of-service vector.
|
|
45
|
+
if (password.length > MAX_PASSWORD_LENGTH) {
|
|
46
|
+
fail()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const user = await findUserByEmail(getDb(), email)
|
|
50
|
+
if (!user || user.status === 'banned') {
|
|
51
|
+
fail()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const ok = await verifyPassword(password, user.password_hash)
|
|
55
|
+
if (!ok) {
|
|
56
|
+
fail()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
recordAuthAttemptSuccess(attemptKeys)
|
|
60
|
+
await setUserSession(event, user.id, user.session_version)
|
|
61
|
+
return { user: toSafeUser(user) }
|
|
62
|
+
})
|