From: Artem Daniliants Date: Fri, 5 Mar 2010 13:26:07 +0000 (+0200) Subject: Started working on registration functionality X-Git-Tag: v0.1~76 X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=commitdiff_plain;h=8062481f7ee26d12aeed313ce860b1d471b4491f Started working on registration functionality --- diff --git a/Server/application/controllers/api.php b/Server/application/controllers/api.php index 1f2b037..1e6ca37 100644 --- a/Server/application/controllers/api.php +++ b/Server/application/controllers/api.php @@ -3,7 +3,7 @@ * API controller for communicating with mobile clients * * @author Artem Daniliants - * @copyright (c) 2010 Speed Freak team + * @copyright (c) 2010 Speed Freak team * @license http://opensource.org/licenses/gpl-license.php GNU Public License */ diff --git a/Server/application/models/user.php b/Server/application/models/user.php new file mode 100644 index 0000000..c79ac28 --- /dev/null +++ b/Server/application/models/user.php @@ -0,0 +1,53 @@ + + * @copyright (c) 2010 Speed Freak team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + */ + +class User_Model extends Model { + + /* + * Initialize class and register user if all parameters are supplied + * + * @param string $username Length 3-12 + * @param string $password Length 6-255 (stored as sha1 hash in database) + * @param string $email Valid email address + * @return bool Returns True if operation was successfull and exception otherwise + */ + public function __construct($username='', $password='', $email=''){ + + // load database library into $this->db + parent::__construct(); + + if (isset($username, $password, $email)){ + if (strlen($username)<3) + throw new Exception('Username too short'); + elseif (strlen($username)>12) + throw new Exception('Username too long'); + elseif (strlen($password)<6) + throw new Exception('Password too short'); + elseif (strlen($username)>255) + throw new Exception('Password too long'); + elseif (valid::email($email) == False) + throw new Exception('Invalid email supplied'); + + $this->register($username, $password, $email); + } + } + + /* + * Register new user + * @param string $username Length 3-12 + * @param string $password Length 6-255 (stored as sha1 hash in database) + * @param string $email Valid email address + * @return bool Returns True if operation was successfull and exception otherwise + */ + private function register($username, $password, $email){ + return $db->query("INSERT into users SET username=?, password=?, email=?", + $username, $password, $email); + } + +} \ No newline at end of file