I would like to protect the viewing of an _entry.html page so that only a user related to that entry can view it.
Asked
Active
Viewed 106 times
1 Answers
2
You could loop through the users and compare them.
{% set authorized = false %}
{% for user in entry.authorizedUsers %}
{% if user == currentUser %}
{% set authorized = true %}
{% endif %}
{% endfor %}
{% if not authorized %}
{% redirect 403 %}
{% endif %}
Douglas McDonald
- 13,457
- 24
- 57
redirectmethod (I just chose 403 as an example), or display alternate content if you like. You may also have to check if there is a currentUser at all, using{% if currentUser %}... {% endif %}– Douglas McDonald Jan 10 '15 at 23:52in_array. It does have anin, so you could do{% if not currentUser in entry.authorizedUsers %}, but I doubt that will work when comparing whole objects to each other. Would probably need to just do the comparison on authorId, but honestly your 2nd solution seems better. – Brad Bell Jan 11 '15 at 00:20