1 <?php defined('SYSPATH') or die('No direct script access.');
3 * API controller for communicating with mobile clients
5 * @author Artem Daniliants <artem@daniliants.com>
6 * @copyright (c) 2010 Speed Freak team
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 class User_Model extends Model {
13 * Initialize class and register user if all parameters are supplied
15 * @param string $username Length 3-12
16 * @param string $password Length 6-255 (stored as sha1 hash in database)
17 * @param string $email Valid email address
18 * @return bool Returns True if operation was successfull and exception otherwise
20 public function __construct($username='', $password='', $email=''){
22 // load database library into $this->db
23 parent::__construct();
25 if (isset($username, $password, $email)){
26 if (strlen($username)<3)
27 throw new Exception('Username too short');
28 elseif (strlen($username)>12)
29 throw new Exception('Username too long');
30 elseif (strlen($password)<6)
31 throw new Exception('Password too short');
32 elseif (strlen($username)>255)
33 throw new Exception('Password too long');
34 elseif (valid::email($email) == False)
35 throw new Exception('Invalid email supplied');
37 $this->register($username, $password, $email);
43 * @param string $username Length 3-12
44 * @param string $password Length 6-255 (stored as sha1 hash in database)
45 * @param string $email Valid email address
46 * @return bool Returns True if operation was successfull and exception otherwise
48 private function register($username, $password, $email){
49 return $db->query("INSERT into users SET username=?, password=?, email=?",
50 $username, $password, $email);