We have to have a “register” method available via web service that is written in java so hence forth we do not have access to the Drupal API. But we need to be able to register a user successfully. Simply adding a user to the users table will not do it as the newly created users are never able to login successfully. Again I love the Drupal API and would always use that as that is the “correct” way to do it but in this case we just dont have the faculty to do that. Any insights to this dilemma ?
Share
You’ll want to step through the
user_save()API function to get an idea of what Drupal does when creating a new user.There isn’t any deep magic to what Drupal does with saving that type of data: it’s all in the database. So, while it’s not ideal that you can’t use the Drupal API, you’re really only dealing with two database inserts: the
{user}table insert (which you’ve already done), and the{users_roles}table insert.Based on your info, I suspect the missing link is that you’re not adding a row to the
{users_roles}table for your new user’s UID. The relevant line inuser_save():Where
$account->uidis the UID of the newly created user, and$ridis the ID of the role you want to give the user. A new user needs at least theauthenticated userrole.Everything else in
user_save()is mainly sanity checking (user_save()handles updating a user in addition to creating a new one) and hook firing, which you likely don’t need to worry about for this use-case.