diff options
author | Robin Appelman <icewind@owncloud.com> | 2016-01-19 14:16:11 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2016-01-29 14:51:30 +0100 |
commit | 860d51487b103f4c050d2427c35ee70dd4b2b05e (patch) | |
tree | a59988eaaba438fa2fa5dbb6ac574d81cc2fb047 /apps/files_external/lib | |
parent | f3e9729a5f68fa36ee6633955b7913f37e1c890e (diff) | |
download | nextcloud-server-860d51487b103f4c050d2427c35ee70dd4b2b05e.tar.gz nextcloud-server-860d51487b103f4c050d2427c35ee70dd4b2b05e.zip |
Allow setting user provided credentials from the personal settings page
Diffstat (limited to 'apps/files_external/lib')
-rw-r--r-- | apps/files_external/lib/auth/password/userprovided.php | 9 | ||||
-rw-r--r-- | apps/files_external/lib/definitionparameter.php | 48 |
2 files changed, 33 insertions, 24 deletions
diff --git a/apps/files_external/lib/auth/password/userprovided.php b/apps/files_external/lib/auth/password/userprovided.php index 8854513e161..b0ff50a279a 100644 --- a/apps/files_external/lib/auth/password/userprovided.php +++ b/apps/files_external/lib/auth/password/userprovided.php @@ -21,6 +21,7 @@ namespace OCA\Files_External\Lib\Auth\Password; +use OCA\Files_External\Lib\DefinitionParameter; use OCP\IL10N; use OCP\IUser; use OCA\Files_External\Lib\Auth\AuthMechanism; @@ -46,7 +47,13 @@ class UserProvided extends AuthMechanism { ->setIdentifier('password::userprovided') ->setScheme(self::SCHEME_PASSWORD) ->setText($l->t('User provided')) - ->addParameters([]); + ->addParameters([ + (new DefinitionParameter('user', $l->t('Username'))) + ->setFlag(DefinitionParameter::FLAG_USER_PROVIDED), + (new DefinitionParameter('password', $l->t('Password'))) + ->setType(DefinitionParameter::VALUE_PASSWORD) + ->setFlag(DefinitionParameter::FLAG_USER_PROVIDED), + ]); } private function getCredentialsIdentifier($storageId) { diff --git a/apps/files_external/lib/definitionparameter.php b/apps/files_external/lib/definitionparameter.php index 59a098e6320..85c3dd08ad4 100644 --- a/apps/files_external/lib/definitionparameter.php +++ b/apps/files_external/lib/definitionparameter.php @@ -35,6 +35,7 @@ class DefinitionParameter implements \JsonSerializable { /** Flag constants */ const FLAG_NONE = 0; const FLAG_OPTIONAL = 1; + const FLAG_USER_PROVIDED = 2; /** @var string name of parameter */ private $name; @@ -121,7 +122,7 @@ class DefinitionParameter implements \JsonSerializable { * @return bool */ public function isFlagSet($flag) { - return (bool) $this->flags & $flag; + return (bool)($this->flags & $flag); } /** @@ -143,10 +144,11 @@ class DefinitionParameter implements \JsonSerializable { break; } - switch ($this->getFlags()) { - case self::FLAG_OPTIONAL: - $prefix = '&' . $prefix; - break; + if ($this->isFlagSet(self::FLAG_OPTIONAL)) { + $prefix = '&' . $prefix; + } + if ($this->isFlagSet(self::FLAG_USER_PROVIDED)) { + $prefix = '@' . $prefix; } return $prefix . $this->getText(); @@ -160,28 +162,28 @@ class DefinitionParameter implements \JsonSerializable { * @return bool success */ public function validateValue(&$value) { - $optional = $this->getFlags() & self::FLAG_OPTIONAL; + $optional = $this->isFlagSet(self::FLAG_OPTIONAL) || $this->isFlagSet(self::FLAG_USER_PROVIDED); switch ($this->getType()) { - case self::VALUE_BOOLEAN: - if (!is_bool($value)) { - switch ($value) { - case 'true': - $value = true; - break; - case 'false': - $value = false; - break; - default: + case self::VALUE_BOOLEAN: + if (!is_bool($value)) { + switch ($value) { + case 'true': + $value = true; + break; + case 'false': + $value = false; + break; + default: + return false; + } + } + break; + default: + if (!$value && !$optional) { return false; } - } - break; - default: - if (!$value && !$optional) { - return false; - } - break; + break; } return true; } |