Started working on registration functionality
authorArtem Daniliants <artem@daniliants.com>
Fri, 5 Mar 2010 13:26:07 +0000 (15:26 +0200)
committerArtem Daniliants <artem@daniliants.com>
Fri, 5 Mar 2010 13:26:07 +0000 (15:26 +0200)
Server/application/controllers/api.php
Server/application/models/user.php [new file with mode: 0644]

index 1f2b037..1e6ca37 100644 (file)
@@ -3,7 +3,7 @@
  * API controller for communicating with mobile clients
  * 
  * @author      Artem Daniliants <artem@daniliants.com>
- * @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 (file)
index 0000000..c79ac28
--- /dev/null
@@ -0,0 +1,53 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+/*
+ * API controller for communicating with mobile clients
+ * 
+ * @author      Artem Daniliants <artem@daniliants.com>
+ * @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