You are here

function auth0_form_user_profile_form_alter in Auth0 Single Sign On 7.2

Implements hook_user_form_user_profile_form_alter().

Disable email and password fields for users who have logged in with Auth0.

File

./auth0.module, line 911

Code

function auth0_form_user_profile_form_alter(&$form, $form_state) {
  $user = $form_state['user'];
  if ($object = auth0_get_auth0_object_from_drupal_uid($user->uid)) {

    // If the user has an Auth0 profile then we simply disable the password/email fields.
    // If this account was created without an email address hide the field,
    // otherwise show it but disable it.
    if ($user->mail) {
      $form['account']['mail']['#disabled'] = TRUE;
    }
    else {
      $form['account']['mail']['#access'] = FALSE;
    }

    // Remove the password field.
    $form['account']['pass']['#access'] = FALSE;

    // If there is no way to edit the mail/pass then we don't need the current pass f
    if (isset($form['account']['current_pass'])) {
      $form['account']['current_pass']['#access'] = FALSE;
    }

    // @TODO: Reenable the password/email editing ability if the connection providor is Auth0
    // This will require using the API to update the info in Auth0
  }
}