public applyLdapGroups ( $groups ) | ||
$groups |
public function applyLdapGroups($groups)
{
// get current teams
$currentTeamIds = array();
foreach ($this->getTeams() as $t) {
$currentTeamIds[$t['id']] = $t['name'];
}
if (count($groups)) {
// create all links between LDAP user and teams ( == LDAP group)
$groups[] = $this->getAccountId();
$teams = $this->db->GetCol("\n SELECT id FROM account_teams\n WHERE name IN(" . join(',', array_fill(0, count($groups) - 1, '?')) . ") AND account_id = ?\n ", $groups);
//Team exists in DB, so we can save link
foreach ($teams as $id) {
$team = new Scalr_Account_Team();
$team->loadById($id);
if (!$team->isTeamUser($this->id)) {
$team->addUser($this->id);
}
unset($currentTeamIds[$id]);
}
}
//Remove old teams
foreach ($currentTeamIds as $id => $name) {
$team = new Scalr_Account_Team();
$team->loadById($id);
$team->removeUser($this->id);
}
}
/** * @param Scalr_Account_User $user * @param bool $keepSession */ private function loginUserCreate($user, $keepSession) { $user->updateLastLogin(); Scalr_Session::create($user->getId()); if (Scalr::config('scalr.auth_mode') == 'ldap') { $user->applyLdapGroups($this->ldapGroups); } else { if ($keepSession) { Scalr_Session::keepSession(); } } $this->response->data(array('userId' => $user->getId(), 'specialToken' => Scalr_Session::getInstance()->getToken())); }