Question

I have a secondary system handling user authentication, but I would like to use the user creation code from that system instead of Drupal. I want to redirect the Drupal user creation to the secondary system instead.

I already have my own user creation page, so I don't want to do a form_alter on Drupals user creation, I'd rather just send the user to my creation page instead.

How do I redirect user/register to my code instead of Drupal?

Was it helpful?

Solution

Roling your own user registration and authentication requires a number of steps. I try to eyplain them.

Calling yourmodule_form_user_register_form_alter(&$form, &$form_state, $form_id) would be a good idea. Actually you have to alter only the submission call back and may be the validation call back. You can have a look at the last lines of user_register_form how this is done in drupal core.

To make sure the users can login. It's possible to include an external authentication service. Have a look at user_login_default_validators for this.

What is most important for you, that at the end of the login procedure you have to have a valid drupal user object. I'd recommend to have parallel external and drupal users. Probably do the authentication on your external service but let drupal load the corresponding drupal user once this was successful.

This gives you basic working system. Next steps would be to handle password change and one time password recovery links in a correct way.

OTHER TIPS

This might work:

function yourmodule_menu() {
  $items["user/register"] = array(
    "type" => MENU_CALLBACK,
    "page callback" => "yourmodule_user_register_override"
  );
  return $items;
}

function yourmodule_user_register_override() {
  drupal_goto("path/to/your/custom/registration/form");
}

Also, you can create a preprocess function in your theme's template.php file like this:

function YOURTHEME_preprocess_page(&$vars) {
  if(arg(0) == "user" && arg(1) == "register") {
    drupal_goto("path/to/your/custom/registration/form");
  }
}

Or, as @BetaRide said:

function yourmodule_form_user_register_form_alter(&$form, &$form_state, $form_id) {
  $form["#action"] = "path/to/your/custom/registration/form";
}
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top