Skip to content

Commit

Permalink
TASK: Implemented package
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandschuetz committed Aug 12, 2019
1 parent d0155cf commit 005e3ae
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 2 deletions.
19 changes: 19 additions & 0 deletions Configuration/NodeTypes.Mixin.Password.yaml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Neos:
Neos:
fusion:
autoInclude:
CodeQ.PasswordProtectedContent: true
userInterface:
translation:
autoInclude:
CodeQ.PasswordProtectedContent:
- 'Fusion/*'
- 'NodeTypes/*'
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
37 changes: 37 additions & 0 deletions Resources/Private/Fusion/Component/PasswordForm.fusion
Original file line number Diff line number Diff line change
@@ -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`
<div class={'password-protected-content' + (props.wrongPasswordStyles ? ' password-protected-content--has-error' : '')}>
<form class="password-protected-content__form" action="" method="POST">
<label class="password-protected-content__form-label" for="passwordProtectedContentPassword">{props.formMessage}</label>
<input class="password-protected-content__form-input" id="passwordProtectedContentPassword" type="password" name="passwordProtectedContentPassword" />
<div class="password-protected-content__eror-message" id="passwordProtectedContentPasswordError" @if.has={props.wrongPassword} style={props.wrongPasswordStyles}>
{props.wrongPasswordErrorMessage}
<script>{"
document.getElementById('passwordProtectedContentPassword').addEventListener('input', function() {
/* as soon as the user types, remove the error message */
var el = document.getElementById('passwordProtectedContentPasswordError'); if(el) el.remove();
}, false);
"}</script>
</div>
<input class="password-protected-content__form-submit" type="submit" value="Submit" />
</form>
</div>
`

@cache {
mode = 'embed'
}
}
43 changes: 43 additions & 0 deletions Resources/Private/Fusion/Helper/ProtectContent.fusion
Original file line number Diff line number Diff line change
@@ -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`
<Carbon.Notification:Tag type="info">
{Translation.translate('backend.configuredPasswordNotification', null, [configuredPassword], 'Fusion/Helper/ProtectContent', 'CodeQ.PasswordProtectedContent')}
</Carbon.Notification:Tag>
{content}
`
}
noOrWrongPassword {
condition = ${configuredPassword != enteredPassword}
renderer = CodeQ.PasswordProtectedContent:Component.PasswordForm {
wrongPassword = ${String.length(enteredPassword) > 0}
}
}
validPassword {
condition = true
renderer = ${content}
}
}
}
9 changes: 9 additions & 0 deletions Resources/Private/Fusion/Root.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
##############################################
##############################################
#### ####
#### !!!DO NOT EDIT THIS FILE!!!! ####
#### ####
##############################################
##############################################

include: **/*.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" product-name="CodeQ.PasswordProtectedContent" source-language="en" datatype="plaintext" target-language="de">
<body>
<trans-unit id="formMessage" xml:space="preserve">
<source>This content is protected, please enter the password:</source>
<target xml:lang="de" state="translated">Dieser Inhalt ist geschützt, bitte geben Sie das Passwort ein:</target>
</trans-unit>
<trans-unit id="wrongPasswordError" xml:space="preserve">
<source>This password is wrong.</source>
<target xml:lang="de" state="translated">Dieses Passwort ist falsch.</target>
</trans-unit>
</body>
</file>
</xliff>
11 changes: 11 additions & 0 deletions Resources/Private/Translations/de/Fusion/Helper/ProtectContent.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" product-name="CodeQ.PasswordProtectedContent" source-language="en" datatype="plaintext" target-language="de">
<body>
<trans-unit id="backend.configuredPasswordNotification" xml:space="preserve">
<source>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.</source>
<target xml:lang="de" state="translated">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.</target>
</trans-unit>
</body>
</file>
</xliff>
15 changes: 15 additions & 0 deletions Resources/Private/Translations/de/NodeTypes/Mixin/Password.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" source-language="en" datatype="plaintext">
<body>
<trans-unit id="groups.passwordprotect" xml:space="preserve">
<source>Password Protection</source>
<target xml:lang="de" state="translated">Passwort-Schutz</target>
</trans-unit>
<trans-unit id="properties.passwordProtectedContentPassword" xml:space="preserve">
<source>Password (visible for all editors)</source>
<target xml:lang="de" state="translated">Passwort (sichtbar für alle Editoren)</target>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" product-name="CodeQ.PasswordProtectedContent" source-language="en" datatype="plaintext">
<body>
<trans-unit id="formMessage" xml:space="preserve">
<source>This content is protected, please enter the password:</source>
</trans-unit>
<trans-unit id="wrongPasswordError" xml:space="preserve">
<source>This password is wrong.</source>
</trans-unit>
</body>
</file>
</xliff>
10 changes: 10 additions & 0 deletions Resources/Private/Translations/en/Fusion/Helper/ProtectContent.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" product-name="CodeQ.PasswordProtectedContent" source-language="en" datatype="plaintext">
<body>
<trans-unit id="backend.configuredPasswordNotification" xml:space="preserve">
<source>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.</source>
</trans-unit>
</body>
</file>
</xliff>
13 changes: 13 additions & 0 deletions Resources/Private/Translations/en/NodeTypes/Mixin/Password.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" source-language="en" datatype="plaintext">
<body>
<trans-unit id="groups.passwordprotect" xml:space="preserve">
<source>Password Protection</source>
</trans-unit>
<trans-unit id="properties.passwordProtectedContentPassword" xml:space="preserve">
<source>Password (visible for all editors)</source>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit 005e3ae

Please sign in to comment.