Back to BlogProtect Support

jiiis
jiiis

Hi,

Thanks again for this plugin.

Been testing this plugin, so it seems that a user has to be in a group with a permission key bound with a blog category to view the blogs from that category. A problem is that the newly created users wouldn't be put in a group by default (there is said to be a registered default group, https://github.com/rainlab/user-plugin/issues/199, but it doesn't seem to work). This means it is still not possible for automatically enabling registered users to view protected blogs, is it?

Wondering if we could have a predefined permission code which enables all users (with or without a group) to view those blogs from categories with this permission code?

Thanks a lot.

KurtJensen
KurtJensen

You could create a page that is only visible by registered users and place unprotected blog post list component on it. Set the category filter to what you want them to see.

Example:

{% if user.is_activated %}

{% component 'blogPosts' %}

{% else %}
Hello you are not activated.
{% endif %}

Last updated

comlet21118
comlet21118

This solution by KurtJensen does not help me as well.

The users should be mapped to one default group, which have minimum permissions. Currently with the Build 390, this is not the case.

Is there a solution for this?

Thanks.

alxy
alxy

You can extend the User model with some custom code.

This is perfectly possible, since the User plugin makes heavy use of the Events api.

The corresponding docs can be found here, the $user is passed to the event. So its just a very few lines of Code to assign a default group ;)

comlet21118
comlet21118

Hello Alxy,

I thought I made some mistake in creating Ajax handler calls. Is there some kind of code available in the forum or somewhere? I am new to October and also not a coder.

Thanks for your help.

Last updated

alxy
alxy
Event::listen('rainlab.user.activate', function($user) {
            $user->groups()->attach(1);
        });

This should make the group with ID 1 default. Here is where you should register this handler.

comlet21118
comlet21118

Hello Alxy,

I have added the above code - after understand the link on registration of this handler above - in the public function boot(). This works perfect.

The Group ID 1 is assigned to Guest Users and ID 2 is for Registered Users. If one wants to add a user upon activation, then one requires $user->groups()->attach(2);

Thanks to Alxy for this help.

Last updated

1-7 of 7