Hi LoginToboggan,
This is in regards to: http://drupal.org/node/1431696
Basically, the Services module has a User Login resource that allows a user to login with a user name and password. The LoginToboggan module of course lets a user login with an e-mail address and password.
It would be great if this was also possible with the Services module through LoginToboggan with an implementation of a new resource through the Services API.
I am familiar with creating resources using the Services API and would be happy to implement this extension for LoginTobboggan. Please let me know if this is something you are interested in, thanks!
Comment | File | Size | Author |
---|---|---|---|
#11 | logintoboggan-n1431724-11.patch | 1.1 KB | DamienMcKenna |
#6 | logintoboggan-services-1431724-5.patch | 2.34 KB | Jon Pugh |
#5 | logintoboggan-services-1431724-5.patch | 2.62 KB | Jon Pugh |
Comments
Comment #1
Jon PughSo, you already have a patch for this? We need the same thing, would you mind posting it?
Comment #2
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedI have the patch for the user_resource.inc, but I'll hold off on posting it. I am waiting for the OK to make an actual Service Resource for this though.
In the mean time, just place this line of code in the _user_resource_login function (D6), just before the call to user_authenticate(...):
if (valid_email_address($username)) { $username = db_result(db_query(" SELECT name FROM {users} WHERE mail = '%s' ",$username)); }
This allows the user login service resource to be used in the exact same way, just pass an e-mail address in place of the user name.
For example, do a POST to http://localhost/my_drupal_site/my_services_endpoint/user/login.json with the following args:
username=foo@foo.com&password=TacoTuesday
The D7 version should be very similar, it would just require a few tweaks for the new database API calls in D7.
Comment #3
stevecowie CreditAttribution: stevecowie commentedI'm not too familiar with the services module. Can you explain a bit more about the use case so I can think about it. It's unlikely to be honest, as we only undertake to keep LT operational with nothing installed other than core so don't want to create dependencies.
Comment #4
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedBasically the Services module can create and expose a RESTful server on a Drupal site. Then for example, an HTML5 mobile application can make calls to resources available through Services. One common resource to use is the 'user login' resource provided by Services. By using this resource, a mobile app can login a user to a Drupal site and subsequently use other service resources that user has permission to do (create content, post comments, etc.).
The user login resource requires a user name and password (just like a normal login). However, it would be fantastic if LT's login with e-mail address feature could be exposed to this as well. That way a user can login with their e-mail and password from a mobile app.
I understand that this may be out of LT's scope. If so, no worries, I'll start a sandbox module to allow this, thanks!
Comment #5
Jon PughHere's a patch that adds a whole new module to the /contrib folder: logintoboggan_services.
In the meantime, I am going to add a new project on d.o for this just because. Will keep tabs on this issue to see if it gets rolled into logintoboggan.
Comment #6
Jon Pughoops, forgot to make it relative.
Comment #7
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedNice job Jon Pugh! Thanks for the quick turn around. Please send a link to the Sandbox module when it is ready and I can review it for you.
Comment #8
stevecowie CreditAttribution: stevecowie commentedcareernerd, just been reviewing this, and I can see a case for having this as an LT contrib module. My point at #3 is nonsense as there's already rules and variable modules in LT Contrib, and both of those have dependencies.
Comment #9
D34dMan CreditAttribution: D34dMan commentedAs there is already a resource which have been declared for the purpose of user login action i've created a patch for the same action in services issue queue. Here is the link - Using Email to log in instead of user name..
Reviewing the code in #6 shows a striking similarity in the approach. I am sure the Jon Pugh's approach should work.
But if you are creating a module as a contrib for LT i would strongly suggest you respect variable_get('user_email_verification', TRUE) somewhere in your module to check if site administrator really wants to use that feature. (This is the main reason why am putting this to needs work.)
Comment #10
DamienMcKennaClosed a duplicate: #457082: Support XML-RPC services for account creation, validation
Comment #11
DamienMcKennaThis is a patch for D6 that implements hook_services_resources_alter() to override the callback for the user login action, and then in the replacement callback it uses the same query from logintoboggan_user_login_validate to see if the user can be matched by email address. Simple stuff, and it's only a few lines of code so should IMHO be considered for inclusion in the main module.
Comment #12
JoeRobertsPhotography CreditAttribution: JoeRobertsPhotography commentedWhat ever happened with this? Did it get added into drupal 7 version? Just curious. Thanks.
Comment #13
info.amit.dahiya CreditAttribution: info.amit.dahiya commentedThis is not working for drupal 7. while enabling service module it is breaking.
Comment #14
DamienMcKennaSo someone needs to port the patch to the D7 branch.
Comment #15
housser CreditAttribution: housser commentedI found the module defined in #6 seems to work just fine for me, Drupal 7.39, LoginToboggan 1.5.
Comment #16
falcon03 CreditAttribution: falcon03 as a volunteer commentedAny update on this? What would need to be done to get the patch in a stable release soon?
Comment #17
DamienMcKenna@falcon03: Someone needs to port the patch to the D7 version of the module.
Comment #18
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedHere's how it can be done with a custom Drupal module:
sites/all/modules/custom/example/example.module
sites/all/modules/custom/example/resources/resource.user-login.inc
Comment #19
D34dMan CreditAttribution: D34dMan as a volunteer and commentedI have done something similar as mentioned by @tyler.frankenstein, but while using user_load_by_mail function. instead of query.
Comment #20
scarer CreditAttribution: scarer commentedI tried implementing a new module and enabling it. It still doesn't work when I use:
POST
http://mywebsite.com/user/login?_format=json
Body (raw):
{"mail":"user@user.com","pass":"user"}
It returns:
{"message":"Missing credentials.name."}
When I change the body to:
{"name":"user@user.com","pass":"user"}
It returns:
{"message":"Sorry, unrecognized username or password."}
I created a custom module called 'loaduserbyemail' with a directory/file structure in the custom folder in modules:
loaduserbyemail/loaduserbyemail.info.yml
loaduserbyemail/loaduserbyemail.module
loaduserbyemail/resources/resource.user-login.inc
loaduserbyemail.info.yml
loaduserbyemail.module
resource.user-login.inc
However when I use the browser and go to the user login form I can use the email in the form field with the password for that user.
Comment #21
tyler.frankenstein CreditAttribution: tyler.frankenstein commented> http://mywebsite.com/user/login?_format=json
This is a path you'd use for Drupal 8 core's REST. You should use this path for Drupal 7 Services:
http://mywebsite.com/[my-endpoint-path]/user/login.json