function addSubscription($params) { if (!isset($params['uid'])) { return FALSE; } if (!isset($params['subscription'])) { return FALSE; } // only the user herself can make a new subscription if ($params['uid'] != $params['__uid']) { echo json_encode(array('status' => 'permission_denied')); exit; } $pm = new sspmod_janus_Postman(); $return = $pm->subscribe($params['uid'], $params['subscription']); if ($return === false) { return array('status' => 'User is already subscribing to that address'); } return array('sid' => $return); }
} } } } if (isset($_POST['submit'])) { if (!empty($_POST['entityid'])) { if (check_uri($_POST['entityid'])) { if (!isset($_POST['entityid']) || empty($_POST['entitytype'])) { $msg = 'error_no_type'; $old_entityid = $_POST['entityid']; $old_entitytype = $_POST['entitytype']; } else { $msg = $mcontrol->createNewEntity($_POST['entityid'], $_POST['entitytype']); if (is_int($msg)) { $entity = new sspmod_janus_Entity($janus_config); $pm->subscribe($user->getUid(), 'ENTITYUPDATE-' . $msg); $directlink = SimpleSAML_Module::getModuleURL('janus/editentity.php', array('eid' => $msg)); $pm->post('New entity created', 'Permalink: <a href="' . $directlink . '">' . $directlink . '</a><br /><br />A new entity has been created.<br />Entityid: ' . $_POST['entityid'] . '<br />Entity type: ' . $_POST['entitytype'], 'ENTITYCREATE', $user->getUid()); SimpleSAML_Utilities::redirect(SimpleSAML_Module::getModuleURL('janus/editentity.php'), array('eid' => $msg)); } } } else { $msg = 'error_entity_not_url'; $old_entityid = $_POST['entityid']; $old_entitytype = $_POST['entitytype']; } } else { if (!empty($_POST['metadata_xml'])) { $doc = new DOMDocument(); $doc->loadXML($_POST['metadata_xml']); $xpath = new DOMXPath($doc);
/** * Saves the user data to the database. * * Method for saving the user data to the database. If the user data has not * been modified the methos just returns true. If an error occures and the * data is not saved the method returns false. * * @return bool true if data is saved end false if data is not saved. * @todo Clean up * @todo Remove exceptions, return true/false */ public function save() { // If the user is not modified, just return if (!$this->_modified) { return true; } // uid is empty. This is a new user if (empty($this->_uid)) { // Test if email address already exists $st = $this->execute('SELECT count(*) AS `count` FROM ' . self::$prefix . 'user WHERE `userid` = ?;', array($this->_userid)); if ($st === false) { throw new SimpleSAML_Error_Exception('JANUS:User:save - Error executing statement : ' . self::formatError($st->errorInfo())); } $row = $st->fetchAll(PDO::FETCH_ASSOC); if ($row[0]['count'] > 0) { return false; } // Create new User $st = $this->execute('INSERT INTO ' . self::$prefix . 'user (`uid`, `userid`, `type`, `email`, `active`, `update`, `created`, `ip`) VALUES (null, ?, ?, ?, ?, ?, ?, ?)', array($this->_userid, serialize($this->_type), $this->_email, $this->_active, date('c'), date('c'), $_SERVER['REMOTE_ADDR'])); // Get new uid $this->_uid = self::$db->lastInsertId(); $pm = new sspmod_janus_Postman(); $pm->subscribe($this->_uid, 'USER-' . $this->_uid); $pm->post('New user created', 'A new user have been created. User ID: ' . $this->_userid . ' Uid: ' . $this->_uid, 'USERCREATE', $this->_uid); unset($pm); } else { // Update existing user $st = $this->execute('UPDATE ' . self::$prefix . 'user set `userid` = ?, `type` = ?, `email` = ?, `active` = ?, `update` = ?, `ip` = ?, `data` = ?, `secret` = ? WHERE `uid` = ?;', array($this->_userid, serialize($this->_type), $this->_email, $this->_active, date('c'), $_SERVER['REMOTE_ADDR'], $this->_data, $this->_secret, $this->_uid)); } if ($st === false) { throw new SimpleSAML_Error_Exception('JANUS:User:save - Error executing statement : ' . self::$db->errorInfo()); } $this->_modified = false; return true; }
/** * Saves the user data to the database. * * Method for saving the user data to the database. If the user data has not * been modified the methos just returns true. If an error occures and the * data is not saved the method returns false. * * @return bool true if data is saved end false if data is not saved. * @throws \Exception */ public function save() { // If the user is not modified, just return if (!$this->_modified) { return true; } $entityManager = $this->getEntityManager(); $this->validateUserTypes($this->_type); // uid is empty. This is a new user if (empty($this->_uid)) { // Test if username already exists $existingUser = $entityManager->getRepository('Janus\\ServiceRegistry\\Entity\\User')->findOneBy(array('username' => $this->_userid)); if ($existingUser instanceof User) { return false; } // Create new user $user = new User($this->_userid, $this->_type, $this->_email, $this->_active === 'yes'); $entityManager->persist($user); $entityManager->flush(); // Get new uid $this->_uid = $user->getId(); $pm = new sspmod_janus_Postman(); $pm->subscribe($this->_uid, 'USER-' . $this->_uid); $pm->post('New user created', 'A new user have been created. User ID: ' . htmlspecialchars($this->_userid) . ' Uid: ' . htmlspecialchars($this->_uid), 'USERCREATE', htmlspecialchars($this->_uid)); unset($pm); } else { // Update existing user $existingUser = $this->getUserService()->findById($this->_uid); if (!$existingUser instanceof User) { throw new \Exception("User '{$this->_uid}' does not exist"); } $existingUser->update($this->_userid, $this->_type, $this->_email, $this->_active === 'yes', $this->_data, $this->_secret); $entityManager->persist($existingUser); $entityManager->flush(); } $this->_modified = false; return true; }
function addSubscription($params) { if (!isset($params['uid'])) { return FALSE; } if (!isset($params['subscription'])) { return FALSE; } $pm = new sspmod_janus_Postman(); $return = $pm->subscribe($params['uid'], $params['subscription']); if ($return === false) { return array('status' => 'User is already subscribing to that address'); } return array('sid' => $return); }