You are here

function gauth_user_auth_services_enabled in Google Auth 7

Same name and namespace in other branches
  1. 7.2 gauth_user/gauth_user.module \gauth_user_auth_services_enabled()

Function returns the permission or the account types allowed for a user.

1 call to gauth_user_auth_services_enabled()
gauth_user_services_authenticate in gauth_user/gauth_user.pages.inc
Menu callback; Creates authenticate link for end users.
1 string reference to 'gauth_user_auth_services_enabled'
gauth_user_menu in gauth_user/gauth_user.module
Implements hook_menu().

File

gauth_user/gauth_user.module, line 268
Google Auth Api for drupal.

Code

function gauth_user_auth_services_enabled($user, $perm = TRUE, $specific_perm = '') {
  if ($perm) {
    if ($specific_perm) {
      return user_access("authenticate {$specific_perm} gauth services account", $user);
    }
    elseif (user_access('administer users', $GLOBALS['user'])) {
      return TRUE;
    }
    elseif ($user->uid == $GLOBALS['user']->uid) {
      $accounts = gauth_user_services_load();
      foreach ($accounts as $type) {
        if (user_access("authenticate {$type->id} gauth services account", $user)) {
          return TRUE;
        }
      }
    }
    return FALSE;
  }
  else {
    $accounts = gauth_user_services_load();
    $account_types = array();
    foreach ($accounts as $type) {
      if (user_access("authenticate {$type->id} gauth services account", $user)) {
        $account_types[$type->id] = $type;
        if ($gauth_account = gauth_account_load($type->id . '|' . $user->uid)) {
          if ($gauth_account['is_authenticated']) {
            $account_types[$type->id]->is_authenticated = TRUE;
          }
          else {
            $account_types[$type->id]->is_authenticated = FALSE;
          }
          $account_types[$type->id]->id = $gauth_account['id'];
        }
      }
    }
    return $account_types;
  }
}