From 005e3aebdae7b97309c55aa3c5b64ec42a6cc5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Schu=CC=88tz?= Date: Mon, 12 Aug 2019 16:32:38 +0200 Subject: [PATCH] TASK: Implemented package --- Configuration/NodeTypes.Mixin.Password.yaml | 19 ++++++++ Configuration/Settings.yaml | 11 +++++ README.md | 10 ++++- .../Fusion/Component/PasswordForm.fusion | 37 ++++++++++++++++ .../Fusion/Helper/ProtectContent.fusion | 43 +++++++++++++++++++ Resources/Private/Fusion/Root.fusion | 9 ++++ .../de/Fusion/Component/PasswordForm.xlf | 15 +++++++ .../de/Fusion/Helper/ProtectContent.xlf | 11 +++++ .../de/NodeTypes/Mixin/Password.xlf | 15 +++++++ .../en/Fusion/Component/PasswordForm.xlf | 13 ++++++ .../en/Fusion/Helper/ProtectContent.xlf | 10 +++++ .../en/NodeTypes/Mixin/Password.xlf | 13 ++++++ 12 files changed, 204 insertions(+), 2 deletions(-) create mode 100755 Configuration/NodeTypes.Mixin.Password.yaml create mode 100755 Configuration/Settings.yaml create mode 100755 Resources/Private/Fusion/Component/PasswordForm.fusion create mode 100755 Resources/Private/Fusion/Helper/ProtectContent.fusion create mode 100755 Resources/Private/Fusion/Root.fusion create mode 100755 Resources/Private/Translations/de/Fusion/Component/PasswordForm.xlf create mode 100755 Resources/Private/Translations/de/Fusion/Helper/ProtectContent.xlf create mode 100755 Resources/Private/Translations/de/NodeTypes/Mixin/Password.xlf create mode 100755 Resources/Private/Translations/en/Fusion/Component/PasswordForm.xlf create mode 100755 Resources/Private/Translations/en/Fusion/Helper/ProtectContent.xlf create mode 100755 Resources/Private/Translations/en/NodeTypes/Mixin/Password.xlf diff --git a/Configuration/NodeTypes.Mixin.Password.yaml b/Configuration/NodeTypes.Mixin.Password.yaml new file mode 100755 index 0000000..a2babfa --- /dev/null +++ b/Configuration/NodeTypes.Mixin.Password.yaml @@ -0,0 +1,19 @@ +'CodeQ.PasswordProtectedContent:Mixin.Password': + abstract: true + ui: + inspector: + groups: + passwordprotect: + label: i18n + icon: 'fas fa-lock' + properties: + passwordProtectedContentPassword: + type: string + defaultValue: '' + ui: + label: i18n + icon: 'fas fa-lock' + reloadPageIfChanged: true + inspector: + group: passwordprotect + position: 100 diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml new file mode 100755 index 0000000..cf418dd --- /dev/null +++ b/Configuration/Settings.yaml @@ -0,0 +1,11 @@ +Neos: + Neos: + fusion: + autoInclude: + CodeQ.PasswordProtectedContent: true + userInterface: + translation: + autoInclude: + CodeQ.PasswordProtectedContent: + - 'Fusion/*' + - 'NodeTypes/*' diff --git a/README.md b/README.md index 353d79d..ca242c6 100755 --- a/README.md +++ b/README.md @@ -27,14 +27,13 @@ We use semantic-versioning so every breaking change will increase the major-vers ## Usage - 1. Add the mixin `'CodeQ.PasswordProtectedContent:Mixin.Password'` to any NodeType to allow editors to configure a password. 2. Add the following process function to protect the content `@process.protect = CodeQ.PasswordProtectedContent:Helper.ProtectContent` The process function is not added automatically, because you probably want to render headers and footers of your page. No you can specifically define which content should be rendered and which not. 3. You need to configure your Fusion object to be cached dynamic based on the post parameter like this: - ```fusion + ```neosfusion @cache { mode = ‘dynamic’ entryIdentifier { @@ -49,6 +48,13 @@ We use semantic-versioning so every breaking change will increase the major-vers } ``` +You can also replace the form rendering with your own by defining `passwordForm` on the processor: +```neosfusion +@process.protect = CodeQ.PasswordProtectedContent:Helper.ProtectContent { + passwordForm = Vendor.YOUR_CUSTOM_PASSWORD_FORM_FUSION_COMPONENT +} +``` + ## License Licensed under MIT, see [LICENSE](LICENSE) diff --git a/Resources/Private/Fusion/Component/PasswordForm.fusion b/Resources/Private/Fusion/Component/PasswordForm.fusion new file mode 100755 index 0000000..db028a2 --- /dev/null +++ b/Resources/Private/Fusion/Component/PasswordForm.fusion @@ -0,0 +1,37 @@ +prototype(CodeQ.PasswordProtectedContent:Component.PasswordForm) < prototype(Neos.Fusion:Component) { + ################################## + # These settings are public API: # + ################################## + formMessage = ${Translation.translate('formMessage', null, [], 'Fusion/Component/PasswordForm', 'CodeQ.PasswordProtectedContent')} + wrongPasswordErrorMessage = ${Translation.translate('wrongPasswordError', null, [], 'Fusion/Component/PasswordForm', 'CodeQ.PasswordProtectedContent')} + wrongPasswordStyles = 'color: red;' + + ################################## + # Property set by the processor: # + ################################## + wrongPassword = false + + # rendering + renderer = afx` +
+
+ + +
+ {props.wrongPasswordErrorMessage} + +
+ +
+
+ ` + + @cache { + mode = 'embed' + } +} diff --git a/Resources/Private/Fusion/Helper/ProtectContent.fusion b/Resources/Private/Fusion/Helper/ProtectContent.fusion new file mode 100755 index 0000000..70e8ad6 --- /dev/null +++ b/Resources/Private/Fusion/Helper/ProtectContent.fusion @@ -0,0 +1,43 @@ +prototype(CodeQ.PasswordProtectedContent:Helper.ProtectContent) < prototype(Neos.Fusion:Component) { + ################################## + # These settings are public API: # + ################################## + configuredPassword = ${q(node).property('passwordProtectedContentPassword')} + renderContentInBackend = true + passwordForm = CodeQ.PasswordProtectedContent:Component.PasswordForm + + + # rendering + @context { + configuredPassword = ${this.configuredPassword} + renderContentInBackend = ${this.renderContentInBackend} + enteredPassword = ${request.arguments.passwordProtectedContentPassword || ''} + content = ${value} + } + + renderer = Neos.Fusion:Case { + noPasswordConfigured { + condition = ${String.length(configuredPassword) == 0} + renderer = ${content} + } + backend { + condition = ${renderContentInBackend && node.context.inBackend} + renderer = afx` + + {Translation.translate('backend.configuredPasswordNotification', null, [configuredPassword], 'Fusion/Helper/ProtectContent', 'CodeQ.PasswordProtectedContent')} + + {content} + ` + } + noOrWrongPassword { + condition = ${configuredPassword != enteredPassword} + renderer = CodeQ.PasswordProtectedContent:Component.PasswordForm { + wrongPassword = ${String.length(enteredPassword) > 0} + } + } + validPassword { + condition = true + renderer = ${content} + } + } +} diff --git a/Resources/Private/Fusion/Root.fusion b/Resources/Private/Fusion/Root.fusion new file mode 100755 index 0000000..c84160b --- /dev/null +++ b/Resources/Private/Fusion/Root.fusion @@ -0,0 +1,9 @@ +############################################## +############################################## +#### #### +#### !!!DO NOT EDIT THIS FILE!!!! #### +#### #### +############################################## +############################################## + +include: **/*.fusion diff --git a/Resources/Private/Translations/de/Fusion/Component/PasswordForm.xlf b/Resources/Private/Translations/de/Fusion/Component/PasswordForm.xlf new file mode 100755 index 0000000..185bd28 --- /dev/null +++ b/Resources/Private/Translations/de/Fusion/Component/PasswordForm.xlf @@ -0,0 +1,15 @@ + + + + + + This content is protected, please enter the password: + Dieser Inhalt ist geschützt, bitte geben Sie das Passwort ein: + + + This password is wrong. + Dieses Passwort ist falsch. + + + + diff --git a/Resources/Private/Translations/de/Fusion/Helper/ProtectContent.xlf b/Resources/Private/Translations/de/Fusion/Helper/ProtectContent.xlf new file mode 100755 index 0000000..6546b77 --- /dev/null +++ b/Resources/Private/Translations/de/Fusion/Helper/ProtectContent.xlf @@ -0,0 +1,11 @@ + + + + + + This content is protected from visitors with the password "{0}". Please keep in mind, this is a weak protection and you should never protect sensitive information only with a password. + Dieser Inhalt ist vor Besuchern durch das Passwort "{0}" geschützt. Bitte beachten Sie, dass dies ein schwacher Schutz ist und sensible Daten niemals nur mit einem Passwort geschützt werden sollten. + + + + diff --git a/Resources/Private/Translations/de/NodeTypes/Mixin/Password.xlf b/Resources/Private/Translations/de/NodeTypes/Mixin/Password.xlf new file mode 100755 index 0000000..7911e79 --- /dev/null +++ b/Resources/Private/Translations/de/NodeTypes/Mixin/Password.xlf @@ -0,0 +1,15 @@ + + + + + + Password Protection + Passwort-Schutz + + + Password (visible for all editors) + Passwort (sichtbar für alle Editoren) + + + + diff --git a/Resources/Private/Translations/en/Fusion/Component/PasswordForm.xlf b/Resources/Private/Translations/en/Fusion/Component/PasswordForm.xlf new file mode 100755 index 0000000..5a0561b --- /dev/null +++ b/Resources/Private/Translations/en/Fusion/Component/PasswordForm.xlf @@ -0,0 +1,13 @@ + + + + + + This content is protected, please enter the password: + + + This password is wrong. + + + + diff --git a/Resources/Private/Translations/en/Fusion/Helper/ProtectContent.xlf b/Resources/Private/Translations/en/Fusion/Helper/ProtectContent.xlf new file mode 100755 index 0000000..4fa2dde --- /dev/null +++ b/Resources/Private/Translations/en/Fusion/Helper/ProtectContent.xlf @@ -0,0 +1,10 @@ + + + + + + This content is protected from visitors with the password "{0}". Please keep in mind, this is a weak protection and you should never protect sensitive information only with a password. + + + + diff --git a/Resources/Private/Translations/en/NodeTypes/Mixin/Password.xlf b/Resources/Private/Translations/en/NodeTypes/Mixin/Password.xlf new file mode 100755 index 0000000..fd5f107 --- /dev/null +++ b/Resources/Private/Translations/en/NodeTypes/Mixin/Password.xlf @@ -0,0 +1,13 @@ + + + + + + Password Protection + + + Password (visible for all editors) + + + +