Hello!

Due to the recently committed issue #2838149: Respect Registration Account Setting, now the module will refuse to create users if the site is set to "only administrators can create accounts". Which is ok in most cases, but not in our current one :)

In our case, we want to allow automatic registrations to the site only for people logging via openId (via our google app domain), but only though that. So, the site was set to "only administrators can create accounts", and we were registering users via openid. Now with the beta3 version this is not possible anymore.

So, in order to support our use case (which sounds like it might be useful for other people) we propose to add a new setting in the settings page, that will allow admins to "override" the registration settings. This setting would be initially set to false. If true, the check is skipped and the user is created.

What do you think?

Attaching the patch.

Comments

vermario created an issue. See original summary.

vermario’s picture

Status: Active » Needs review
StatusFileSize
new4.6 KB

Patch attached.

interx’s picture

Status: Needs review » Needs work

Thanks for the patch, I'm in a similar case: don't allow any manual user registration, but do allow OpenID Connect users.

The patch works fine. I do have some remarks:

  • The comment "// Check if we are..." exceed 80 chars and should be split up on 2 lines
  • The else statement should start on a new line "} else {"
  • I don't see any test for the new registration method, only SettingsFormTest that uses the config value. It might need the extra value.
  • You are adding a value to the setting config. The default config is set via the patch, but you should also update the active config, f.e. :
    /**
     * Update the active config with the registration override value.
     */
    function openid_connect_update_8102() {
      $config_factory = \Drupal::configFactory();
      $config = $config_factory->getEditable('openid_connect.settings');
      $config->set('override_registration_settings', FALSE);
      $config->save();
    }
    
yannickoo’s picture

@interX you can find a patch for this feature over in #2867260: Add pre_login hook similar to post_authorize hook (D8 version) :)

vermario’s picture

Status: Needs work » Needs review
StatusFileSize
new6.07 KB

(hi @yannickoo!) :) It seems to me that the linked issue provides a code based solution (which is nice), while this patch provides a solution via the ui/config. For this reason I think it might still be useful, and I am providing a revised patch following the feedback from @interX (thank you very much for the feedback by the way!)

interx’s picture

I think this patch is a more elegant way to simply override the registration setting and continue the path in the OpenID Connect module.
A pre_login hook could be useful, but imo it shouldn't be used as in the linked example (specifically create an authmap for the account manually).

yannickoo’s picture

Sorry for the confusion, the patch over in the other issue is handy if you e.g. migrate users beforehand but in your case you want to allow registrations via OpenID Connect but not via /user/register – sorry 😬

interx’s picture

/nitpickmodus on :)

Normally the comment:

    // Check if we are allowing to create users overriding
    // the drupal user register settings:

should continue on one line until a word reaches the 80 characters limit, and then go to the next line.
Also, Drupal should always start with a capital. So, it should be:

    // Check if we are allowing to create users overriding the Drupal user
    // register settings:

/nitpickmodus off

sanduhrs’s picture

* Changed the code to only respect override in case admin only is set for user registration.
* Changed order of form elements
* Some code style fixes
* Syntax error fix

Thanks for the patch!

  • sanduhrs committed ebddc8c on 8.x-1.x
    Issue #2904411 by vermario, sanduhrs: Allow to override the drupal user...
sanduhrs’s picture

Assigned: vermario » Unassigned
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

rojan raj’s picture

What if user settings has Visitors, but administrator approval is required.
Currently I have this requirement.

rojan raj’s picture

What if user settings has Visitors, but administrator approval is required.
Currently I have this requirement.