From efbdc3bbd6cba8691391ec2192ea96adbfb8c029 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Wed, 19 Mar 2014 22:45:31 +0100 Subject: Initial commit --- autoload/Todo/Model/User.php | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 autoload/Todo/Model/User.php (limited to 'autoload/Todo/Model/User.php') diff --git a/autoload/Todo/Model/User.php b/autoload/Todo/Model/User.php new file mode 100644 index 0000000..53c8f67 --- /dev/null +++ b/autoload/Todo/Model/User.php @@ -0,0 +1,66 @@ +code = ''; + for($i = 0; $i < 16; $i++) { + $this->code .= substr($alphabet, mt_rand(0, $len-1), 1); + } + } + + public function register($name, $email, $password) { + $this->load(array('name=? OR email=?', $name, $email)); + if(!$this->dry()) { + $this->reset(); + return false; + } + + $this->name = $name; + $this->email = $email; + $this->pwhash = \Bcrypt::instance()->hash($password); + $this->active = false; + $this->makeCode(); + $this->save(); + return true; + } + + public function byName($name) { + $this->load(array('name=?', $name)); + return !$this->dry(); + } + + public function byID($id) { + $this->load(array('id=?', $id)); + return !$this->dry(); + } + + public function byEmail($email) { + $this->load(array('email=?', $email)); + return !$this->dry(); + } + + public function verifyPass($password) { + return \Bcrypt::instance()->verify($password, $this->pwhash); + } + + public function deleteUser() { + $this->db->exec('DELETE FROM `items` WHERE `list` IN (SELECT `id` FROM `lists` WHERE `user` = :u)', array(':u' => $this->id)); + $this->db->exec('DELETE FROM `lists` WHERE `user` = :u', array(':u' => $this->id)); + $this->erase(); + } + + # Returns a TodoList object that can be iterated with ->next(). + public function lists() { + $l = new \Todo\Model\TodoList($this->db); + $l->load(array('user=?', $this->id), array('order' => 'name ASC')); + return $l; + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2