When creating a user account through the "/user/register" endpoint, the data parameters to be passed are an array consisting of: "name", "mail", "pass". However, when logging in through the endpoint "/user/login" the parameters to be passed are called "username", "password".

Can the parameters on the two endpoints be made consistent?

Comments

ygerasimov’s picture

Category: feature » task
Issue tags: +Novice

I agree with this issue. Please provide a patch. I am for shorter version 'name', 'pass'.

lisa.rae’s picture

Patch is attached...

lisa.rae’s picture

Status: Active » Needs review
ygerasimov’s picture

Patch won't pass tests. Please correct tests as well.

lisa.rae’s picture

Tests corrected, resubmitting....

kylebrowning’s picture

Status: Needs review » Needs work

Id prefer that you used the versioning API that services provides so that this doesnt break peoples clients.

look at services.versions.api.php

lisa.rae’s picture

So, use the versioning api instead of patching the user resources and associated tests directly?

kylebrowning’s picture

yeah because if you change the user resource directly, peoples clients will break when they update Services.

As an example, this is in the user resource and lets admins choose the version they wish to use for the logout method.

<?php
/**
 *  Update the current user logout callback to the new callback with a better return value.
 */
function _user_resource_logout_update_1_1() {
  $new_set = array(
    'callback' => '_user_resource_logout_1_1',
  );
  return $new_set;
}

/**
 * Logs out the currently logged in user and returns the new user object.
 */
function _user_resource_logout_1_1() {
  global $user;

  if (!$user->uid) {
    // User is not logged in
    return services_error(t('User is not logged in.'), 406);
  }

  watchdog('user', 'Session closed for %name.', array('%name' => $user->name));

  // Destroy the current session.
  module_invoke_all('user_logout', $user);
  session_destroy();

  // Load the anonymous user.
  $user = drupal_anonymous_user();

  return $user;
}
lisa.rae’s picture

Status: Needs work » Needs review
StatusFileSize
new1.1 KB

That actually makes perfect sense. I wasn't aware there was an update API.

New patch, patching user_resource.inc to include API version 1.1 for the login endpoint.

Status: Needs review » Needs work
Issue tags: -Novice

The last submitted patch, services-consistent-register-login-parameters-1975954-9.patch, failed testing.

ygerasimov’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
Issue tags: +Novice

The last submitted patch, services-consistent-register-login-parameters-1975954-9.patch, failed testing.

lisa.rae’s picture

Status: Needs work » Needs review
StatusFileSize
new1021 bytes

ok, recreated the patch from inside the module directory this time, resubmitting.....

kylebrowning’s picture

Status: Needs review » Needs work

I hate to be picky, but can we get a test for the new version response? Just create a total new test in the User resource.

leave the old one test intact, but make a new one, pass the version HEADER and verify that the parameters are correct and then this patch will be perfect.

You can see some examples in ServicesVersions.test and dont forget youll need to update the endpoint!

lisa.rae’s picture

Sorry, but I'm looking at the example test, and I don't understand how this works, so it's going to be impossible for me to write a test for this in any reasonable amount of time. I looked for the test case for the logout api version 1.1 and didn't see it -- if you would point me to that one I'll look at it and see if I can figure out what needs to be done.

kylebrowning’s picture

Status: Needs work » Needs review
StatusFileSize
new5.02 KB

Heres a patch with tests.

ygerasimov’s picture

Status: Needs review » Reviewed & tested by the community
ygerasimov’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

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