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 user */ public function createAction() { if (!$this->request->isPost()) { return $this->dispatcher->forward(array("controller" => "users", "action" => "index")); } $user = new Users(); $user->email = $this->request->getPost("email", "email"); $user->full_name = $this->request->getPost("full_name"); $user->image_path = $this->request->getPost("image_path"); $user->password = sha1($this->request->getPost("password")); $user->role = $this->request->getPost("role"); $user->status = $this->request->getPost("status"); $user->organisation_id = $this->request->getPost("organisation_id"); if (!$user->save()) { foreach ($user->getMessages() as $message) { $this->flash->error($message); } return $this->dispatcher->forward(array("namespace" => "PRIME\\Controllers", "controller" => "users", "action" => "index")); } $this->flash->success("User was created successfully"); return $this->dispatcher->forward(array("namespace" => "PRIME\\Controllers", "controller" => "users", "action" => "index")); }