68 lines
1.7 KiB
PHP
68 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Zoomyboy\Owncloud\Components;
|
|
|
|
use Cms\Classes\ComponentBase;
|
|
use GuzzleHttp\Client;
|
|
use Mail;
|
|
use Zoomyboy\Owncloud\Models\Settings;
|
|
|
|
class Confirm extends ComponentBase
|
|
{
|
|
/**
|
|
* Gets the details for the component.
|
|
*/
|
|
public function componentDetails()
|
|
{
|
|
return [
|
|
'name' => 'Confirm Component',
|
|
'description' => 'No description provided yet...',
|
|
];
|
|
}
|
|
|
|
public function onRun(): void
|
|
{
|
|
$b = base64_decode($this->property('payload'));
|
|
|
|
if (!$b) {
|
|
return;
|
|
}
|
|
|
|
$b = json_decode($b, true);
|
|
|
|
if (!$b) {
|
|
return;
|
|
}
|
|
|
|
$password = str_random(32);
|
|
$auth = base64_encode(Settings::get('username').':'.Settings::get('password'));
|
|
$client = new Client(['base_uri' => Settings::get('url'), 'headers' => ['Authorization' => 'Basic '.$auth, 'Content-Type' => 'application/x-www-form-urlencoded']]);
|
|
$client->post('/ocs/v1.php/cloud/users', [
|
|
'form_params' => [
|
|
'groups' => array_merge($b['oc_groups'], Settings::get('force_groups')),
|
|
'userid' => $b['username'],
|
|
'password' => $password,
|
|
],
|
|
]);
|
|
|
|
Mail::send('owncloud_confirm', [
|
|
'password' => $password,
|
|
'payload' => $b,
|
|
], function ($message) use ($b) {
|
|
$message->to($b['email'], $b['firstname'].' '.$b['lastname']);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Returns the properties provided by the component.
|
|
*/
|
|
public function defineProperties()
|
|
{
|
|
return [
|
|
'payload' => [
|
|
'label' => 'Payload',
|
|
],
|
|
];
|
|
}
|
|
}
|