Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have a requirement where user can login with google, but should not allow him to register using the google account.
I have seen in the code we are validating registration should be done from "admin_only" setting.
Its better to have a social auth setting to force user to register in the system like in account settings form
"Who can register accounts?
. Register & Login
. Login Only".
Comment | File | Size | Author |
---|---|---|---|
#28 | 2854156-28.patch | 6.65 KB | rpayanm |
#25 | 2854156-25.patch | 7.32 KB | himanshu-dixit |
#23 | 2854156-23.patch | 7.32 KB | denutkarsh |
#23 | interdiff-2854156-21-23.txt | 3.04 KB | denutkarsh |
#21 | interdiff-2854156-19-21.txt | 619 bytes | denutkarsh |
Comments
Comment #2
sriharsha.uppuluri CreditAttribution: sriharsha.uppuluri at Azri Solutions commentedComment #3
sriharsha.uppuluri CreditAttribution: sriharsha.uppuluri at Azri Solutions commentedAttaching the patch
Comment #4
sriharsha.uppuluri CreditAttribution: sriharsha.uppuluri at Azri Solutions commentedComment #5
denutkarsh CreditAttribution: denutkarsh at Google Code-In commentedI guess all the feature request should go to 8.x-1.x-dev .
Comment #6
gvsoI like this idea, but I think we should allow users to login, register, or both (default).
With the changes, this might become an array. Also, we need a hook_update function in social_auth.install
The label should be the same as the form field title.
It would be better if we allow checkboxes with "Register" and "Login"
What about "What can users do?"
Comment #7
denutkarsh CreditAttribution: denutkarsh at Google Code-In commentedHere is the new patch, It still needs hook_update_N() implementation but let's see if everything else is okay. Sorry, wasn't able to test it out, but it should work.
Comment #8
denutkarsh CreditAttribution: denutkarsh at Google Code-In commentedForgot some change in the previous patch. Here is the new Patch, (also added hook_update_N() )
Comment #9
gvsoSince this is short, ->save() should be in the same line. We need to explain what the update does too.
You don't need this here since you have already saved the configuration in the previous line.
For this new configuration, we need to change the warning 'Failed to create user. User registration is disabled in Drupal account settings' for something like 'Failed to create user. User registration is disabled.'
Comment #10
tameeshb CreditAttribution: tameeshb at Google Summer of Code commentedApplied changes from #9 on patch #8, please review! :)
Comment #11
denutkarsh CreditAttribution: denutkarsh at Google Code-In commentedLooks like you missed this
Comment #12
gvsoThanks @tameeshb,
We need to change the warning 'Failed to create user. User registration is disabled in Drupal account settings' in SocialAuthUserManager too
Comment #13
tameeshb CreditAttribution: tameeshb at Google Summer of Code commentedNot very sure about what do i write for this:
Modified SocialAuthUserManager.php to change warning message.
Comment #14
himanshu-dixit CreditAttribution: himanshu-dixit as a volunteer commentedMaybe this
Comment #15
gvsoMaybe
Comment #16
tameeshb CreditAttribution: tameeshb at Google Summer of Code commentedAdded documentation from #15
Comment #17
gvsoThese should be checkboxes so that the user can select both behaviors if they want.
Also, this version of hook_update_N tries to use all the spaces up to 80 cols and removes the unnecessary $config variable
Please update the project from the remote git repository. It seems you haven't done that before creating the last patch
Comment #18
denutkarsh CreditAttribution: denutkarsh at Google Code-In commentedI thought i already used checkboxes :( Would provide the new patch today with testing
Comment #19
denutkarsh CreditAttribution: denutkarsh at Google Code-In commentedHere is the new patch rerolled and also implements changes in #17. IDK if i should attach the interdiff if it's a reroll. Here are the couple of things that i changed
if (!in_array('login', $this->configFactory->get('social_auth.settings')->get('user_allowed'),)) {
to
if (!in_array('login', $this->configFactory->get('social_auth.settings')->get('user_allowed'), true)) {
.IDK why the previous code wasn't working.
This time i tested this patch, with Social Auth Twitter and it works great. The only problem i noticed is that when the user registration is blocked, two error messages appear which i don't think is cool. I will open an issue for that. Assigning gvso to review this patch.
Comment #20
gvsoI'd change these to just "Register" and "Login"
What's the issue with the messages? Can't that issue be fixed in this patch?
Comment #21
denutkarsh CreditAttribution: denutkarsh at Google Code-In commentedI have attached the new patch following the suggestion in #20 .
drupal_set_message() is called in createUser when the registration is disabled.
But since createUser() doesn't redirect to login page after this message is set the createUser() returns FALSE and then the following code is followed,
This way 2 messages are set with drupal_set_message 'User registration is disabled, please contact the administrator.' and 'You could not be authenticated, please contact the administrator' . I am not sure if we should fix that in this issue since we'll have to change createUser() function to maybe return RedirectResponse . What do you think?
Comment #22
gvsoSince registrationBlocked() is modified by the patch, let's fix that issue here. Plus, I'd change registrationBlocked() for isRegistrationDisabled() to make it more consistent with other methods.
Comment #23
denutkarsh CreditAttribution: denutkarsh at Google Code-In commentedHere is the new patch!
Comment #24
gvsoOk, everything works fine. Thanks for the patch.
My only question is if we should allow to login the user who just registered. Currently, the user who registers can't login if the settings is set to allow registration but not login.
@sriharsha.uppuluri, could you help us finding the best approach for this?
Comment #25
himanshu-dixit CreditAttribution: himanshu-dixit as a volunteer and at Google Summer of Code commented@gvso I think the current approach is fine. I tried to apply the patch on my local drupal installation but the patch needed rerolling. Here is the rerolled patch.
Comment #26
gvsoWe need to reroll this patch to make it work with 2.x
Comment #27
gvsoComment #28
rpayanmComment #29
gvsoI think, we should change the checkboxes for radio buttons "Register and login" and "Login only". I think it woudn't make much sense to allow user to register but no login since a password would be needed in that case.
Comment #31
gvsoMade the above change. Thanks everyone!