kopia lustrzana https://github.com/nextcloud/social
OAuth2+test
rodzic
4ee727060a
commit
04972c6118
|
@ -0,0 +1,4 @@
|
|||
|
||||
\.idea/
|
||||
|
||||
vendor/
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\AppInfo;
|
||||
|
||||
require_once __DIR__ . '/autoload.php';
|
||||
require_once(__DIR__ . '/../lib/autoload.php');
|
||||
|
||||
//$app = new Application();
|
||||
//$app->registerNavigation();
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace OCA\Social\AppInfo;
|
||||
|
||||
$composerDir = __DIR__ . '/../vendor/';
|
||||
|
||||
if (is_dir($composerDir) && file_exists($composerDir . 'autoload.php')) {
|
||||
require_once $composerDir . 'autoload.php';
|
||||
}
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<database>
|
||||
<name>*dbname*</name>
|
||||
<create>true</create>
|
||||
<overwrite>false</overwrite>
|
||||
<charset>utf8</charset>
|
||||
|
||||
<table>
|
||||
<name>*dbprefix*social_services</name>
|
||||
<declaration>
|
||||
<field>
|
||||
<name>id</name>
|
||||
<type>integer</type>
|
||||
<length>7</length>
|
||||
<unsigned>true</unsigned>
|
||||
<notnull>true</notnull>
|
||||
<autoincrement>true</autoincrement>
|
||||
<primary>true</primary>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>type</name>
|
||||
<type>text</type>
|
||||
<length>15</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>address</name>
|
||||
<type>text</type>
|
||||
<length>128</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>config</name>
|
||||
<type>text</type>
|
||||
<length>3000</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>status</name>
|
||||
<type>integer</type>
|
||||
<length>1</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>creation</name>
|
||||
<type>timestamp</type>
|
||||
</field>
|
||||
|
||||
</declaration>
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<name>*dbprefix*social_accounts</name>
|
||||
<declaration>
|
||||
|
||||
<field>
|
||||
<name>id</name>
|
||||
<type>integer</type>
|
||||
<length>7</length>
|
||||
<unsigned>true</unsigned>
|
||||
<notnull>true</notnull>
|
||||
<autoincrement>true</autoincrement>
|
||||
<primary>true</primary>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>service_id</name>
|
||||
<type>integer</type>
|
||||
<length>7</length>
|
||||
<notnull>true</notnull>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>user_id</name>
|
||||
<type>text</type>
|
||||
<length>63</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>account</name>
|
||||
<type>text</type>
|
||||
<length>127</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>status</name>
|
||||
<type>integer</type>
|
||||
<length>1</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>auth</name>
|
||||
<type>text</type>
|
||||
<length>2000</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>config</name>
|
||||
<type>text</type>
|
||||
<length>2000</length>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>creation</name>
|
||||
<type>timestamp</type>
|
||||
</field>
|
||||
|
||||
</declaration>
|
||||
</table>
|
||||
|
||||
</database>
|
||||
|
|
@ -1,24 +1,29 @@
|
|||
<?xml version="1.0"?>
|
||||
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
|
||||
<id>social</id>
|
||||
<name>Social</name>
|
||||
<summary>🎉 Nextcloud becomes part of the federated social networks!</summary>
|
||||
<description><![CDATA[test]]></description>
|
||||
<version>0.0.1</version>
|
||||
<licence>agpl</licence>
|
||||
<author mail="jus@bitgrid.net" >Julius Härtl</author>
|
||||
<author mail="hey@jancborchardt.net" homepage="https://jancborchardt.net">Jan-Christoph Borchardt</author>
|
||||
<namespace>Social</namespace>
|
||||
<category>social</category>
|
||||
<bugs>https://github.com/nextcloud/social</bugs>
|
||||
<dependencies>
|
||||
<nextcloud min-version="14" max-version="15"/>
|
||||
</dependencies>
|
||||
<navigations>
|
||||
<navigation>
|
||||
<name>Social</name>
|
||||
<route>social.page.index</route>
|
||||
</navigation>
|
||||
</navigations>
|
||||
<info xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
|
||||
<id>social</id>
|
||||
<name>Social</name>
|
||||
<summary>🎉 Nextcloud becomes part of the federated social networks!</summary>
|
||||
<description><![CDATA[test]]></description>
|
||||
<version>0.0.9</version>
|
||||
<licence>agpl</licence>
|
||||
<author mail="maxence@artificial-owl.com">Maxence Lange</author>
|
||||
<author mail="jus@bitgrid.net">Julius Härtl</author>
|
||||
<author mail="hey@jancborchardt.net" homepage="https://jancborchardt.net">Jan-Christoph Borchardt</author>
|
||||
<namespace>Social</namespace>
|
||||
<category>social</category>
|
||||
<website>https://github.com/nextcloud/social</website>
|
||||
<repository type="git">https://github.com/nextcloud/social.git</repository>
|
||||
<bugs>https://github.com/nextcloud/social/issues</bugs>
|
||||
<screenshot>https://raw.githubusercontent.com/nextcloud/social/master/screenshots/screenshot.png</screenshot>
|
||||
<dependencies>
|
||||
<nextcloud min-version="14" max-version="15"/>
|
||||
</dependencies>
|
||||
<navigations>
|
||||
<navigation>
|
||||
<name>Social</name>
|
||||
<route>social.Navigation.navigate</route>
|
||||
</navigation>
|
||||
</navigations>
|
||||
|
||||
</info>
|
||||
|
|
|
@ -8,8 +8,29 @@
|
|||
* it's instantiated in there
|
||||
*/
|
||||
return [
|
||||
'routes' => [
|
||||
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
|
||||
['name' => 'page#mail', 'url' => '/mail', 'verb' => 'GET'],
|
||||
]
|
||||
'routes' => [
|
||||
['name' => 'Navigation#navigate', 'url' => '/', 'verb' => 'GET'],
|
||||
|
||||
[
|
||||
'name' => 'ServiceAccounts#getAvailableAccounts', 'url' => '/user/accounts',
|
||||
'verb' => 'GET'
|
||||
],
|
||||
[
|
||||
'name' => 'ServiceAccounts#create', 'url' => '/user/account',
|
||||
'verb' => 'POST'
|
||||
],
|
||||
[
|
||||
'name' => 'ActivityStreams#test', 'url' => '/user/account/{accountId}/test',
|
||||
'verb' => 'GET'
|
||||
],
|
||||
|
||||
// [
|
||||
// 'name' => 'OAuth2#getAuthUrl', 'url' => '/client/oauth2/auth/{serviceId}/',
|
||||
// 'verb' => 'GET'
|
||||
// ],
|
||||
[
|
||||
'name' => 'OAuth2#setCode', 'url' => '/client/oauth2/redirect/{serviceId}/',
|
||||
'verb' => 'GET'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "vendor_name/package_name",
|
||||
"description": "description_text",
|
||||
"minimum-stability": "stable",
|
||||
"license": "proprietary",
|
||||
"authors": [
|
||||
{
|
||||
"name": "author's name",
|
||||
"email": "email@example.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"league/oauth2-client": "2.3.0",
|
||||
"lrf141/oauth2-mastodon": "1.0.1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,422 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "61a7838c51e287d8fb6c226460fd4e2c",
|
||||
"packages": [
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
"version": "6.3.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/guzzle.git",
|
||||
"reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba",
|
||||
"reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"guzzlehttp/promises": "^1.0",
|
||||
"guzzlehttp/psr7": "^1.4",
|
||||
"php": ">=5.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-curl": "*",
|
||||
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0",
|
||||
"psr/log": "^1.0"
|
||||
},
|
||||
"suggest": {
|
||||
"psr/log": "Required for using the Log middleware"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "6.3-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/functions_include.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
}
|
||||
],
|
||||
"description": "Guzzle is a PHP HTTP client library",
|
||||
"homepage": "http://guzzlephp.org/",
|
||||
"keywords": [
|
||||
"client",
|
||||
"curl",
|
||||
"framework",
|
||||
"http",
|
||||
"http client",
|
||||
"rest",
|
||||
"web service"
|
||||
],
|
||||
"time": "2018-04-22T15:46:56+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/promises",
|
||||
"version": "v1.3.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/promises.git",
|
||||
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646",
|
||||
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.5.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.4-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\Promise\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"src/functions_include.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
}
|
||||
],
|
||||
"description": "Guzzle promises library",
|
||||
"keywords": [
|
||||
"promise"
|
||||
],
|
||||
"time": "2016-12-20T10:07:11+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/psr7",
|
||||
"version": "1.4.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/psr7.git",
|
||||
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
|
||||
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"psr/http-message": "~1.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/http-message-implementation": "1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.4-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\Psr7\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"src/functions_include.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Schultze",
|
||||
"homepage": "https://github.com/Tobion"
|
||||
}
|
||||
],
|
||||
"description": "PSR-7 message implementation that also provides common utility methods",
|
||||
"keywords": [
|
||||
"http",
|
||||
"message",
|
||||
"request",
|
||||
"response",
|
||||
"stream",
|
||||
"uri",
|
||||
"url"
|
||||
],
|
||||
"time": "2017-03-20T17:10:46+00:00"
|
||||
},
|
||||
{
|
||||
"name": "league/oauth2-client",
|
||||
"version": "2.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/thephpleague/oauth2-client.git",
|
||||
"reference": "aa2e3df188f0bfd87f7880cc880e906e99923580"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/thephpleague/oauth2-client/zipball/aa2e3df188f0bfd87f7880cc880e906e99923580",
|
||||
"reference": "aa2e3df188f0bfd87f7880cc880e906e99923580",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "^6.0",
|
||||
"paragonie/random_compat": "^1|^2",
|
||||
"php": "^5.6|^7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"eloquent/liberator": "^2.0",
|
||||
"eloquent/phony-phpunit": "^1.0|^3.0",
|
||||
"jakub-onderka/php-parallel-lint": "^0.9.2",
|
||||
"phpunit/phpunit": "^5.7|^6.0",
|
||||
"squizlabs/php_codesniffer": "^2.3|^3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-2.x": "2.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"League\\OAuth2\\Client\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Alex Bilbie",
|
||||
"email": "hello@alexbilbie.com",
|
||||
"homepage": "http://www.alexbilbie.com",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"name": "Woody Gilk",
|
||||
"homepage": "https://github.com/shadowhand",
|
||||
"role": "Contributor"
|
||||
}
|
||||
],
|
||||
"description": "OAuth 2.0 Client Library",
|
||||
"keywords": [
|
||||
"Authentication",
|
||||
"SSO",
|
||||
"authorization",
|
||||
"identity",
|
||||
"idp",
|
||||
"oauth",
|
||||
"oauth2",
|
||||
"single sign on"
|
||||
],
|
||||
"time": "2018-01-13T05:27:58+00:00"
|
||||
},
|
||||
{
|
||||
"name": "lrf141/oauth2-mastodon",
|
||||
"version": "1.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/lrf141/oauth2-mastodon.git",
|
||||
"reference": "ba051985643bf46788c151dc70bc8ee85edff6a4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/lrf141/oauth2-mastodon/zipball/ba051985643bf46788c151dc70bc8ee85edff6a4",
|
||||
"reference": "ba051985643bf46788c151dc70bc8ee85edff6a4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"league/oauth2-client": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^1.1",
|
||||
"phpunit/phpunit": ">=5.4.3",
|
||||
"squizlabs/php_codesniffer": "^2.3"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Lrf141\\OAuth2\\Client\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "K.Takeuchi",
|
||||
"email": "ghost141.kentyo@gmail.com",
|
||||
"homepage": "https://github.com/lrf141",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Mastodon OAuth 2.0 support for the PHP League's OAuth 2.0 Client",
|
||||
"homepage": "https://github.com/lrf141/oauth2-client",
|
||||
"keywords": [
|
||||
"authorization",
|
||||
"client",
|
||||
"lrf141",
|
||||
"mastodon",
|
||||
"oauth2",
|
||||
"oauth2-mastodon"
|
||||
],
|
||||
"time": "2018-08-31T08:03:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "paragonie/random_compat",
|
||||
"version": "v2.0.17",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/paragonie/random_compat.git",
|
||||
"reference": "29af24f25bab834fcbb38ad2a69fa93b867e070d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/29af24f25bab834fcbb38ad2a69fa93b867e070d",
|
||||
"reference": "29af24f25bab834fcbb38ad2a69fa93b867e070d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "4.*|5.*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"lib/random.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Paragon Initiative Enterprises",
|
||||
"email": "security@paragonie.com",
|
||||
"homepage": "https://paragonie.com"
|
||||
}
|
||||
],
|
||||
"description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
|
||||
"keywords": [
|
||||
"csprng",
|
||||
"polyfill",
|
||||
"pseudorandom",
|
||||
"random"
|
||||
],
|
||||
"time": "2018-07-04T16:31:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-message",
|
||||
"version": "1.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/http-message.git",
|
||||
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
|
||||
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Http\\Message\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "http://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interface for HTTP messages",
|
||||
"homepage": "https://github.com/php-fig/http-message",
|
||||
"keywords": [
|
||||
"http",
|
||||
"http-message",
|
||||
"psr",
|
||||
"psr-7",
|
||||
"request",
|
||||
"response"
|
||||
],
|
||||
"time": "2016-08-06T14:39:51+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": []
|
||||
}
|
14
js/social.js
14
js/social.js
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,105 @@
|
|||
(function () {
|
||||
|
||||
var Social = function () {
|
||||
|
||||
var elem = {
|
||||
socialInstanceNewAccount: null,
|
||||
socialSubmitNewAccount: null,
|
||||
socialListAccounts: null,
|
||||
socialSubmitAccountTest: null
|
||||
}
|
||||
|
||||
var test = {
|
||||
|
||||
newAccount: function () {
|
||||
var data = {
|
||||
instance: elem.socialInstanceNewAccount.val()
|
||||
}
|
||||
|
||||
test.sendRequest('POST', data, '/user/account', test.newAccountResult)
|
||||
},
|
||||
|
||||
newAccountResult: function (data) {
|
||||
if (data.status !== 1) {
|
||||
return
|
||||
}
|
||||
|
||||
window.open(data.result.authorizationUrl, 'gettoken', 'width=500,height=550')
|
||||
|
||||
// test.getAccounts()
|
||||
},
|
||||
|
||||
getAccounts: function () {
|
||||
test.sendRequest('GET', {}, '/user/accounts', test.getAccountsResult)
|
||||
},
|
||||
|
||||
getAccountsResult: function (data) {
|
||||
if (data.status !== 1) {
|
||||
return
|
||||
}
|
||||
|
||||
elem.socialListAccounts.empty()
|
||||
for (var i = 0; i < data.result.accounts.length; i++) {
|
||||
var item = data.result.accounts[i]
|
||||
elem.socialListAccounts.append($('<option>', {value: item.id}).text(item.account + '@' + item.service.address))
|
||||
}
|
||||
},
|
||||
|
||||
testAccount: function (accountId) {
|
||||
test.sendRequest('GET', {}, '/user/account/' + accountId + '/test', test.testAccountResult)
|
||||
},
|
||||
|
||||
testAccountResult: function (data) {
|
||||
console.log(JSON.stringify(data))
|
||||
},
|
||||
|
||||
sendRequest: function (method, data, url, callback) {
|
||||
$.ajax({
|
||||
method: method,
|
||||
url: OC.generateUrl('/apps/social' + url),
|
||||
data: {data: data}
|
||||
}).done(function (res) {
|
||||
test.requestCallback(callback, res)
|
||||
}).fail(function () {
|
||||
console.log('fail to request')
|
||||
})
|
||||
},
|
||||
|
||||
requestCallback: function (callback, result) {
|
||||
if (callback && (typeof callback === 'function')) {
|
||||
if (typeof result === 'object') {
|
||||
callback(result)
|
||||
} else {
|
||||
callback({status: -1})
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
elem.socialInstanceNewAccount = $('#social-instance-new-account')
|
||||
elem.socialSubmitNewAccount = $('#social-submit-new-account')
|
||||
elem.socialListAccounts = $('#social-list-accounts')
|
||||
elem.socialSubmitAccountTest = $('#social-submit-account-test')
|
||||
|
||||
elem.socialSubmitNewAccount.on('click', function () {
|
||||
test.newAccount()
|
||||
})
|
||||
|
||||
elem.socialSubmitAccountTest.on('click', function () {
|
||||
test.testAccount(elem.socialListAccounts.val())
|
||||
})
|
||||
|
||||
test.getAccounts()
|
||||
}
|
||||
|
||||
if (OCA.Social === undefined) {
|
||||
OCA.Social = {}
|
||||
}
|
||||
OCA.Social.test = new Social()
|
||||
|
||||
})()
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\AppInfo;
|
||||
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\AppFramework\IAppContainer;
|
||||
|
||||
class Application extends App {
|
||||
|
||||
const APP_NAME = 'social';
|
||||
|
||||
/** @var IAppContainer */
|
||||
private $container;
|
||||
|
||||
|
||||
/**
|
||||
* Application constructor.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct(array $params = []) {
|
||||
parent::__construct(self::APP_NAME, $params);
|
||||
|
||||
$this->container = $this->getContainer();
|
||||
}
|
||||
|
||||
//
|
||||
// /**
|
||||
// * Register Navigation Tab
|
||||
// */
|
||||
// public function registerNavigation() {
|
||||
//
|
||||
// $urlGen = \OC::$server->getURLGenerator();
|
||||
// $navName = \OC::$server->getL10N(self::APP_NAME)
|
||||
// ->t('Social');
|
||||
//
|
||||
// $social = [
|
||||
// 'id' => self::APP_NAME,
|
||||
// 'order' => 5,
|
||||
// 'href' => $urlGen->linkToRoute('social.Navigation.navigate'),
|
||||
// 'icon' => $urlGen->imagePath(self::APP_NAME, 'social.svg'),
|
||||
// 'name' => $navName
|
||||
// ];
|
||||
//
|
||||
// $this->container->getServer()
|
||||
// ->getNavigationManager()
|
||||
// ->add($social);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Controller;
|
||||
|
||||
use daita\Traits\TArrayTools;
|
||||
use daita\Traits\TNCDataResponse;
|
||||
use Exception;
|
||||
use OCA\Social\AppInfo\Application;
|
||||
use OCA\Social\Service\ActivityStreamsService;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCA\Social\Service\ServiceAccountsService;
|
||||
use OCA\Social\Service\ServicesService;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\IRequest;
|
||||
|
||||
|
||||
class ActivityStreamsController extends Controller {
|
||||
|
||||
use TArrayTools;
|
||||
use TNCDataResponse;
|
||||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
/** @var ConfigService */
|
||||
private $configService;
|
||||
|
||||
/** @var ServiceAccountsService */
|
||||
private $serviceAccountsService;
|
||||
|
||||
/** @var ActivityStreamsService */
|
||||
private $activityStreamsService;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* ServiceAccountsController constructor.
|
||||
*
|
||||
* @param IRequest $request
|
||||
* @param string $userId
|
||||
* @param ConfigService $configService
|
||||
* @param ServiceAccountsService $serviceAccountsService
|
||||
* @param ActivityStreamsService $activityStreamsService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IRequest $request, string $userId, ConfigService $configService,
|
||||
ServiceAccountsService $serviceAccountsService,
|
||||
ActivityStreamsService $activityStreamsService, MiscService $miscService
|
||||
) {
|
||||
parent::__construct(Application::APP_NAME, $request);
|
||||
|
||||
$this->userId = $userId;
|
||||
$this->configService = $configService;
|
||||
$this->serviceAccountsService = $serviceAccountsService;
|
||||
$this->activityStreamsService = $activityStreamsService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function test(int $accountId): DataResponse {
|
||||
try {
|
||||
$account = $this->serviceAccountsService->getAccount($this->userId, $accountId);
|
||||
|
||||
$result = $this->activityStreamsService->test($account);
|
||||
|
||||
return $this->success($result);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Controller;
|
||||
|
||||
|
||||
use OCA\Social\AppInfo\Application;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
use OCP\IURLGenerator;
|
||||
|
||||
class NavigationController extends Controller {
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* NavigationController constructor.
|
||||
*
|
||||
* @param IRequest $request
|
||||
* @param IConfig $config
|
||||
* @param IURLGenerator $urlGenerator
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IRequest $request, IConfig $config, IURLGenerator $urlGenerator, MiscService $miscService
|
||||
) {
|
||||
parent::__construct(Application::APP_NAME, $request);
|
||||
|
||||
$this->config = $config;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
* @NoSubAdminRequired
|
||||
*
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function navigate() {
|
||||
$data = [];
|
||||
|
||||
return new TemplateResponse(Application::APP_NAME, 'main', $data);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Controller;
|
||||
|
||||
|
||||
use daita\Traits\TNCDataResponse;
|
||||
use Exception;
|
||||
use OCA\Social\AppInfo\Application;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCA\Social\Service\ServiceAccountsService;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
use OCP\IURLGenerator;
|
||||
|
||||
class OAuth2Controller extends Controller {
|
||||
|
||||
|
||||
use TNCDataResponse;
|
||||
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
/** @var ServiceAccountsService */
|
||||
private $serviceAccountsService;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* NavigationController constructor.
|
||||
*
|
||||
* @param IRequest $request
|
||||
* @param IConfig $config
|
||||
* @param string $userId
|
||||
* @param IURLGenerator $urlGenerator
|
||||
* @param ServiceAccountsService $serviceAccountsService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IRequest $request, IConfig $config, string $userId, IURLGenerator $urlGenerator,
|
||||
ServiceAccountsService $serviceAccountsService, MiscService $miscService
|
||||
) {
|
||||
parent::__construct(Application::APP_NAME, $request);
|
||||
|
||||
$this->config = $config;
|
||||
$this->userId = $userId;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
|
||||
$this->serviceAccountsService = $serviceAccountsService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
* @NoSubAdminRequired
|
||||
*
|
||||
* @param int $serviceId
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setCode(int $serviceId) {
|
||||
|
||||
$code = $_GET['code'];
|
||||
// TODO: verify $state
|
||||
$state = $_GET['state'];
|
||||
|
||||
$this->serviceAccountsService->generateAccount($this->userId, $serviceId, $code);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
namespace OCA\Social\Controller;
|
||||
|
||||
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\Mail\IEMailTemplate;
|
||||
use OCP\Mail\IMailer;
|
||||
|
||||
class PageController extends Controller {
|
||||
private $userId;
|
||||
|
||||
public function __construct($AppName, IRequest $request, $UserId, IL10N $l10n){
|
||||
parent::__construct($AppName, $request);
|
||||
$this->userId = $UserId;
|
||||
$this->l10n = $l10n;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function index() {
|
||||
$response = new TemplateResponse('social', 'main');
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Controller;
|
||||
|
||||
use daita\Traits\TArrayTools;
|
||||
use daita\Traits\TNCDataResponse;
|
||||
use Exception;
|
||||
use OCA\Social\AppInfo\Application;
|
||||
use OCA\Social\Service\ActivityStreamsService;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCA\Social\Service\ServiceAccountsService;
|
||||
use OCA\Social\Service\ServicesService;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\IRequest;
|
||||
|
||||
|
||||
class ServiceAccountsController extends Controller {
|
||||
|
||||
use TArrayTools;
|
||||
use TNCDataResponse;
|
||||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
/** @var ConfigService */
|
||||
private $configService;
|
||||
|
||||
/** @var ServicesService */
|
||||
private $servicesService;
|
||||
|
||||
/** @var ServiceAccountsService */
|
||||
private $serviceAccountsService;
|
||||
|
||||
/** @var ActivityStreamsService */
|
||||
private $activityStreamsService;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* ServiceAccountsController constructor.
|
||||
*
|
||||
* @param IRequest $request
|
||||
* @param string $userId
|
||||
* @param ConfigService $configService
|
||||
* @param ServicesService $servicesService
|
||||
* @param ServiceAccountsService $serviceAccountsService
|
||||
* @param ActivityStreamsService $activityStreamsService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IRequest $request, string $userId, ConfigService $configService,
|
||||
ServicesService $servicesService, ServiceAccountsService $serviceAccountsService,
|
||||
ActivityStreamsService $activityStreamsService, MiscService $miscService
|
||||
) {
|
||||
parent::__construct(Application::APP_NAME, $request);
|
||||
|
||||
$this->userId = $userId;
|
||||
$this->configService = $configService;
|
||||
$this->servicesService = $servicesService;
|
||||
$this->serviceAccountsService = $serviceAccountsService;
|
||||
$this->activityStreamsService = $activityStreamsService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function getAvailableAccounts(): DataResponse {
|
||||
try {
|
||||
$ret =
|
||||
['accounts' => $this->serviceAccountsService->getAvailableAccounts($this->userId)];
|
||||
|
||||
return $this->success($ret);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function create(array $data): DataResponse {
|
||||
try {
|
||||
$instance = strtolower($this->get('instance', $data, ''));
|
||||
if ($instance === '') {
|
||||
throw new Exception('Empty address');
|
||||
}
|
||||
|
||||
$service = $this->servicesService->createFromInstance($instance);
|
||||
|
||||
$authUrl = $this->serviceAccountsService->getAuthorizationUrl($service);
|
||||
$data = [
|
||||
'protocol' => 'OAuth2',
|
||||
'authorizationUrl' => $authUrl
|
||||
];
|
||||
$this->miscService->log('___' . json_encode($data));
|
||||
|
||||
return $this->success($data);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,204 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Db;
|
||||
|
||||
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
class CoreRequestBuilder {
|
||||
|
||||
const TABLE_SERVICES = 'social_services';
|
||||
const TABLE_ACCOUNTS = 'social_accounts';
|
||||
const TABLE_OAUTH2_TOKENS = 'social_oauth2_tokens';
|
||||
|
||||
|
||||
/** @var IDBConnection */
|
||||
protected $dbConnection;
|
||||
|
||||
/** @var ConfigService */
|
||||
protected $configService;
|
||||
|
||||
/** @var MiscService */
|
||||
protected $miscService;
|
||||
|
||||
|
||||
/** @var string */
|
||||
protected $defaultSelectAlias;
|
||||
|
||||
|
||||
/**
|
||||
* CoreRequestBuilder constructor.
|
||||
*
|
||||
* @param IDBConnection $connection
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IDBConnection $connection, ConfigService $configService, MiscService $miscService
|
||||
) {
|
||||
$this->dbConnection = $connection;
|
||||
$this->configService = $configService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Limit the request to the Id
|
||||
*
|
||||
* @param IQueryBuilder $qb
|
||||
* @param int $id
|
||||
*/
|
||||
protected function limitToId(IQueryBuilder &$qb, $id) {
|
||||
$this->limitToDBField($qb, 'id', $id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Limit the request to the OwnerId
|
||||
*
|
||||
* @param IQueryBuilder $qb
|
||||
* @param string $userId
|
||||
*/
|
||||
protected function limitToUserId(IQueryBuilder &$qb, $userId) {
|
||||
$this->limitToDBField($qb, 'user_id', $userId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Limit the request to the OwnerId
|
||||
*
|
||||
* @param IQueryBuilder $qb
|
||||
* @param int $accountId
|
||||
*/
|
||||
protected function limitToAccountId(IQueryBuilder &$qb, int $accountId) {
|
||||
$this->limitToDBField($qb, 'account_id', $accountId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Limit the request to the ServiceId
|
||||
*
|
||||
* @param IQueryBuilder $qb
|
||||
* @param int $serviceId
|
||||
*/
|
||||
protected function limitToServiceId(IQueryBuilder &$qb, int $serviceId) {
|
||||
$this->limitToDBField($qb, 'service_id', $serviceId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Limit the request to the account
|
||||
*
|
||||
* @param IQueryBuilder $qb
|
||||
* @param string $account
|
||||
*/
|
||||
protected function limitToAccount(IQueryBuilder &$qb, string $account) {
|
||||
$this->limitToDBField($qb, 'account', $account);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Limit the request to the status
|
||||
*
|
||||
* @param IQueryBuilder $qb
|
||||
* @param string $status
|
||||
*/
|
||||
protected function limitToStatus(IQueryBuilder &$qb, $status) {
|
||||
$this->limitToDBField($qb, 'status', $status);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Limit the request to the instance
|
||||
*
|
||||
* @param IQueryBuilder $qb
|
||||
* @param string $address
|
||||
*/
|
||||
protected function limitToAddress(IQueryBuilder &$qb, $address) {
|
||||
$this->limitToDBField($qb, 'address', $address);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param IQueryBuilder $qb
|
||||
* @param string $field
|
||||
* @param string|integer|array $values
|
||||
*/
|
||||
private function limitToDBField(IQueryBuilder &$qb, $field, $values) {
|
||||
$expr = $qb->expr();
|
||||
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
|
||||
$field = $pf . $field;
|
||||
|
||||
if (!is_array($values)) {
|
||||
$values = [$values];
|
||||
}
|
||||
|
||||
$orX = $expr->orX();
|
||||
foreach ($values as $value) {
|
||||
$orX->add($expr->eq($field, $qb->createNamedParameter($value)));
|
||||
}
|
||||
|
||||
$qb->andWhere($orX);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Left Join service to get info about the serviceId
|
||||
*
|
||||
* @param IQueryBuilder $qb
|
||||
*/
|
||||
public function leftJoinService(IQueryBuilder &$qb) {
|
||||
|
||||
if ($qb->getType() !== QueryBuilder::SELECT) {
|
||||
return;
|
||||
}
|
||||
|
||||
$expr = $qb->expr();
|
||||
$pf = $this->defaultSelectAlias;
|
||||
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
$qb->selectAlias('s.address', 'service_address')
|
||||
->selectAlias('s.status', 'service_status')
|
||||
->selectAlias('s.config', 'service_config')
|
||||
->selectAlias('s.type', 'service_type')
|
||||
->leftJoin(
|
||||
$this->defaultSelectAlias, CoreRequestBuilder::TABLE_SERVICES, 's',
|
||||
$expr->eq($pf . '.service_id', 's.id')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,230 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Db;
|
||||
|
||||
|
||||
use Exception;
|
||||
use OCA\Social\Exceptions\ServiceAccountDoesNotExistException;
|
||||
use OCA\Social\Model\ServiceAccount;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
|
||||
class ServiceAccountsRequest extends ServiceAccountsRequestBuilder {
|
||||
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
|
||||
|
||||
/**
|
||||
* ServicesRequest constructor.
|
||||
*
|
||||
* @param IL10N $l10n
|
||||
* @param IDBConnection $connection
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IL10n $l10n, IDBConnection $connection, ConfigService $configService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
parent::__construct($connection, $configService, $miscService);
|
||||
|
||||
$this->l10n = $l10n;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceAccount $account
|
||||
*
|
||||
* @return int
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create(ServiceAccount $account): int {
|
||||
try {
|
||||
$service = $account->getService();
|
||||
$qb = $this->getAccountsInsertSql();
|
||||
$qb->setValue('service_id', $qb->createNamedParameter($service->getId()))
|
||||
->setValue('user_id', $qb->createNamedParameter($account->getUserId()))
|
||||
->setValue('account', $qb->createNamedParameter($account->getAccount()))
|
||||
->setValue('status', $qb->createNamedParameter($account->getStatus()))
|
||||
->setValue('auth', $qb->createNamedParameter(json_encode($account->getAuthAll())));
|
||||
|
||||
$qb->execute();
|
||||
|
||||
return $qb->getLastInsertId();
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
*
|
||||
* @return ServiceAccount[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getAvailableAccounts(string $userId): array {
|
||||
try {
|
||||
$qb = $this->getAccountsSelectSql();
|
||||
$this->limitToUserId($qb, $userId);
|
||||
$this->limitToStatus($qb, 1);
|
||||
$this->leftJoinService($qb);
|
||||
|
||||
$accounts = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
$accounts[] = $this->parseAccountsSelectSql($data);
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
return $accounts;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $serviceId
|
||||
* @param string $userId
|
||||
* @param string $accountName
|
||||
*
|
||||
* @return ServiceAccount
|
||||
* @throws ServiceAccountDoesNotExistException
|
||||
*/
|
||||
public function getFromAccountName(int $serviceId, string $userId, string $accountName) {
|
||||
$qb = $this->getAccountsSelectSql();
|
||||
$this->limitToUserId($qb, $userId);
|
||||
$this->limitToAccount($qb, $accountName);
|
||||
$this->limitToServiceId($qb, $serviceId);
|
||||
$this->leftJoinService($qb);
|
||||
|
||||
$cursor = $qb->execute();
|
||||
$data = $cursor->fetch();
|
||||
$cursor->closeCursor();
|
||||
|
||||
if ($data === false) {
|
||||
throw new ServiceAccountDoesNotExistException($this->l10n->t('Account not found'));
|
||||
}
|
||||
|
||||
return $this->parseAccountsSelectSql($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return account.
|
||||
*
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return ServiceAccount
|
||||
* @throws ServiceAccountDoesNotExistException
|
||||
*/
|
||||
public function getAccount(int $accountId): ServiceAccount {
|
||||
$qb = $this->getAccountsSelectSql();
|
||||
$this->limitToId($qb, $accountId);
|
||||
$this->leftJoinService($qb);
|
||||
|
||||
$cursor = $qb->execute();
|
||||
$data = $cursor->fetch();
|
||||
$cursor->closeCursor();
|
||||
|
||||
if ($data === false) {
|
||||
throw new ServiceAccountDoesNotExistException($this->l10n->t('Account not found'));
|
||||
}
|
||||
|
||||
return $this->parseAccountsSelectSql($data);
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * @param Service $service
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// public function update(Service $service): bool {
|
||||
//
|
||||
// try {
|
||||
// $this->getService($service->getId());
|
||||
// } catch (ServiceDoesNotExistException $e) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// $qb = $this->getServicesUpdateSql();
|
||||
// $qb->set('address', $qb->createNamedParameter($service->getAddress()));
|
||||
// $qb->set('config', $qb->createNamedParameter(json_encode($service->getConfigAll())));
|
||||
// $qb->set('status', $qb->createNamedParameter($service->getStatus()));
|
||||
// $qb->set('auth', $qb->createNamedParameter(''));
|
||||
// $qb->set('config', $qb->createNamedParameter(json_encode($service->getConfigAll())));
|
||||
//
|
||||
// $this->limitToId($qb, $service->getId());
|
||||
//
|
||||
// $qb->execute();
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * @param int $serviceId
|
||||
// */
|
||||
// public function delete(int $serviceId) {
|
||||
// $qb = $this->getServicesDeleteSql();
|
||||
// $this->limitToId($qb, $serviceId);
|
||||
//
|
||||
// $qb->execute();
|
||||
// }
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
// /**
|
||||
// * return services.
|
||||
// *
|
||||
// * @return Service[]
|
||||
// */
|
||||
// public function getServices(): array {
|
||||
// $qb = $this->getServicesSelectSql();
|
||||
//
|
||||
// $services = [];
|
||||
// $cursor = $qb->execute();
|
||||
// while ($data = $cursor->fetch()) {
|
||||
// $services[] = $this->parseServicesSelectSql($data);
|
||||
// }
|
||||
// $cursor->closeCursor();
|
||||
//
|
||||
// return $services;
|
||||
// }
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Db;
|
||||
|
||||
|
||||
use daita\Traits\TArrayTools;
|
||||
use OCA\Social\Model\Service;
|
||||
use OCA\Social\Model\ServiceAccount;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
|
||||
class ServiceAccountsRequestBuilder extends CoreRequestBuilder {
|
||||
|
||||
|
||||
use TArrayTools;
|
||||
|
||||
|
||||
/**
|
||||
* Base of the Sql Insert request
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getAccountsInsertSql() {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->insert(self::TABLE_ACCOUNTS);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base of the Sql Update request
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getAccountsUpdateSql() {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->update(self::TABLE_ACCOUNTS);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base of the Sql Select request for Shares
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getAccountsSelectSql() {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
$qb->select(
|
||||
'a.id', 'a.service_id', 'a.user_id', 'a.account', 'a.status', 'a.auth', 'a.config',
|
||||
'a.creation'
|
||||
)
|
||||
->from(self::TABLE_ACCOUNTS, 'a');
|
||||
|
||||
$this->defaultSelectAlias = 'a';
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base of the Sql Delete request
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getAccountsDeleteSql() {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->delete(self::TABLE_ACCOUNTS);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
protected function parseAccountsSelectSql($data) {
|
||||
|
||||
$service = new Service($this->getInt('service_id', $data));
|
||||
$service->setAddress($this->get('service_address', $data, ''))
|
||||
->setStatus($this->getInt('service_status', $data, 0))
|
||||
->setConfigAll(json_decode($this->get('service_config', $data, '[]'), true))
|
||||
->setType($this->get('service_type', $data, ''));
|
||||
|
||||
$account = new ServiceAccount(intval($data['id']));
|
||||
$account->setService($service)
|
||||
->setUserId($data['user_id'])
|
||||
->setAccount($this->get('account', $data, ''))
|
||||
->setStatus($this->getInt('status', $data, 0))
|
||||
->setAuthAll(json_decode($this->get('auth', $data, '[]'), true))
|
||||
->setConfigAll(json_decode($this->get('config', $data, '[]'), true))
|
||||
->setCreation($this->getInt('creation', $data, 0));
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,199 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Db;
|
||||
|
||||
|
||||
use OCA\Social\Exceptions\ServiceDoesNotExistException;
|
||||
use OCA\Social\Model\Service;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
|
||||
class ServicesRequest extends ServicesRequestBuilder {
|
||||
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
|
||||
|
||||
/**
|
||||
* ServicesRequest constructor.
|
||||
*
|
||||
* @param IL10N $l10n
|
||||
* @param IDBConnection $connection
|
||||
* @param ConfigService $configService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
IL10n $l10n, IDBConnection $connection, ConfigService $configService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
parent::__construct($connection, $configService, $miscService);
|
||||
|
||||
$this->l10n = $l10n;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $instance
|
||||
*
|
||||
* @return int
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function create(string $type, string $instance): int {
|
||||
|
||||
try {
|
||||
$qb = $this->getServicesInsertSql();
|
||||
$qb->setValue('type', $qb->createNamedParameter($type))
|
||||
->setValue('address', $qb->createNamedParameter($instance))
|
||||
->setValue('status', $qb->createNamedParameter(Service::STATUS_SETUP));
|
||||
|
||||
$qb->execute();
|
||||
|
||||
return $qb->getLastInsertId();
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Service $service
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function update(Service $service): bool {
|
||||
|
||||
try {
|
||||
$this->getService($service->getId());
|
||||
} catch (ServiceDoesNotExistException $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$qb = $this->getServicesUpdateSql();
|
||||
$qb->set('address', $qb->createNamedParameter($service->getAddress()));
|
||||
$qb->set('config', $qb->createNamedParameter(json_encode($service->getConfigAll())));
|
||||
$qb->set('status', $qb->createNamedParameter($service->getStatus()));
|
||||
$qb->set('config', $qb->createNamedParameter(json_encode($service->getConfigAll())));
|
||||
|
||||
$this->limitToId($qb, $service->getId());
|
||||
|
||||
$qb->execute();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $serviceId
|
||||
*/
|
||||
public function delete(int $serviceId) {
|
||||
$qb = $this->getServicesDeleteSql();
|
||||
$this->limitToId($qb, $serviceId);
|
||||
|
||||
$qb->execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return service.
|
||||
*
|
||||
* @param int $serviceId
|
||||
*
|
||||
* @return Service
|
||||
* @throws ServiceDoesNotExistException
|
||||
*/
|
||||
public function getService(int $serviceId): Service {
|
||||
$qb = $this->getServicesSelectSql();
|
||||
$this->limitToId($qb, $serviceId);
|
||||
|
||||
$cursor = $qb->execute();
|
||||
$data = $cursor->fetch();
|
||||
$cursor->closeCursor();
|
||||
|
||||
if ($data === false) {
|
||||
throw new ServiceDoesNotExistException($this->l10n->t('Service not found'));
|
||||
}
|
||||
|
||||
return $this->parseServicesSelectSql($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return service.
|
||||
*
|
||||
* @param string $instance
|
||||
*
|
||||
* @return Service
|
||||
* @throws ServiceDoesNotExistException
|
||||
*/
|
||||
public function getServiceFromInstance(string $instance): Service {
|
||||
$qb = $this->getServicesSelectSql();
|
||||
$this->limitToAddress($qb, $instance);
|
||||
|
||||
$cursor = $qb->execute();
|
||||
$data = $cursor->fetch();
|
||||
$cursor->closeCursor();
|
||||
|
||||
if ($data === false) {
|
||||
throw new ServiceDoesNotExistException($this->l10n->t('Service not found'));
|
||||
}
|
||||
|
||||
return $this->parseServicesSelectSql($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return services.
|
||||
*
|
||||
* @param bool $validOnly
|
||||
*
|
||||
* @return Service[]
|
||||
*/
|
||||
public function getServices($validOnly = false): array {
|
||||
$qb = $this->getServicesSelectSql();
|
||||
|
||||
if ($validOnly === true) {
|
||||
$this->limitToStatus($qb, 1);
|
||||
}
|
||||
|
||||
$services = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
$services[] = $this->parseServicesSelectSql($data, $validOnly);
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
return $services;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Db;
|
||||
|
||||
|
||||
use daita\Traits\TArrayTools;
|
||||
use OCA\Social\Model\Service;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
|
||||
class ServicesRequestBuilder extends CoreRequestBuilder {
|
||||
|
||||
|
||||
use TArrayTools;
|
||||
|
||||
|
||||
/**
|
||||
* Base of the Sql Insert request
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getServicesInsertSql() {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->insert(self::TABLE_SERVICES);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base of the Sql Update request
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getServicesUpdateSql() {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->update(self::TABLE_SERVICES);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base of the Sql Select request for Shares
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getServicesSelectSql() {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
$qb->select('s.id', 's.type', 's.address', 's.status', 's.config', 's.creation')
|
||||
->from(self::TABLE_SERVICES, 's');
|
||||
|
||||
$this->defaultSelectAlias = 's';
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base of the Sql Delete request
|
||||
*
|
||||
* @return IQueryBuilder
|
||||
*/
|
||||
protected function getServicesDeleteSql() {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->delete(self::TABLE_SERVICES);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param bool $sensitive
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
protected function parseServicesSelectSql($data, $sensitive = false) {
|
||||
$service = new Service(intval($data['id']));
|
||||
$service->setType($data['type'])
|
||||
->setAddress($data['address'])
|
||||
->setStatus($this->getInt('status', $data, -1))
|
||||
->setCreation($this->getInt('creation', $data, 0));
|
||||
|
||||
if ($sensitive === false) {
|
||||
$service->setConfigAll(json_decode($this->get('config', $data, '[]'), true));
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class ActivityStreamsRequestException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class InvalidAccessTokenException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class MissingStuffException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class MovedPermanentlyException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class ServiceAccountAlreadyExistException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class ServiceAccountDoesNotExistException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class ServiceAccountException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class ServiceDoesNotExistException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class TokenGenerationException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,238 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Model;
|
||||
|
||||
|
||||
use daita\Traits\TArrayTools;
|
||||
|
||||
class Service implements \JsonSerializable {
|
||||
|
||||
|
||||
const STATUS_SETUP = 0;
|
||||
const STATUS_VALID = 1;
|
||||
|
||||
|
||||
use TArrayTools;
|
||||
|
||||
|
||||
/** @var int */
|
||||
private $id;
|
||||
|
||||
/** @var string */
|
||||
private $type = '';
|
||||
|
||||
/** @var string */
|
||||
private $address = '';
|
||||
|
||||
/** @var int */
|
||||
private $status = -1;
|
||||
|
||||
/** @var array */
|
||||
private $config = [];
|
||||
|
||||
/** @var int */
|
||||
private $creation = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Service constructor.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function __construct(int $id = 0) {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
public function setId(int $id): Service {
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
public function setType(string $type): Service {
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAddress(): string {
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $address
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
public function setAddress(string $address): Service {
|
||||
$this->address = $address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getStatus(): int {
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $status
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
public function setStatus(int $status): Service {
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getConfigAll(): array {
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
public function setConfigAll(array $config): Service {
|
||||
$this->config = $config;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @param string $default
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConfig(string $key, string $default = ''): string {
|
||||
return $this->get($key, $this->config, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
public function setConfig(string $key, string $value): Service {
|
||||
$this->config[$key] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
public function unsetConfig(string $key): Service {
|
||||
unset($this->config[$key]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCreation(): int {
|
||||
return $this->creation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $creation
|
||||
*
|
||||
* @return Service
|
||||
*/
|
||||
public function setCreation(int $creation): Service {
|
||||
$this->creation = $creation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'type' => $this->getType(),
|
||||
'address' => $this->getAddress(),
|
||||
'status' => $this->getStatus(),
|
||||
'config' => $this->getConfigAll(),
|
||||
'creation' => $this->getCreation()
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,324 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Model;
|
||||
|
||||
|
||||
class ServiceAccount implements \JsonSerializable {
|
||||
|
||||
|
||||
/** @var int */
|
||||
private $id;
|
||||
|
||||
/** @var Service */
|
||||
private $service;
|
||||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
/** @var string */
|
||||
private $account = '';
|
||||
|
||||
/** @var int */
|
||||
private $status = 0;
|
||||
|
||||
/** @var array */
|
||||
private $auth = [];
|
||||
|
||||
/** @var array */
|
||||
private $config = [];
|
||||
|
||||
/** @var int */
|
||||
private $creation = 0;
|
||||
|
||||
|
||||
/**
|
||||
* ServiceAccount constructor.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function __construct(int $id = 0) {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setId(int $id): ServiceAccount {
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Service
|
||||
*/
|
||||
public function getService(): Service {
|
||||
return $this->service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Service $service
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setService(Service $service): ServiceAccount {
|
||||
$this->service = $service;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUserId(): string {
|
||||
return $this->userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setUserId(string $userId): ServiceAccount {
|
||||
$this->userId = $userId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAccount(): string {
|
||||
return $this->account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $account
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setAccount(string $account): ServiceAccount {
|
||||
$this->account = $account;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getStatus(): int {
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $status
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setStatus(int $status): ServiceAccount {
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAuth(string $k): string {
|
||||
return $this->auth[$k];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAuthInt(string $k): int {
|
||||
return $this->auth[$k];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAuthAll(): array {
|
||||
return $this->auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $auth
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setAuthAll(array $auth): ServiceAccount {
|
||||
$this->auth = $auth;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
* @param string $v
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setAuth(string $k, string $v): ServiceAccount {
|
||||
$this->auth[$k] = $v;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
* @param int $v
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setAuthInt(string $k, int $v): ServiceAccount {
|
||||
$this->auth[$k] = $v;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConfig(string $k): string {
|
||||
return $this->config[$k];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getConfigInt(string $k): int {
|
||||
return $this->config[$k];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getConfigAll(): array {
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
* @param string $v
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setConfig(string $k, string $v): ServiceAccount {
|
||||
$this->config[$k] = $v;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
* @param int $v
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setConfigInt(string $k, int $v): ServiceAccount {
|
||||
$this->config[$k] = $v;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setConfigAll(array $config): ServiceAccount {
|
||||
$this->config = $config;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCreation(): int {
|
||||
return $this->creation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $creation
|
||||
*
|
||||
* @return ServiceAccount
|
||||
*/
|
||||
public function setCreation(int $creation): ServiceAccount {
|
||||
$this->creation = $creation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'service' => $this->getService(),
|
||||
'userId' => $this->getUserId(),
|
||||
'account' => $this->getAccount(),
|
||||
'auth' => $this->getAuthAll(),
|
||||
'creation' => $this->getCreation()
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Service;
|
||||
|
||||
|
||||
use daita\Model\Request;
|
||||
use Exception;
|
||||
use OCA\Social\Db\ServiceAccountsRequest;
|
||||
use OCA\Social\Exceptions\ActivityStreamsRequestException;
|
||||
use OCA\Social\Exceptions\InvalidAccessTokenException;
|
||||
use OCA\Social\Model\ServiceAccount;
|
||||
use OCA\Social\Traits\TOAuth2;
|
||||
|
||||
class ActivityStreamsService {
|
||||
|
||||
|
||||
const URL_CREATE_APP = '/api/v1/apps';
|
||||
const URL_VERIFY_ACCOUNT = '/api/v1/accounts/verify_credentials';
|
||||
const URL_TEST = '/api/v1/accounts/verify_credentials';
|
||||
|
||||
|
||||
use TOAuth2;
|
||||
|
||||
/** @var ServiceAccountsRequest */
|
||||
private $serviceAccountsRequest;
|
||||
|
||||
/** @var ConfigService */
|
||||
private $configService;
|
||||
|
||||
/** @var CurlService */
|
||||
private $curlService;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* ActivityStreamsService constructor.
|
||||
*
|
||||
* @param ServiceAccountsRequest $serviceAccountsRequest
|
||||
* @param ConfigService $configService
|
||||
* @param CurlService $curlService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
ServiceAccountsRequest $serviceAccountsRequest, ConfigService $configService,
|
||||
CurlService $curlService, MiscService $miscService
|
||||
) {
|
||||
$this->serviceAccountsRequest = $serviceAccountsRequest;
|
||||
$this->configService = $configService;
|
||||
$this->curlService = $curlService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceAccount $account
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function test(ServiceAccount $account) {
|
||||
$request = new Request(self::URL_TEST, Request::TYPE_GET);
|
||||
|
||||
return $this->request($account, $request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceAccount $account
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getAccountInformation(ServiceAccount $account) {
|
||||
$request = new Request(self::URL_VERIFY_ACCOUNT, Request::TYPE_GET);
|
||||
|
||||
return $this->request($account, $request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceAccount $account
|
||||
* @param Request $request
|
||||
*
|
||||
* @return array
|
||||
* @throws ActivityStreamsRequestException
|
||||
*/
|
||||
private function request(ServiceAccount $account, Request $request) {
|
||||
try {
|
||||
return $this->curlService->request($account, $request, true);
|
||||
} catch (InvalidAccessTokenException $e) {
|
||||
// $this->oAuth2TokensRequest->resetToken($auth);
|
||||
throw new ActivityStreamsRequestException($e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
$message = 'Issue with ' . json_encode($request) . ' - ' . get_class($e) . ' - '
|
||||
. $e->getMessage();
|
||||
|
||||
$this->miscService->log($message);
|
||||
throw new ActivityStreamsRequestException($message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,201 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Service;
|
||||
|
||||
use OCA\Social\AppInfo\Application;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
use OCP\PreConditionNotMetException;
|
||||
|
||||
|
||||
class ConfigService {
|
||||
|
||||
/** @var array */
|
||||
public $defaults = [
|
||||
];
|
||||
|
||||
// public $serviceTypes = [
|
||||
// [
|
||||
// 'id' => 'mastodon',
|
||||
// 'name' => 'Mastodon (OAuth2)'
|
||||
// ]
|
||||
// ];
|
||||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var IRequest */
|
||||
private $request;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* ConfigService constructor.
|
||||
*
|
||||
* @param string $userId
|
||||
* @param IConfig $config
|
||||
* @param IRequest $request
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
string $userId, IConfig $config, IRequest $request, MiscService $miscService
|
||||
) {
|
||||
$this->userId = $userId;
|
||||
$this->config = $config;
|
||||
$this->request = $request;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a value by key
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAppValue($key) {
|
||||
$defaultValue = null;
|
||||
if (array_key_exists($key, $this->defaults)) {
|
||||
$defaultValue = $this->defaults[$key];
|
||||
}
|
||||
|
||||
return $this->config->getAppValue(Application::APP_NAME, $key, $defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a value by key
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAppValue($key, $value) {
|
||||
$this->config->setAppValue(Application::APP_NAME, $key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a key
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function deleteAppValue($key) {
|
||||
return $this->config->deleteAppValue(Application::APP_NAME, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user value by key
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUserValue($key) {
|
||||
$defaultValue = null;
|
||||
if (array_key_exists($key, $this->defaults)) {
|
||||
$defaultValue = $this->defaults[$key];
|
||||
}
|
||||
|
||||
return $this->config->getUserValue(
|
||||
$this->userId, Application::APP_NAME, $key, $defaultValue
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a user value by key
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
* @throws PreConditionNotMetException
|
||||
*/
|
||||
public function setUserValue($key, $value) {
|
||||
return $this->config->setUserValue($this->userId, Application::APP_NAME, $key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user value by key and user
|
||||
*
|
||||
* @param string $userId
|
||||
* @param string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueForUser($userId, $key) {
|
||||
return $this->config->getUserValue($userId, Application::APP_NAME, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a user value by key
|
||||
*
|
||||
* @param string $userId
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
* @throws PreConditionNotMetException
|
||||
*/
|
||||
public function setValueForUser($userId, $key, $value) {
|
||||
return $this->config->setUserValue($userId, Application::APP_NAME, $key, $value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getSystemValue($key) {
|
||||
return $this->config->getSystemValue($key, '');
|
||||
}
|
||||
|
||||
public function getCloudAddress() {
|
||||
return $this->request->getServerHost();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return array
|
||||
// */
|
||||
// public function getServiceTypes(): array {
|
||||
// return $this->serviceTypes;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,198 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Service;
|
||||
|
||||
|
||||
use daita\Model\Request;
|
||||
use OCA\Social\Exceptions\InvalidAccessTokenException;
|
||||
use OCA\Social\Exceptions\MovedPermanentlyException;
|
||||
use OCA\Social\Model\ServiceAccount;
|
||||
|
||||
class CurlService {
|
||||
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* CurlService constructor.
|
||||
*
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(MiscService $miscService) {
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceAccount $account
|
||||
* @param Request $request
|
||||
* @param bool $authed
|
||||
*
|
||||
* @return array
|
||||
* @throws InvalidAccessTokenException
|
||||
* @throws MovedPermanentlyException
|
||||
*/
|
||||
public function request(ServiceAccount $account, Request $request, bool $authed = true) {
|
||||
|
||||
$curl = $this->initRequest($account, $request, $authed);
|
||||
$this->initRequestPost($curl, $request);
|
||||
$this->initRequestPut($curl, $request);
|
||||
$this->initRequestDelete($curl, $request);
|
||||
|
||||
$result = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
|
||||
$this->parseRequestResultCode301($code);
|
||||
$this->parseRequestResultCode401($code);
|
||||
// $this->parseRequestResultCode503($code);
|
||||
// $this->parseRequestResultCode500($code);
|
||||
// $this->parseRequestResult($result);
|
||||
|
||||
return json_decode($result, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceAccount $account
|
||||
* @param Request $request
|
||||
* @param bool $authed
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
private function initRequest(ServiceAccount $account, Request $request, bool $authed) {
|
||||
|
||||
$curl = $this->generateCurlRequest($account, $request);
|
||||
$headers = [];
|
||||
|
||||
if ($authed) {
|
||||
$headers[] = 'Authorization: Bearer ' . $account->getAuth('token');
|
||||
}
|
||||
|
||||
|
||||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
|
||||
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
return $curl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ServiceAccount $account
|
||||
* @param Request $request
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
private function generateCurlRequest(ServiceAccount $account, Request $request) {
|
||||
|
||||
$service = $account->getService();
|
||||
// $service->setAddress('mastodon.social');
|
||||
$url = 'https://' . $service->getAddress() . $request->getUrl();
|
||||
|
||||
if ($request->getType() !== Request::TYPE_GET) {
|
||||
$curl = curl_init($url);
|
||||
} else {
|
||||
$curl = curl_init($url . '?' . $request->getDataBody());
|
||||
}
|
||||
|
||||
return $curl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param resource $curl
|
||||
* @param Request $request
|
||||
*/
|
||||
private function initRequestPost($curl, Request $request) {
|
||||
if ($request->getType() !== Request::TYPE_POST) {
|
||||
return;
|
||||
}
|
||||
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getDataBody());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param resource $curl
|
||||
* @param Request $request
|
||||
*/
|
||||
private function initRequestPut($curl, Request $request) {
|
||||
if ($request->getType() !== Request::TYPE_PUT) {
|
||||
return;
|
||||
}
|
||||
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getDataBody());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param resource $curl
|
||||
* @param Request $request
|
||||
*/
|
||||
private function initRequestDelete($curl, Request $request) {
|
||||
if ($request->getType() !== Request::TYPE_DELETE) {
|
||||
return;
|
||||
}
|
||||
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getDataBody());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $code
|
||||
*
|
||||
* @throws MovedPermanentlyException
|
||||
*/
|
||||
private function parseRequestResultCode301($code) {
|
||||
if ($code === 301) {
|
||||
throw new MovedPermanentlyException('301 Moved Permanently');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $code
|
||||
*
|
||||
* @throws InvalidAccessTokenException
|
||||
*/
|
||||
private function parseRequestResultCode401($code) {
|
||||
if ($code === 401) {
|
||||
throw new InvalidAccessTokenException('401 Access Token Invalid');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Service;
|
||||
|
||||
use OCA\Social\AppInfo\Application;
|
||||
use OCP\ILogger;
|
||||
|
||||
class MiscService {
|
||||
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
|
||||
/**
|
||||
* MiscService constructor.
|
||||
*
|
||||
* @param ILogger $logger
|
||||
*/
|
||||
public function __construct(ILogger $logger) {
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $message
|
||||
* @param int $level
|
||||
*/
|
||||
public function log($message, $level = 2) {
|
||||
$data = array(
|
||||
'app' => Application::APP_NAME,
|
||||
'level' => $level
|
||||
);
|
||||
|
||||
$this->logger->log($level, $message, $data);
|
||||
}
|
||||
|
||||
|
||||
public static function noEndSlash($path) {
|
||||
if (substr($path, -1) === '/') {
|
||||
$path = substr($path, 0, -1);
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,200 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Service;
|
||||
|
||||
|
||||
use daita\Traits\TArrayTools;
|
||||
use Exception;
|
||||
use Lrf141\OAuth2\Client\Provider\Mastodon;
|
||||
use OCA\Social\Db\ServiceAccountsRequest;
|
||||
use OCA\Social\Db\ServicesRequest;
|
||||
use OCA\Social\Exceptions\ServiceAccountAlreadyExistException;
|
||||
use OCA\Social\Exceptions\ServiceAccountDoesNotExistException;
|
||||
use OCA\Social\Exceptions\ServiceAccountException;
|
||||
use OCA\Social\Model\Service;
|
||||
use OCA\Social\Model\ServiceAccount;
|
||||
use OCA\Social\Traits\TOAuth2;
|
||||
|
||||
class ServiceAccountsService {
|
||||
|
||||
|
||||
use TOAuth2;
|
||||
use TArrayTools;
|
||||
|
||||
|
||||
/** @var ServicesRequest */
|
||||
private $servicesRequest;
|
||||
|
||||
/** @var ServiceAccountsRequest */
|
||||
private $serviceAccountsRequest;
|
||||
|
||||
/** @var ActivityStreamsService */
|
||||
private $activityStreamsService;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* ServiceAccountsService constructor.
|
||||
*
|
||||
* @param ServicesRequest $servicesRequest
|
||||
* @param ServiceAccountsRequest $serviceAccountsRequest
|
||||
* @param ActivityStreamsService $activityStreamsService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
ServicesRequest $servicesRequest, ServiceAccountsRequest $serviceAccountsRequest,
|
||||
ActivityStreamsService $activityStreamsService, MiscService $miscService
|
||||
) {
|
||||
$this->servicesRequest = $servicesRequest;
|
||||
$this->serviceAccountsRequest = $serviceAccountsRequest;
|
||||
$this->activityStreamsService = $activityStreamsService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
*
|
||||
* @return ServiceAccount[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getAvailableAccounts(string $userId): array {
|
||||
$service = $this->serviceAccountsRequest->getAvailableAccounts($userId);
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
* @param int $accountId
|
||||
*
|
||||
* @return ServiceAccount
|
||||
* @throws ServiceAccountDoesNotExistException
|
||||
*/
|
||||
public function getAccount(string $userId, int $accountId): ServiceAccount {
|
||||
$account = $this->serviceAccountsRequest->getAccount($accountId);
|
||||
|
||||
if ($account->getUserId() !== $userId) {
|
||||
throw new ServiceAccountDoesNotExistException('Wrong owner');
|
||||
}
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Service $service
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthorizationUrl(Service $service): string {
|
||||
$mastodon = $this->generateMastodonAuth($service);
|
||||
|
||||
return $mastodon->getAuthorizationUrl();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
* @param int $serviceId
|
||||
* @param string $code
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function generateAccount(string $userId, int $serviceId, string $code) {
|
||||
|
||||
$service = $this->servicesRequest->getService($serviceId);
|
||||
$mastodon = $this->generateMastodonAuth($service);
|
||||
|
||||
$token =
|
||||
$mastodon->getAccessToken('authorization_code', ['code' => $code]);
|
||||
|
||||
$account = new ServiceAccount();
|
||||
$account->setAuth('token', $token->getToken());
|
||||
// $account->setAuth('refresh_token', $token->getRefreshToken());
|
||||
$account->setService($service);
|
||||
$account->setUserId($userId);
|
||||
$account->setStatus(1);
|
||||
|
||||
$info = $this->activityStreamsService->getAccountInformation($account);
|
||||
$accountName = '@' . $this->get('username', $info, '');
|
||||
$this->checkAccountUniqueness($serviceId, $userId, $accountName);
|
||||
|
||||
$account->setAccount($accountName);
|
||||
$this->serviceAccountsRequest->create($account);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $serviceId
|
||||
* @param string $userId
|
||||
* @param string $accountName
|
||||
*
|
||||
* @throws ServiceAccountAlreadyExistException
|
||||
* @throws ServiceAccountException
|
||||
*/
|
||||
private function checkAccountUniqueness(int $serviceId, string $userId, string $accountName) {
|
||||
|
||||
if ($accountName === '@') {
|
||||
throw new ServiceAccountException('Account name is not valid');
|
||||
}
|
||||
|
||||
try {
|
||||
$this->serviceAccountsRequest->getFromAccountName($serviceId, $userId, $accountName);
|
||||
throw new ServiceAccountAlreadyExistException('This account already exist');
|
||||
} catch (ServiceAccountDoesNotExistException $e) {
|
||||
/** we do nohtin' */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Service $service
|
||||
*
|
||||
* @return Mastodon
|
||||
*/
|
||||
private function generateMastodonAuth(Service $service): Mastodon {
|
||||
return new Mastodon(
|
||||
[
|
||||
'clientId' => $service->getConfig('clientKey'),
|
||||
'clientSecret' => $service->getConfig('clientSecret'),
|
||||
'redirectUri' => $this->generateRedirectUrl($service->getId()),
|
||||
'instance' => 'https://' . $service->getAddress(),
|
||||
'scope' => 'read write follow'
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,244 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Service;
|
||||
|
||||
|
||||
use daita\Model\Request;
|
||||
use daita\Traits\TArrayTools;
|
||||
use Exception;
|
||||
use OCA\Social\Db\ServicesRequest;
|
||||
use OCA\Social\Exceptions\MissingStuffException;
|
||||
use OCA\Social\Exceptions\ServiceDoesNotExistException;
|
||||
use OCA\Social\Model\Service;
|
||||
use OCA\Social\Model\ServiceAccount;
|
||||
use OCA\Social\Traits\TOAuth2;
|
||||
|
||||
class ServicesService {
|
||||
|
||||
|
||||
use TOAuth2;
|
||||
use TArrayTools;
|
||||
|
||||
|
||||
/** @var ServicesRequest */
|
||||
private $servicesRequest;
|
||||
|
||||
/** @var ConfigService */
|
||||
private $configService;
|
||||
|
||||
/** @var CurlService */
|
||||
private $curlService;
|
||||
|
||||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
|
||||
/**
|
||||
* ServicesService constructor.
|
||||
*
|
||||
* @param ServicesRequest $servicesRequest
|
||||
* @param ConfigService $configService
|
||||
* @param CurlService $curlService
|
||||
* @param MiscService $miscService
|
||||
*/
|
||||
public function __construct(
|
||||
ServicesRequest $servicesRequest, ConfigService $configService, CurlService $curlService,
|
||||
MiscService $miscService
|
||||
) {
|
||||
$this->servicesRequest = $servicesRequest;
|
||||
$this->configService = $configService;
|
||||
$this->curlService = $curlService;
|
||||
$this->miscService = $miscService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $instance
|
||||
*
|
||||
* @return Service
|
||||
* @throws Exception
|
||||
*/
|
||||
public function createFromInstance(string $instance) {
|
||||
try {
|
||||
$service = $this->servicesRequest->getServiceFromInstance($instance);
|
||||
|
||||
if ($service->getStatus() !== Service::STATUS_VALID) {
|
||||
$this->servicesRequest->delete($service->getId());
|
||||
throw new ServiceDoesNotExistException();
|
||||
}
|
||||
} catch (ServiceDoesNotExistException $e) {
|
||||
|
||||
$service = $this->createService('mastodon', $instance);
|
||||
$app = $this->createAppOnService($service);
|
||||
|
||||
$service->setConfig('clientKey', $this->get('client_id', $app, ''))
|
||||
->setConfig('clientSecret', $this->get('client_secret', $app, ''))
|
||||
->unsetConfig('redirectUrl')
|
||||
->setStatus(Service::STATUS_VALID);
|
||||
$this->servicesRequest->update($service);
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $address
|
||||
*
|
||||
* @return Service
|
||||
* @throws Exception
|
||||
*/
|
||||
public function createService(string $type, string $address): Service {
|
||||
if ($type === '' || $address === '') {
|
||||
throw new MissingStuffException('missing some data');
|
||||
}
|
||||
|
||||
$serviceId = $this->servicesRequest->create($type, $address);
|
||||
|
||||
$service = $this->servicesRequest->getService($serviceId);
|
||||
$service->setConfig('redirectUrl', $this->generateRedirectUrl($serviceId));
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Service $service
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function createAppOnService(Service $service) {
|
||||
|
||||
$account = new ServiceAccount();
|
||||
$account->setService($service);
|
||||
|
||||
$this->miscService->log('___' . $this->configService->getCloudAddress());
|
||||
|
||||
$data = [
|
||||
'client_name' => 'Social@' . $this->configService->getCloudAddress(),
|
||||
'redirect_uris' => $this->generateRedirectUrl($service->getId()),
|
||||
'scopes' => 'read write follow',
|
||||
'website' => 'https://' . $this->configService->getCloudAddress() . '/'
|
||||
];
|
||||
|
||||
$request = new Request(ActivityStreamsService::URL_CREATE_APP, Request::TYPE_POST);
|
||||
$request->setData($data);
|
||||
|
||||
return $this->curlService->request($account, $request, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $serviceId
|
||||
*
|
||||
* @return Service
|
||||
* @throws ServiceDoesNotExistException
|
||||
*/
|
||||
public function getService(int $serviceId): Service {
|
||||
$service = $this->servicesRequest->getService($serviceId);
|
||||
$service->setConfig('redirectUrl', $this->generateRedirectUrl($serviceId));
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $serviceId
|
||||
* @param array $data
|
||||
*
|
||||
* @return Service
|
||||
* @throws ServiceDoesNotExistException
|
||||
*/
|
||||
public function editService(int $serviceId, array $data): Service {
|
||||
|
||||
$service = $this->servicesRequest->getService($serviceId);
|
||||
|
||||
$service->setAddress($this->get('address', $data, ''));
|
||||
$service->setConfig('clientKey', trim($this->get('clientKey', $data, '')));
|
||||
$service->setConfig('clientSecret', trim($this->get('clientSecret', $data, '')));
|
||||
|
||||
$this->validateService($service);
|
||||
$this->servicesRequest->update($service);
|
||||
|
||||
$service->setConfig('redirectUrl', $this->generateRedirectUrl($serviceId));
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Service $service
|
||||
*/
|
||||
private function validateService(Service &$service) {
|
||||
if ($service->getStatus() === 1
|
||||
|| $service->getConfig('clientKey', '') === ''
|
||||
|| $service->getConfig('clientSecret', '') === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$service->setStatus(1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $serviceId
|
||||
*
|
||||
* @return Service[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function removeService(int $serviceId): array {
|
||||
$this->servicesRequest->delete($serviceId);
|
||||
|
||||
return $this->servicesRequest->getServices();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getServices(): array {
|
||||
return $this->servicesRequest->getServices();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getAvailableServices(): array {
|
||||
return $this->servicesRequest->getServices(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,196 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace daita\Model;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
class Request implements \JsonSerializable {
|
||||
|
||||
const TYPE_GET = 0;
|
||||
const TYPE_POST = 1;
|
||||
const TYPE_PUT = 2;
|
||||
const TYPE_DELETE = 3;
|
||||
|
||||
/** @var string */
|
||||
private $address;
|
||||
|
||||
/** @var int */
|
||||
private $url;
|
||||
|
||||
/** @var int */
|
||||
private $type;
|
||||
|
||||
/** @var array */
|
||||
private $data = [];
|
||||
|
||||
|
||||
/**
|
||||
* Request constructor.
|
||||
*
|
||||
* @param string $url
|
||||
* @param int $type
|
||||
*/
|
||||
public function __construct($url, $type = 0) {
|
||||
$this->url = $url;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAddress(): string {
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $address
|
||||
*
|
||||
* @return Request
|
||||
*/
|
||||
public function setAddress(string $address): Request {
|
||||
$this->address = $address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl(): string {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getType(): int {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getData(): array {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Request
|
||||
*/
|
||||
public function setData(array $data): Request {
|
||||
$this->data = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
*
|
||||
* @return Request
|
||||
*/
|
||||
public function setDataJson(string $data): Request {
|
||||
$this->setData(json_decode($data, true));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param JsonSerializable $data
|
||||
*
|
||||
* @return Request
|
||||
*/
|
||||
public function setDataSerialize(JsonSerializable $data): Request {
|
||||
$this->setDataJson(json_encode($data));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
* @param string $v
|
||||
*
|
||||
* @return Request
|
||||
*/
|
||||
public function addData(string $k, string $v): Request {
|
||||
$this->data[$k] = $v;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
* @param int $v
|
||||
*
|
||||
* @return Request
|
||||
*/
|
||||
public function addDataInt(string $k, int $v): Request {
|
||||
$this->data[$k] = $v;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDataBody() {
|
||||
|
||||
if ($this->getData() === []) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return preg_replace(
|
||||
'/([(%5B)]{1})[0-9]+([(%5D)]{1})/', '$1$2', http_build_query($this->getData())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function jsonSerialize() {
|
||||
return [
|
||||
'url' => $this->getUrl(),
|
||||
'type' => $this->getType(),
|
||||
'data' => $this->getData()
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace daita\Traits;
|
||||
|
||||
|
||||
trait TArrayTools {
|
||||
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
* @param array $arr
|
||||
* @param string $default
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get(string $k, array $arr, string $default = '') {
|
||||
if ($arr === null) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
if (!key_exists($k, $arr) || $arr[$k] === null) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return $arr[$k];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
* @param array $arr
|
||||
* @param int $default
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function getInt(string $k, array $arr, int $default = 0) {
|
||||
if ($arr === null) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
if (!key_exists($k, $arr) || $arr[$k] === null) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return intval($arr[$k]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
* @param array $arr
|
||||
* @param bool $default
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function getBool(string $k, array $arr, bool $default = false) {
|
||||
if ($arr === null) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
if (!key_exists($k, $arr)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return $arr[$k];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $k
|
||||
* @param array $arr
|
||||
* @param array $default
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getArray(string $k, array $arr, array $default = []) {
|
||||
if ($arr === null) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
if (!key_exists($k, $arr)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$r = $arr[$k];
|
||||
if ($r === null || !is_array($r)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace daita\Traits;
|
||||
|
||||
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
|
||||
trait TNCDataResponse {
|
||||
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
private function fail(string $message = ''): DataResponse {
|
||||
return new DataResponse(
|
||||
['status' => -1, 'message' => $message], Http::STATUS_NON_AUTHORATIVE_INFORMATION
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $result
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
private function success(array $result): DataResponse {
|
||||
$data =
|
||||
[
|
||||
'result' => $result,
|
||||
'status' => 1
|
||||
];
|
||||
|
||||
return new DataResponse($data, Http::STATUS_CREATED);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Social\Traits;
|
||||
|
||||
|
||||
trait TOAuth2 {
|
||||
|
||||
|
||||
/**
|
||||
* @param int $serviceId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateRedirectUrl(int $serviceId): string {
|
||||
return \OC::$server->getURlGenerator()
|
||||
->linkToRouteAbsolute(
|
||||
'social.OAuth2.setCode',
|
||||
['serviceId' => $serviceId]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* Nextcloud - Social Support
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param $dir
|
||||
*/
|
||||
function loadPHPFiles($dir) {
|
||||
try {
|
||||
$files = scandir($dir);
|
||||
} catch (Exception $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (substr($file, 0, 1) === '.' || $file === 'autoload.php') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = $dir . '/' . $file;
|
||||
if (is_dir($path)) {
|
||||
loadPHPFiles($path);
|
||||
} else {
|
||||
require_once($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadPHPFiles(__DIR__ . '/Tools');
|
||||
//loadPHPFiles(__DIR__ . '/Authentication');
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptLibraryMappings">
|
||||
<includedPredefinedLibrary name="ECMAScript 6" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -7,6 +7,12 @@
|
|||
</div>
|
||||
<div id="app-content">
|
||||
<div class="social__container">
|
||||
Add an account:
|
||||
<input type="text" id="social-instance-new-account" placeholder="mastodon.social" />
|
||||
<input type="submit" id="social-submit-new-account" /><br />
|
||||
|
||||
Accounts: <select id="social-list-accounts"></select><input type="submit" id="social-submit-account-test" value="Test this account" /><br />
|
||||
|
||||
<h2>🎉 Nextcloud becomes part of the federated social networks!</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
script('social', 'social');
|
||||
script('social', 'test');
|
||||
style('social', 'style');
|
||||
?>
|
||||
<div id="vue-content"></div>
|
||||
|
|
Ładowanie…
Reference in New Issue