I've run into an issue when using user.save to register a new user. When user.save is called with a new user, it executes the register form, but that form should be run as an anonymous user. If the current service session is authenticated this causes a problem. I think that the code should drop to the anonymous user, run the form, and then come back to whatever user is logged in.

Comments

abs_ts’s picture

StatusFileSize
new1.03 KB

Here's the patch.

abs_ts’s picture

I should clarify that this occurs in a situation where you are not giving anonymous users permissions to the user service, and require that all calls have a logged in user for security reasons. The current user.save code works fine if you can call user.save with an anonymous session, but in setups where anonymous doesn't have the required permissions to register a user the call returns with "access denied". The patch I supplied allows you to require remote calls be using a services user account, but still be able to run the registration form as anonymous.

Hopefully that makes sense.

marcingy’s picture

Status: Active » Needs work

I'll be happy to commit this but there coding style issues plus

This is not needed

$orig_state = session_save_session();

and

session_save_session( $orig_state );

should be

session_save_session(TRUE);

And can't this block of code be simplified

$newuser = user_load( array( 'name' => $form_state['values']['name'] ) );
$form_state['user'] = $newuser;

to

$form_state['user'] = user_load( array( 'name' => $form_state['values']['name'] ) );
abs_ts’s picture

Status: Needs work » Needs review
StatusFileSize
new967 bytes

OK. Let's try that again with a new patch.

abs_ts’s picture

StatusFileSize
new958 bytes

I realized that I had some whitespace at the end of a line or two. Here's a corrected patch with the whitespace removed.

marcingy’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev
Status: Needs review » Patch (to be ported)

Commited however I have just realised that this also needs to go into 3.x as well.

marcingy’s picture

Status: Patch (to be ported) » Fixed
kylebrowning’s picture

Status: Fixed » Needs work

So, this actually broke the user resource so I removed it. feel free to get another patch in but please have it reviewed before committing.

glennpratt’s picture

It appears this was applied to 6.x-3.x and not removed. This breaks things for me, because I need to be able to create a user as another user, not switch to anon, for a number of reasons.

In IRC, kylebrowning said he would remove it and replace it with a new register action to allow this functionality. See #1134872: Create register action for user resource

kylebrowning’s picture

Status: Needs work » Closed (won't fix)

This workaround was fine for 2.x but in 3.x we decided to add the register method as #9 says.

glennpratt’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Closed (won't fix) » Needs review
StatusFileSize
new912 bytes

The previous patch introduced a redundant user_load. Because of other contrib modules, it doesn't work on my setup and clears the $form_state['user'] entry.

The reason this seems redundant is user_register_submit populates $form_state['user'].

http://api.drupal.org/api/drupal/modules--user--user.module/function/use...

This patch removes that as well. User resource tests are a little broken for me, but the tests related to user creation pass just the same.

kylebrowning’s picture

Status: Needs review » Fixed

patch in #11 has been tested, and fixed, it does not exist in 7.x therefore this is now fixed.

Status: Fixed » Closed (fixed)

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