Let's clean up our signup code by creating a public function, called signup
, inside the User
class.
1. Open
classes/user.php
, and create apublic
function for signup.public function signup($username,$password) { }
2. Enter the code to match the code below. It's almost identical to the code that we entered in the last section, except that instead of referencing
$user
, we are referencing$this
. You'll also notice thatfull_name
andemail
aren't located in this function; you'll see them in just a second.public function signup($username, $password) { $bones = new Bones(); $bones->couch->setDatabase('_users'); $bones->couch->login(ADMIN_USER, ADMIN_PASSWORD); $this->roles = array(); $this->name = preg_replace('/[^a-z0-9-]/', '', strtolower($username)); $this->_id = 'org.couchdb.user:' . $this->name; $this->salt = $bones->couch->generateIDs(1)->body->uuids[0]; $this->password_sha = sha1($password . $this...