使用Drupal中的外部标识库验证注册数据 [英] Validating Registration Data with an External Identity Repository in Drupal

查看:125
本文介绍了使用Drupal中的外部标识库验证注册数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的用户尝试注册时,我想通过检查外部身份存储库(例如调用Web服务或查找目录服务器)来确保他的信息有效。

When my user tries to register, I'd like to make sure his information is valid, by checking an external identity repository (e.g. call a web service or look up a directory server).

是否可以使用任何现有的模块?如果没有,开发这个功能的最好方法是什么?

Is that possible with any existing module? If not, what would be the best way to develop this functionality?

推荐答案

我不知道现有的模块允许除了自定义验证的,但它是非常容易实现这个使用验证的行动 hook_user()

I'm not aware of an existing module allowing the addition of custom validation, but it is fairly easy to implement this using the 'validate' action of hook_user():

function yourModule_user($op, &$edit, &$account, $category = NULL) {
  // Are we in the validation phase of a new user registration?
  if ('validate' == $op && 'user_register' == $edit['form_id'] && 'account' == $category) {
    // Yes, do custom validation...
    // NOTE: Just an example to validate by email.
    // Check the other elements in $edit array (e.g. 'name') for more options
    $mail_is_valid = yourModule_custom_mail_validation($edit['mail']);
    // Is the mail address OK?
    if (!$mail_is_valid) {
      // No, set error on mail form field
      form_set_error('mail', t('your custom error message'));
    }
  }
}

这将停止注册过程并且只要重新显示与邮件字段错误消息中的登记表为 yourModule_custom_mail_validation()不返回TRUE。

This would stop the registration process and redisplay the registration form with the error message on the mail field as long as yourModule_custom_mail_validation() does not return TRUE.

如果您想要对现有用户编辑帐户进行验证,您可以将

If you want the validation to happen for existing users editing their account also, you could drop the

 && 'user_register' == $edit['form_id']

第一个if子句中的部分 - 代码然后运行每个用户编辑表单提交,而不仅仅是注册。

part from the first if clause - the code would then run for every user edit form submission, not just on registration.

这篇关于使用Drupal中的外部标识库验证注册数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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