Cannot login with a role defined in a plugin

Hi everyone,

I try to group in plugin a custom role and user blueprint.

My problem is that users with the custom role are not able to login into the panel.
Also, if I can create “newcomer” users from the panel, their custom fields are not displayed.
If I move those role and blueprints files in the site folder (not as plugin) everything works well.

What do I miss?

Any help will be appreciated:
Thanks Julien.


My plugin arborescent is:

site/plugins/custom-role
  - blueprints/
    - users/
      - newcomer.yml
  - roles/
    - newcomer.php
  - custom-role.php

my custom-role.php contains:

<?php

$kirby->set('blueprint', 'newcomer', __DIR__ . '/blueprints/users/newcomer.yml');
$kirby->set('role',      'newcomer', __DIR__ . '/roles/newcomer.php');

According to the docs, the user blueprint must be registered like this:

$kirby->set('blueprint', 'users/admin', __DIR__ . '/blueprints/users/admin.yml');

The role setting looks ok, hm :thinking:

Edit: I just tested it with that little change and works (creating the user, logging in as this new user, and the fields appear as well):

$kirby->set('blueprint', 'users/newcomer', __DIR__ . '/blueprints/users/newcomer.yml');

Thank you for your answer!
Blueprint works well indeed. But I still cannot log in users with the role file describe in the plugin… It’s strange, especially if you can :slight_smile:. I kept looking and tell you if I find something!

Could you post your role file, please?

Sure:

<?php

// site/roles/editor.php
return [
  'name'        => 'Newcomer',
  'default'     => false,
  'permissions' => [
    '*'                 => true,
    'panel.site.update' => true,
    'panel.user.*'      => false,
    'panel.user.read'   => true,
    'panel.user.update' => function() {

      if($this->user()->is($this->target()->user())) {
        // users are allowed to edit their own information
        return true;
      } else {
        // other users can't be edited
        return false;
      }

    }
  ]
];

But role works when in site/roles folder…

Yes, that should and does work.

Which Kirby version are you using? Do you get any error messages when trying to log into the Panel? Also check out your server error logs, if available.

I am using the 2.5.4 (kirby + panel).
Panel says nothing, just reload the login page without any warning. If I try to log with a bad password, a message is displayed, as expected. No error in my PHP logs…

That’s weird. Are you using any other role definitions?

Thanks to your remark, I found something interesting!

I have another custom role in site/roles, they are two different filenames and role names. But if I remove it, my plugin role works.

Yes, I can reproduce this. Login is not possible if I add a custom role in /site/roles.

Looks like a bug, but thank you a lot for your help.
At least, I know why it did not work!

Also, it’s probably related, but I cannot add multiple roles in the plugin.

For example, in custom-role.php, the “editor” is not available from the panel.

<?php

$kirby->set('blueprint', 'users/newcomer', __DIR__ . '/blueprints/users/newcomer.yml');
$kirby->set('role',      'newcomer',       __DIR__ . '/roles/newcomer.php');
$kirby->set('role',      'editor',         __DIR__ . '/roles/editor.php');

Multiple roles in a plugin work for me, though. Have you removed the roles from the site/roles folder?

My bad, editor content was all commented… I should delete my previous comment to avoid confusion :confounded: