private function action($form) { $u = new User(); $u->username = strtolower($form->email); $u->screenname = $form->screenname; $u->password = $form->password; $u->lastLogin = time(); $u->isValid = false; $u->columns['bitmap_normal']->value = User::kProfileDefaultNormal; $u->columns['bitmap_bigger']->value = User::kProfileDefaultBigger; $u->save(); //echo $u->bitmap_normal; //exit; //$session = Application::session(); //$session->regenerate(true); //$session->id = $u->id; //$session->screenname = $u->screenname; //$session->isAuthenticated = true; $session = session_currentSession(); session_regenerateCurrentSession(); session_setValueForKey($u->id, 'id'); session_setValueForKey($u->screenname, 'screenname'); session_setValueForKey(true, 'isAuthenticated'); // generate a random key for the user to authenticate against: $stream = fopen('/dev/random', 'r'); $bytes = fread($stream, 512); fclose($stream); $key = hash('md5', base64_encode($bytes)); $authorized = array('type' => 'authorization', 'user' => $u->id, 'key' => $key); $db = new CouchDB(array('database' => Configuration::kDatabaseName)); $db->put(json_encode($authorized)); $email = array(); $email['recipients'][] = $u->username; $email['key'] = $key; email_sendAccountCreate($email); header('location:/'); }
* PURPOSE. See the License for the specific language governing permissions and * limitations under the License. * * Author: Adam Venturella - aventurella@gmail.com * * @package Sample * @author Adam Venturella <*****@*****.**> * @copyright Copyright (C) 2009 Adam Venturella * @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0 * **/ /** * Sample */ require 'couchdb/CouchDB.php'; $newdb = 'newdb'; $options = array('database' => $newdb); $db = new CouchDB($options); // Document as JSON: $json = json_encode(array('data' => 'hello world')); $result = $db->put($json); // OR As an Object $document = new stdClass(); $document->data = 'Hello World!'; $db->put($document); // OR As an Array: $document = array(); $document['data'] = 'Hello World!!'; $db->put($document); // the newly created document id echo $result['id'];
/** * @expectedException Exception */ public function testDocumentPutWithNoDatabaseOption() { $document = new stdClass(); $document->label = 'Test0'; $document->type = CouchDBTestConstants::kDefaultType; $document->creationDate = date('c', time()); $couchdb = new CouchDB(); $couchdb->put($document); }
* * Author: Adam Venturella - aventurella@gmail.com * * @package Sample * @author Adam Venturella <*****@*****.**> * @copyright Copyright (C) 2009 Adam Venturella * @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0 * **/ /** * Sample */ require 'couchdb/CouchDB.php'; $newdb = 'newdb'; $options = array('database' => $newdb); $db = new CouchDB($options); $document_id = 'target_documnet_id'; // Get an existing document $document = $db->document($document_id); echo '<h2>BEFORE</h2>'; echo '<pre>', print_r($document, true), '</pre>'; // Add a new value $document['screenname'] = 'lipsum'; // As JSON $json = json_encode($document); $db->put($json, $document_id); // OR As Array: //$db->put($document, $document_id); // Get the document again to show it changed echo '<h2>AFTER</h2>'; echo '<pre>', print_r($db->document($document_id), true), '</pre>';