diff --git a/apps/files_external/appinfo/routes.php b/apps/files_external/appinfo/routes.php
index 68924ba2c6bc0..1062ae524fffa 100644
--- a/apps/files_external/appinfo/routes.php
+++ b/apps/files_external/appinfo/routes.php
@@ -42,7 +42,12 @@
'url' => '/ajax/public_key.php',
'verb' => 'POST',
'requirements' => array()
- )
+ ),
+ [
+ 'name' => 'Ajax#saveGlobalCredentials',
+ 'url' => '/globalcredentials',
+ 'verb' => 'POST',
+ ],
)
)
);
diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js
index d210c158ec125..921bf92e775ef 100644
--- a/apps/files_external/js/settings.js
+++ b/apps/files_external/js/settings.js
@@ -1347,6 +1347,33 @@ $(document).ready(function() {
}
});
+ $('#global_credentials').on('submit', function() {
+ var $form = $(this);
+ var uid = $form.find('[name=uid]').val();
+ var user = $form.find('[name=username]').val();
+ var password = $form.find('[name=password]').val();
+ var $submit = $form.find('[type=submit]');
+ $submit.val(t('files_external', 'Saving...'));
+ $.ajax({
+ type: 'POST',
+ contentType: 'application/json',
+ data: JSON.stringify({
+ uid: uid,
+ user: user,
+ password: password
+ }),
+ url: OC.generateUrl('apps/files_external/globalcredentials'),
+ dataType: 'json',
+ success: function() {
+ $submit.val(t('files_external', 'Saved'));
+ setTimeout(function(){
+ $submit.val(t('files_external', 'Save'));
+ }, 2500);
+ }
+ });
+ return false;
+ });
+
// global instance
OCA.External.Settings.mountConfig = mountConfigListView;
diff --git a/apps/files_external/lib/AppInfo/Application.php b/apps/files_external/lib/AppInfo/Application.php
index f78411038fa77..ee773d03d8ca7 100644
--- a/apps/files_external/lib/AppInfo/Application.php
+++ b/apps/files_external/lib/AppInfo/Application.php
@@ -112,6 +112,7 @@ public function getAuthMechanisms() {
// AuthMechanism::SCHEME_PASSWORD mechanisms
$container->query('OCA\Files_External\Lib\Auth\Password\Password'),
$container->query('OCA\Files_External\Lib\Auth\Password\SessionCredentials'),
+ $container->query('OCA\Files_External\Lib\Auth\Password\GlobalAuth'),
// AuthMechanism::SCHEME_OAUTH1 mechanisms
$container->query('OCA\Files_External\Lib\Auth\OAuth1\OAuth1'),
diff --git a/apps/files_external/lib/Controller/AjaxController.php b/apps/files_external/lib/Controller/AjaxController.php
index c3df3fa8522dd..8dcfb2a47eb8e 100644
--- a/apps/files_external/lib/Controller/AjaxController.php
+++ b/apps/files_external/lib/Controller/AjaxController.php
@@ -24,6 +24,7 @@
namespace OCA\Files_External\Controller;
+use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
use OCP\AppFramework\Controller;
use OCP\IRequest;
use OCP\AppFramework\Http\JSONResponse;
@@ -32,10 +33,16 @@
class AjaxController extends Controller {
/** @var RSA */
private $rsaMechanism;
+ /** @var GlobalAuth */
+ private $globalAuth;
- public function __construct($appName, IRequest $request, RSA $rsaMechanism) {
+ public function __construct($appName,
+ IRequest $request,
+ RSA $rsaMechanism,
+ GlobalAuth $globalAuth) {
parent::__construct($appName, $request);
$this->rsaMechanism = $rsaMechanism;
+ $this->globalAuth = $globalAuth;
}
private function generateSshKeys() {
@@ -61,4 +68,15 @@ public function getSshKeys() {
'status' => 'success'
));
}
+
+ /**
+ * @param string $uid
+ * @param string $user
+ * @param string $password
+ * @return bool
+ */
+ public function saveGlobalCredentials($uid, $user, $password) {
+ $this->globalAuth->saveAuth($uid, $user, $password);
+ return true;
+ }
}
diff --git a/apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php b/apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php
new file mode 100644
index 0000000000000..5fa4dc5d1d457
--- /dev/null
+++ b/apps/files_external/lib/Lib/Auth/Password/GlobalAuth.php
@@ -0,0 +1,88 @@
+
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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, version 3,
+ * along with this program. If not, see