示例#1
0
 /**
  * Add user
  * @param $result
  * @return mixed
  */
 public function addUser($result)
 {
     $jsonval = new JsonValidate($this->data, '{"username":"", "pass":"", "admin":1}');
     if (($errors = $jsonval->validate()) !== true) {
         $result['error'] = $errors;
         return $result;
     }
     // check for duplicate username
     $authMdl = new AuthModel();
     if (sizeof($authMdl->get(0, 0, null, $this->data->username)) > 0) {
         $result['error'] = "The username specified is already taken";
         return $result;
     }
     // insert entry if the user is admin, preset all permissions
     $qresult = $authMdl->create($this->data->username, $this->data->pass, $this->data->admin, $this->data->admin == 1 ? json_encode($this->defaultAdminPermissions) : json_encode($this->defaultPermissions));
     if ($qresult === false) {
         $result['error'] = "Could not add the user";
     } else {
         $result['data'] = true;
         // log data
         unset($this->data->pass);
         Logger::write("User added with id:" . $this->data->id, "USER", json_encode($this->data));
     }
     return $result;
 }