public function testGetUserByCommunicationKey() { $csid = InstructionControl::getChannelSetId(genSaneGuid()); $u = InstructionControl::getUser(null, $n); $u = InstructionControl::getUser($u['login_key'], $n); InstructionControl::setUserChannelset($u['id'], $csid); $v = InstructionControl::getUserByCommunicationKey($csid, $u['communication_key']); $this->assertEquals($u, $v); $w = InstructionControl::getUserByCommunicationKey($csid, genSaneGuid()); $this->assertNull($w); }
/** * Does a HTTP 303 redirect to the InstructionControl URL with a unique * channelset name appeneded. */ public function restRedirect($params) { header('HTTP/1.1 303 See Other'); $url = INSTRUCTIONCONTROL__BASEURL . INSTRUCTIONCONTROL__PHP_URL; $url .= '/' . genSaneGuid(); header('Location: ' . $url); }
/** * Gets a User. * * If $loginKey is null a new User will be created, if it is not, it will try * and load that User. * * @param string $loginKey A Key which the User may have for loading himself. * @param string $knownAs If supplied this could be displayed in the * browser, it will be stored in the database. * @return array Associative array containing user information. * @throws InstructionControl_Exception should we fail loading a User. */ public static function getUser($loginKey = null, $knownAs = null) { // Make sure we have a User if ($loginKey) { // If we can just load it do so, $user = self::loadUser($loginKey, $knownAs); } else { // otherwise we need to create a new record $loginKey = genSaneGuid(); $communicationKey = genSaneGuid(); $insertData = array('login_key' => $loginKey, 'communication_key' => $communicationKey, 'known_as' => $knownAs); $id = self::getDbFunctionsInstance()->pdoInsert(' insert into user (login_key,communication_key,known_as) values (:login_key,:communication_key,:known_as) ', $insertData); $user = array_merge(array('id' => $id), $insertData); } // If known_as is different from what was passed in, sync it if ($knownAs && $user['known_as'] != $knownAs) { $stmt = InstructionControl::getDbFunctionsInstance()->pdoUpdate(' update user set known_as = :ka where id = :id ', array('ka' => $knownAs, 'id' => $user['id'])); $stmt->execute(); $user['known_as'] = $knownAs; } return $user; }