public function registerAction()
 {
     $request = $this->request;
     if ($request->isPost()) {
         $full_name = $request->getPost('firstname', array('string', 'striptags')) . " " . $request->getPost('lastname', array('string', 'striptags'));
         $organisation_name = $request->getPost('organisation_name', array('string', 'striptags'));
         $email = $request->getPost('email', 'email');
         $password = $request->getPost('password');
         $repeat_password = $this->request->getPost('password2');
         if ($password != $repeat_password) {
             $this->flash->error("Passwords don't match");
             return $this->forward('session/register');
         }
         $organisation = new Organisation();
         $organisation->name = $organisation_name;
         $organisation->theme = 'make';
         if ($organisation->save() == true) {
             $config = new \Phalcon\Config\Adapter\Ini('/../app/config/config.ini');
             $database = new OrgDatabase();
             $database->db_host = $config->database->host;
             $database->db_username = "******" . $organisation_name;
             $database->db_password = sha1($password);
             $database->db_name = "db_" . $organisation_name;
             $database->organisation_id = $organisation->id;
             $user = new Users();
             $user->password = sha1($password);
             $user->full_name = $full_name;
             $user->role = 'Admin';
             $user->email = $email;
             $user->created_at = new \Phalcon\Db\RawValue('now()');
             $user->status = 'disable';
             $user->organisation_id = $organisation->id;
             if ($user->save() == false) {
                 foreach ($user->getMessages() as $message) {
                     $this->flash->error((string) $message);
                 }
             } else {
                 if ($database->save() == false) {
                     foreach ($database->getMessages() as $message) {
                         $this->flash->error((string) $message);
                     }
                 } else {
                     //Read the configuration
                     $host = $config->database->host;
                     $root = $config->database->username;
                     $root_password = $config->database->password;
                     $user = "******" . $organisation_name;
                     $pass = sha1($password);
                     $db = "db_" . $organisation_name;
                     Tag::setDefault('email', '');
                     Tag::setDefault('password', '');
                     $this->flash->success('Thanks for signing up for a new PRIME Dashboard, our consultants will contact you soon.');
                     return $this->forward('session/index');
                 }
             }
         } else {
             foreach ($organisation->getMessages() as $message) {
                 $this->flash->error((string) $message);
             }
         }
     }
 }
 /**
  * Creates a new organisation
  */
 public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "organisation", "action" => "index"));
     }
     $organisation = new Organisation();
     $organisation->id = $this->request->getPost("id");
     $organisation->name = $this->request->getPost("name");
     $organisation->image_path = $this->request->getPost("image_path");
     if (!$organisation->save()) {
         foreach ($organisation->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "organisation", "action" => "new"));
     }
     $this->flash->success("organisation was created successfully");
     return $this->dispatcher->forward(array("controller" => "organisation", "action" => "index"));
 }