'Form Component', 'description' => 'No description provided yet...', ]; } /** * Returns the properties provided by the component. */ public function defineProperties() { return []; } public function onRun(): void { $groups = Cache::remember('oc_groupsa', 1, function () { return $this->getGroups(); }); $this->groups = collect($groups) ->filter(fn ($g) => !in_array($g, Settings::get('force_groups'))) ->filter(fn ($g) => !in_array($g, Settings::get('disallowed_groups'))) ->map(fn ($group) => ['id' => $group, 'name' => $group]) ->toArray(); } public function onSubmit() { $rules = [ 'firstname' => 'required|string|max:255', 'lastname' => 'required|string|max:255', 'username' => ['required', 'string', 'max:255', 'regex:/^[a-zA-Z0-9]+$/', Rule::notIn($this->getUsers())], 'email' => 'required|email|string|max:255', 'group' => 'required|string|max:255', 'function' => 'required|string|max:255', 'oc_groups' => 'present|array', 'oc_groups.*' => 'string', ]; $validator = Validator::make(Input::all(), $rules, [ 'username.not_in' => 'OwnCloud Nutzername wird bereits verwendet.', 'username.regex' => 'OwnCloud Nutzername darf nur aus Buchstaben und Zahlen bestehen', ], Lang::get('zoomyboy.owncloud::validation.attributes')); if ($validator->fails()) { return response()->json($validator->errors(), 422); } $payload = base64_encode(json_encode($validator->validated())); Mail::send('owncloud_request', [ 'link' => url('/owncloud-confirm/'.$payload), 'payload' => $validator->validated(), ], function ($message) { foreach (Settings::get('admins') as $admin) { $message->to($admin); } }); dd('I'); return response()->json([], 201); } private function getGroups(): array { $response = $this->getClient()->get('/ocs/v1.php/cloud/groups'); $r = []; $xml = simplexml_load_string((string) $response->getBody()); foreach ($xml->xpath('/ocs/data/groups/element') as $element) { $r[] = (string) $element; } return $r; } private function getUsers(): array { $response = $this->getClient()->get('/ocs/v1.php/cloud/users'); $r = []; $xml = simplexml_load_string((string) $response->getBody()); foreach ($xml->xpath('/ocs/data/users/element') as $element) { $r[] = (string) $element; } return $r; } private function getClient(): Client { $auth = base64_encode(Settings::get('username').':'.Settings::get('password')); return new Client(['base_uri' => Settings::get('url'), 'headers' => ['Authorization' => 'Basic '.$auth]]); } }