如何在不使用API​​的情况下将用户注册到Drupal 6.x? [英] How to register a user to Drupal 6.x without using the API?

查看:99
本文介绍了如何在不使用API​​的情况下将用户注册到Drupal 6.x?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们必须通过Java编写的Web服务提供注册方法,因此我们无法访问Drupal API。但是我们需要能够成功注册用户。只需将用户添加到users表中即可,因为新创建的用户无法成功登录。再次,我喜欢Drupal API,并且总是使用它,因为这是正确的方法,但在这种情况下,我们没有教师这样做。对这个困境的任何见解?

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 ?

推荐答案

你会想要浏览 user_save() API函数来了解什么是Drupal创建一个新用户。

You'll want to step through the user_save() API function to get an idea of what Drupal does when creating a new user.

Drupal在保存数据类型方面没有任何深刻的魔力:它全部在数据库中。所以,尽管不能使用Drupal API并不理想,但实际上只处理两个数据库插入: {user} 表插入(你'已经完成了),以及 {users_roles} 表插入。

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.

根据您的信息,我怀疑失踪链接是您没有为新用户的UID向 {users_roles} 表添加一行。 user_save()中的相关行:

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 in user_save():

db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $account->uid, $rid);

其中 $ account-> uid 新创建的用户的UID,以及 $ rid 是您要给用户的角色的ID。新用户至少需要认证用户角色。

Where $account->uid is the UID of the newly created user, and $rid is the ID of the role you want to give the user. A new user needs at least the authenticated user role.

user_save )主要是理智检查( user_save()处理更新用户,除了创建一个新的)和钩子触发,你可能会'这个用例需要担心。

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.

这篇关于如何在不使用API​​的情况下将用户注册到Drupal 6.x?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆