/** * * Whenever you need to create a connection file, * Just insert data and call this function * in any method you want * * @param string $host - The Host Name * @param string $user - The Database User Name * @param string $password - The User Password * @param string $database - The Database Name */ public function generateConnectionFile($name, $host, $user, $password, $database) { $data = array('host' => $host, 'user' => $user, 'pass' => $password, 'db' => $database); $data = json_encode($data); $data = CR::encrypt($data); file_put_contents(MODELDIR . '/' . md5($name), $data); }
/** * POST Method to create new user */ public function postAddUser() { $post = $this->getPost(); if (!$this->validatePost('name', 'user', 'pass')) { return RestServer::throwError(Language::CANNOT_BE_BLANK('Name, User and Pass'), 400); } $userData = array('name' => $post['name'], 'username' => $post['user'], 'passwd' => CR::encrypt($post['pass']), 'email' => $post['email']); $this->newModel('auth'); $this->model('auth')->insertUser($userData); if (!$this->model('auth')->queryOk()) { if ($this->model('auth')->getErrorCode() == 23000) { return RestServer::throwError(Language::USER_ALREADY_TAKEN(), 400); } else { return RestServer::throwError(Language::QUERY_ERROR(), 500); } } return RestServer::response(array('status' => 200, 'uid' => $this->model('auth')->getLastInsertId(), 'message' => 'User created!'), 200); }