Custom user login

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
monaw's picture

(Preface: I am a beginner Group user so excuse my ignorance and feel free to educate me. If this is not the right place to post questions, where should I post questions about Services?)

I would like to customize the user login resource...in particular, the client will send the username and password along with few other additional bits of information. I need the custom code to be able to login and then add a node entry from the additional info received. This custom code then needs to return the user login info AND some addtional information. Is there some doc somewhere on how to accomplish this?

Thanks for all pointers!

Comments

more details

monaw's picture

I'm using D7 and Services 7.x-3.1

Hope this will help you !

stonevo's picture

First you can look through the user_resource (inside the resource folder of services folder). From here you can see the user/login service. Next you will copy the user/login action from user_resource and create a new customized service(ex: services_adlogin). Please change the path something like user/adlogin. You would declare something like:
'user' => array(
'actions' => array(
'adlogin' => array(
'help' => 'customize login a user for a new session',
'callback' => 'services_adlogin_login',
'args' => array(
array(
'name' => 'username',
'type' => 'string',
'description' => 'A valid username',
'source' => array('data' => 'username'),
'optional' => FALSE,
),
array(
'name' => 'password',
'type' => 'string',
'description' => 'A valid password',
'source' => array('data' => 'password'),
'optional' => FALSE,
),
array(
'name' => 'data',
'optional' => FALSE,
'source' => 'data',
'description' => 'The extra data',
'type' => 'struct',
),
),
'access callback' => 'services_access_menu',
'file' => array('type' => 'inc', 'module' => 'services_adlogin'),
),
)
)
Here I created the services_adlogin to hold the customized login service. And now you just customize the services_adlogin_login function to do another thing like adding new node data..
You shouldn't change the user/login service because it's the default service.

Drupal - The modern Lego game