You are here

function janrain_capture_admin_signin in Janrain Registration 7.4

Same name and namespace in other branches
  1. 7.2 includes/janrain_capture.endpoints.inc \janrain_capture_admin_signin()

Callback to show a Drupal login block to verify that a user is an admin

1 string reference to 'janrain_capture_admin_signin'
janrain_capture_menu in ./janrain_capture.module
Implements hook_menu().

File

includes/janrain_capture.endpoints.inc, line 262
User page callbacks for the janrain_capture module.

Code

function janrain_capture_admin_signin() {
  global $user;
  if (user_is_logged_in()) {
    $api = new JanrainCaptureApi();
    $profile = $api
      ->loadUserEntity();
    if (in_array('administrator', $user->roles) && $profile['result']['email'] == $user->mail) {

      // Add Capture data to the local account
      janrain_capture_sync_account($user, $profile['result']);
      $user = user_save($user);
      module_invoke_all('janrain_capture_user_authenticated', $profile['result'], $user, FALSE);
      drupal_get_messages(NULL, TRUE);
      drupal_set_message(t('Success! Your Drupal account has been associated with Capture.'), 'status');
      drupal_goto();
    }
    else {
      $tmp = NULL;
      session_destroy();
      user_module_invoke('logout', $tmp, $user);
      $user = drupal_anonymous_user();
      drupal_set_message(t('The user account must match the user that was logged in using Capture. Please sign into Capture again.'), 'error');
      drupal_goto();
    }
  }
  else {
    drupal_set_message(t('A Drupal administrator account already exists with this email address. Please sign in using your Drupal username and password to associate this account with Capture.'), 'warning');
    $form = drupal_get_form('user_login_block');
    return $form;
  }
}