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

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

问题描述

我们必须通过用 Java 编写的 Web 服务提供一个注册"方法,因此我们无法访问 Drupal API.但是我们需要能够成功注册一个用户.简单地将用户添加到用户表中是行不通的,因为新创建的用户永远无法成功登录.我再次喜欢 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.新用户至少需要 authenticated user 角色.

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天全站免登陆