public function authenticate() { $this->errorCode = self::ERROR_NONE; $authenticated = false; $username = $this->username; $password = $this->password; $user = null; try { Yii::app()->db; $dbload = true; } catch (Exception $e) { # If Connection doesn't exist $dbload = false; } # Check if user exists or is locked out if ($dbload) { $user = new UserObj($username); if ($user->loaded and isset($user->active, $user->attempts) and ($user->active == 0 or $user->attempts > 5)) { $this->errorCode = ERROR_MAX_ATTEMPTS; return !$this->errorCode; } } # The new Authentication System $adauth = new ADAuth("adcontroller"); # Authenticate! if ($adauth->authenticate($username, $password)) { # !Important! User groups and their permission levels $valid_groups = array("ASSETT-Programming" => 10, "ASSETT-Admins" => 10, "ASSETT-TTAs" => 3, "ASSETT-Core" => 3, "ASSETT-Staff" => 3, "ASSETT-ATCs" => 3, "ASSETT-Design" => 3); # Empty for now $info = $adauth->lookup_user(); # Iterate through groups and assign user to appropriate groups foreach ($valid_groups as $group => $permlevel) { if ($adauth->is_member($group)) { // Update only if membership changed or new user if ($dbload === true and !is_null($user) and (!$user->loaded or $user->loaded and $user->member != $group)) { $user->permission = $permlevel; $user->member = $group; } else { if ($dbload === false and (!isset($permission) or $permlevel > $permission)) { $permission = $permlevel; $belongsto = $group; } } break; } } if ($dbload === false) { if (!isset($permission)) { $this->errorCode = ERROR_AUTH_GROUP_INVALID; return !$this->errorCode; } Yii::app()->user->setState("group", $belongsto); Yii::app()->user->setState("permission", $permission); } else { if (is_null($user->permission) and !$user->loaded) { $user->permission = 1; } $user->email = $info[0]["mail"][0]; $user->name = $info[0]["displayname"][0]; if ($user->permission == 0) { $this->errorCode = ERROR_AUTH_GROUP_INVALID; } if (!$this->errorCode) { $user->last_login = date("Y-m-d H:i:s"); $user->attempts = 0; $user->save(); $user->load(); } # Switch to the directory and lookup user's CU affiliation (student/staff/faculty) $adauth->change_controller("directory"); $info = $adauth->lookup_user(); $user->roles = $this->parse_roles($info[0]["edupersonaffiliation"]); # Save and reload $user->save(); $user->load(); $contact = new ContactObj(); $contact->username = $user->username; $contact->load(); if ($contact->loaded) { Yii::app()->user->setState("cid", $contact->cid); Yii::app()->user->setState("userobj", $user); } } } else { if ($dbload === true and $user->loaded) { $user->attempts++; $user->save(); } $this->errorCode = ERROR_INVALID_CREDENTIALS; } return !$this->errorCode; }
public function action_add_contact_name() { $this->noGuest(); $contact = new ContactObj(); $newname = $_REQUEST["firstname"] . " " . $_REQUEST["lastname"]; $contact->firstname = $_REQUEST["firstname"]; $contact->lastname = $_REQUEST["lastname"]; $log = new LogObj(); $contact->load(); if ($contact->loaded) { return print $contact->cid; } if (!$contact->save()) { $log->type = "error"; $log->log_message = "Attempting to create new contact \"{$newname}\".\n"; $log->log_message .= $contact->get_error(); if (!$log->save()) { die($log->get_error()); } return print $log->log_message; } $log->type = "insert"; $log->log_message = "Successfully created new contact \"{$newname}\"."; $log->save(); return print 1; }
function get_all_tags() { $tlc1 = new ContactObj(); $tlc1->fullname = "Amanda McAndrew"; $tlc1->load(); $tlc2 = new ContactObj(); $tlc2->fullname = "Nigora Azimova"; $tlc2->load(); $tlc3 = new ContactObj(); $tlc3->fullname = "Jacie Moriyama"; $tlc3->load(); $tlc3 = new ContactObj(); $tlc3->fullname = "Jacie Moriyama"; $tlc3->load(); $tlcs[] = $tlc1; $tlcs[] = $tlc2; $tlcs[] = $tlc3; $interactions = $tlc1->get_interactions(); $interactions = array_merge($interactions, $tlc2->get_interactions()); $interactions = array_merge($interactions, $tlc3->get_interactions()); $depts = array(); $conn = Yii::app()->db; foreach ($interactions as $index => $interaction) { if (strtotime($interaction->meetingdate) < strtotime("January 1st, 2014")) { unset($interactions[$index]); } foreach (explode(", ", $interaction->tags) as $tag) { $tags[] = $tag; } } $tags = array_unique($tags); foreach ($tags as $tag) { $query = "\n SELECT attendees\n FROM interactions\n WHERE tags LIKE :tag\n "; $command = $conn->createCommand($query); $command->bindValue(":tag", "%" . $tag . "%"); $result = $command->queryAll(); $names = array(); $depts = array(); $rowinfo = array(); foreach ($result as $row) { $attendees = json_decode($row["attendees"]); # Remove the TLCs foreach ($tlcs as $tlc) { if ($key = array_search($tlc->cid, $attendees) !== false) { unset($attendees[$key]); } } foreach ($attendees as $attendee) { $query = "\n SELECT B.deptname, A.fullname\n FROM contacts as A, departments as B\n WHERE A.cid = :cid\n AND B.deptid = (SELECT deptid FROM contact_departments WHERE cid = :cid LIMIT 1);\n "; $command = $conn->createCommand($query); $command->bindParam(":cid", $attendee); $result = $command->queryRow(); if (!in_array($result["fullname"], $names)) { if ($result["fullname"] != "") { $names[] = $result["fullname"]; $rowinfo[] = $result["fullname"]; } if ($result["deptname"] != "") { $rowinfo[] = $result["deptname"]; $depts[] = $result["deptname"]; } } } } $output[$tag] = array("tag" => $tag, "numcontacts" => count($names), "numdepts" => count($depts)); $output[$tag] = array_merge($output[$tag], $rowinfo); } return $output; }