检查drupal中是否已存在用户
当用户输入他的登录信息并点击提交时,我想检查该用户是否已经存在。 所以,我有以下两个问题 1. 对于用户点击登录表单上的提交按钮的情况,需要实现哪个钩子。我需要用户输入的用户名。 2. 如何以编程方式检查用户是否已存在于 drupal 中?
一些示例代码将非常感激。 请帮忙。
谢谢。
When a user enters his login information and hits submit, i want to check if the user already exists or not.
So, i have the following two questions
1. Which hook is needed to be implemented , for the case when user hits the submit button on the login form. I need the username entered by the user.
2. How to check if a user already exists in drupal or not programmatically ?
Some sample code would be really appreciated.
Please help.
Thank You.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Drupal 7 提供了一个按名称获取用户对象的函数:
http:// /api.drupal.org/api/drupal/modules%21user%21user.module/function/user_load_by_name/7
Drupal 7 provides a function to get a user object by name :
http://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_load_by_name/7
这可以通过 hook_form_alter 来完成:
在这种情况下,直接查询数据库比使用 user_load 更好,因为它也挂钩到其他模块。
This can be done with
hook_form_alter
:It's better to query the DB directly in this case than than using
user_load
as it hooks into other modules as well.在 Drupal 7 中,在验证函数中替换为:
In Drupal 7, substitute for this in the validation function:
我意识到这已经快两年了,但 user_authenticate 做得很好。
希望这对其他人有帮助。
I realize this is almost 2 years old, but user_authenticate does this nicely.
Hope this helps someone else.
您可以尝试查看这两个模块以获取灵感:Friendly_register 和 username_check。
You can try to look on these 2 modules for inspiration: friendly_register and username_check.