~canonical-isd-hackers/wordpress-teams-integration/trunk

« back to all changes in this revision

Viewing changes to openid-teams.php

Pass user identity and team membership information on the session between the openid callback and the login callback

Show diffs side-by-side

added added

removed removed

Lines of Context:
545
545
 * @param string $identity_url
546
546
 */
547
547
function openid_teams_finish_auth($identity_url) {
548
 
  global $openid_teams;
549
548
  set_include_path(dirname(__FILE__).'/../openid/' . PATH_SEPARATOR .
550
549
                   get_include_path());
551
550
  require_once 'teams-extension.php';
557
556
    $raw_teams    = $teams_resp->getTeams();
558
557
    $endpoint     = $response->endpoint;
559
558
    $openid_teams = get_approved_team_mappings($raw_teams, $endpoint->server_url);
 
559
    $_SESSION['openid_teams'] = $openid_teams;
 
560
    $_SESSION['openid_identity_url'] = $identity_url;
560
561
 
 
562
    # If restricted teams is enabled, check the list against allowed teams
561
563
    if (openid_teams_is_restricted_access_enabled()) {
562
564
      $teams = openid_teams_get_restricted_teams();
563
565
      $teams = array_merge($teams, get_all_local_teams());
579
581
 * @param string $password (Default '')
580
582
 */
581
583
function openid_teams_assign_on_login($username, $password='') {
582
 
  global $openid_teams;
583
 
  $user = restore_old_roles(new WP_User($username));
584
 
  if ($openid_teams) {
585
 
    $existing_roles = array_keys($user->caps);
586
 
    $openid_assigned_roles = array();
587
 
    $all_teams = openid_teams_get_trust_list();
588
 
    foreach ($openid_teams as $id) {
589
 
      $role = $all_teams[$id]->role;
590
 
      if (!in_array($role, $existing_roles) && !isset($user->caps[$role])) {
591
 
        $user->add_role($role);
592
 
        $openid_assigned_roles[] = $role;
 
584
  session_start();
 
585
  $identity_url = $_SESSION['openid_identity_url'];
 
586
  if (is_numeric($identity_url)) {
 
587
    $user_id = $identity_url;
 
588
  } else {
 
589
    $user_id = get_user_by_openid($identity_url);
 
590
  }
 
591
  $openid_teams = $_SESSION['openid_teams'];
 
592
  if ($user_id) {
 
593
    $user = new WP_User($user_id);
 
594
    $user = restore_old_roles($user);
 
595
      if ($user && $openid_teams) {
 
596
        $existing_roles = array_keys($user->caps);
 
597
        $openid_assigned_roles = array();
 
598
        $all_teams = openid_teams_get_trust_list();
 
599
        foreach ($openid_teams as $id) {
 
600
          $role = $all_teams[$id]->role;
 
601
          if (!in_array($role, $existing_roles) && !isset($user->caps[$role])) {
 
602
            $user->add_role($role);
 
603
            $openid_assigned_roles[] = $role;
 
604
          }
 
605
        }
 
606
        update_usermeta($user->ID, 'openid_assigned_roles', $openid_assigned_roles);
593
607
      }
594
 
    }
595
 
    update_usermeta($user->ID, 'openid_assigned_roles', $openid_assigned_roles);
596
608
  }
597
609
}
598
610