masterzero/nextcloud

library for nextcloud user management

dev-master 2018-06-23 05:41 UTC

This package is not auto-updated.

Last update: 2024-04-14 03:12:23 UTC


README

manage your nextcloud users via laravel

Setup:

  1. Use following command in your terminal to install this library. (Currently the library is in development mode):

    composer require masterzero/nextcloud dev-master

  2. Update the poviders in config/app.php

     'providers' => [
         // ...
         MasterZero\Nextcloud\ApiServiceProvider::class,
     ]
    
  3. Update the aliases in config/app.php

     'aliases' => [
         // ...
         'NextcloudApi' => MasterZero\Nextcloud\Facade\Api::class,
     ]
    
  4. Create config/nextcloud.php with content:

return [
    'login'=> env('NEXTCLOUD_LOGIN', 'admin'),
    'password'=> env('NEXTCLOUD_PASSWORD', '12345678'),
    'baseUrl'=> env('NEXTCLOUD_BASEURL', 'http://localhost'),
];
  1. Add these params to .env (optional):
NEXTCLOUD_LOGIN=admin
NEXTCLOUD_PASSWORD=12345678
NEXTCLOUD_BASEURL=http://localhost

Usage:

create user:

// reqeust to API
$data = NextcloudApi::createUser($username, $password);

// do something with it
if ($data['success']) {

    // do something ...

} else {

    // do something else ...

    echo $data['message'];

}

user list:

// reqeust to API
$data =  NextcloudApi::getUserList();

// do something with it
if ($data['success']) {

    foreach ($data['users'] as $userid) {
        // do something with $userid
    }

} else {
    
    // do something else ...

}

edit user param:

// reqeust to API
$data = NextcloudApi::editUser('rabbit','quota', '200 MB');

if ($data['success']) {

    // do something ...

} else {

    // do something else ...

}

enable/disable user:

// reqeust to API
$data = NextcloudApi::enableUser('bird');
//$data = NextcloudApi::disableUser('turtle');

if ($data['success']) {

    // do something ...

} else {

    // do something else ...

}

exceptions

use MasterZero\Nextcloud\Exceptions\XMLParseException;
use MasterZero\Nextcloud\Exceptions\CurlException;

// ... 

try {
    // reqeust to API
    NextcloudApi::editUser('rabbit','quota', '200 MB');
} catch (XMLParseException $e) {
    // bad nextcloud answer
} catch (CurlException $e) {
    // bad connection
} catch (\Exception $e) {
    // bad something else
}

multi-server usage

use MasterZero\Nextcloud\Api;

// ... 

$api = new Api([
    'baseUrl' => 'http://develop.localhost:3500',
    'login' => 'admin',
    'password' => '12345678',
    'sslVerify' => false,


    // use default value
    // 'apiPath' => 'custom/path/to/api.php', 
    // 'userPath' => '',
    // 'enablePath' => '',
    // 'disablePath' => '',
]);


$api->createUser( 'dummy', 'qwerty');