Handle logged in users by not requiring username/email
Still post them as hidden to overcome validation, but still overwrite the values in backend to avoid manipulation
This commit is contained in:
parent
0cf90a74d7
commit
ee608539d4
|
@ -174,6 +174,12 @@ class CommentsPlugin extends Plugin
|
|||
$email = filter_var(urldecode($post['email']), FILTER_SANITIZE_STRING);
|
||||
$title = filter_var(urldecode($post['title']), FILTER_SANITIZE_STRING);
|
||||
|
||||
$user = $this->grav['user'];
|
||||
if ($user->authenticated) {
|
||||
$name = $user->fullname;
|
||||
$email = $user->email;
|
||||
}
|
||||
|
||||
/** @var Language $language */
|
||||
$language = $this->grav['language'];
|
||||
$lang = $language->getLanguage();
|
||||
|
|
|
@ -11,9 +11,21 @@
|
|||
{% if field.evaluateDefault %}
|
||||
{% set value = evaluate(field.evaluateDefault) %}
|
||||
{% endif %}
|
||||
{% if grav.user.authenticated %}
|
||||
{% if field.name == 'name' %}
|
||||
<input type="hidden" name="{{field.name}}" value="{{grav.user.fullname}}">
|
||||
{% elseif field.name == 'email' %}
|
||||
<input type="hidden" name="{{field.name}}" value="{{grav.user.email}}">
|
||||
{% else %}
|
||||
<div>
|
||||
{% include "forms/fields/#{field.type}/#{field.type}.html.twig" %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<div>
|
||||
{% include "forms/fields/#{field.type}/#{field.type}.html.twig" %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
<div class="buttons">
|
||||
|
|
Loading…
Reference in New Issue