@@ -34,8 +34,8 @@ |
||
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * Constructor |
| 37 | - * @param string $msg the error message |
|
| 38 | 37 | * @since 15.0.0 |
| 38 | + * @param string $property |
|
| 39 | 39 | */ |
| 40 | 40 | public function __construct($property){ |
| 41 | 41 | parent::__construct('Property ' . $property . ' does not exist.'); |
@@ -32,13 +32,13 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class PropertyDoesNotExistException extends \Exception { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Constructor |
|
| 37 | - * @param string $msg the error message |
|
| 38 | - * @since 15.0.0 |
|
| 39 | - */ |
|
| 40 | - public function __construct($property){ |
|
| 41 | - parent::__construct('Property ' . $property . ' does not exist.'); |
|
| 42 | - } |
|
| 35 | + /** |
|
| 36 | + * Constructor |
|
| 37 | + * @param string $msg the error message |
|
| 38 | + * @since 15.0.0 |
|
| 39 | + */ |
|
| 40 | + public function __construct($property){ |
|
| 41 | + parent::__construct('Property ' . $property . ' does not exist.'); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | } |
@@ -37,8 +37,8 @@ |
||
| 37 | 37 | * @param string $msg the error message |
| 38 | 38 | * @since 15.0.0 |
| 39 | 39 | */ |
| 40 | - public function __construct($property){ |
|
| 41 | - parent::__construct('Property ' . $property . ' does not exist.'); |
|
| 40 | + public function __construct($property) { |
|
| 41 | + parent::__construct('Property '.$property.' does not exist.'); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | } |
@@ -37,33 +37,33 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | interface IAccountManager { |
| 39 | 39 | |
| 40 | - /** nobody can see my account details */ |
|
| 41 | - const VISIBILITY_PRIVATE = 'private'; |
|
| 42 | - /** only contacts, especially trusted servers can see my contact details */ |
|
| 43 | - const VISIBILITY_CONTACTS_ONLY = 'contacts'; |
|
| 44 | - /** every body ca see my contact detail, will be published to the lookup server */ |
|
| 45 | - const VISIBILITY_PUBLIC = 'public'; |
|
| 40 | + /** nobody can see my account details */ |
|
| 41 | + const VISIBILITY_PRIVATE = 'private'; |
|
| 42 | + /** only contacts, especially trusted servers can see my contact details */ |
|
| 43 | + const VISIBILITY_CONTACTS_ONLY = 'contacts'; |
|
| 44 | + /** every body ca see my contact detail, will be published to the lookup server */ |
|
| 45 | + const VISIBILITY_PUBLIC = 'public'; |
|
| 46 | 46 | |
| 47 | - const PROPERTY_AVATAR = 'avatar'; |
|
| 48 | - const PROPERTY_DISPLAYNAME = 'displayname'; |
|
| 49 | - const PROPERTY_PHONE = 'phone'; |
|
| 50 | - const PROPERTY_EMAIL = 'email'; |
|
| 51 | - const PROPERTY_WEBSITE = 'website'; |
|
| 52 | - const PROPERTY_ADDRESS = 'address'; |
|
| 53 | - const PROPERTY_TWITTER = 'twitter'; |
|
| 47 | + const PROPERTY_AVATAR = 'avatar'; |
|
| 48 | + const PROPERTY_DISPLAYNAME = 'displayname'; |
|
| 49 | + const PROPERTY_PHONE = 'phone'; |
|
| 50 | + const PROPERTY_EMAIL = 'email'; |
|
| 51 | + const PROPERTY_WEBSITE = 'website'; |
|
| 52 | + const PROPERTY_ADDRESS = 'address'; |
|
| 53 | + const PROPERTY_TWITTER = 'twitter'; |
|
| 54 | 54 | |
| 55 | - const NOT_VERIFIED = '0'; |
|
| 56 | - const VERIFICATION_IN_PROGRESS = '1'; |
|
| 57 | - const VERIFIED = '2'; |
|
| 55 | + const NOT_VERIFIED = '0'; |
|
| 56 | + const VERIFICATION_IN_PROGRESS = '1'; |
|
| 57 | + const VERIFIED = '2'; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Get the account data for a given user |
|
| 61 | - * |
|
| 62 | - * @since 15.0.0 |
|
| 63 | - * |
|
| 64 | - * @param IUser $user |
|
| 65 | - * @return IAccount |
|
| 66 | - */ |
|
| 67 | - public function getAccount(IUser $user): IAccount; |
|
| 59 | + /** |
|
| 60 | + * Get the account data for a given user |
|
| 61 | + * |
|
| 62 | + * @since 15.0.0 |
|
| 63 | + * |
|
| 64 | + * @param IUser $user |
|
| 65 | + * @return IAccount |
|
| 66 | + */ |
|
| 67 | + public function getAccount(IUser $user): IAccount; |
|
| 68 | 68 | |
| 69 | 69 | } |
@@ -34,71 +34,71 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | interface IAccountProperty extends \JsonSerializable { |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Set the value of a property |
|
| 39 | - * |
|
| 40 | - * @since 15.0.0 |
|
| 41 | - * |
|
| 42 | - * @param string $value |
|
| 43 | - * @return IAccountProperty |
|
| 44 | - */ |
|
| 45 | - public function setValue(string $value): IAccountProperty; |
|
| 37 | + /** |
|
| 38 | + * Set the value of a property |
|
| 39 | + * |
|
| 40 | + * @since 15.0.0 |
|
| 41 | + * |
|
| 42 | + * @param string $value |
|
| 43 | + * @return IAccountProperty |
|
| 44 | + */ |
|
| 45 | + public function setValue(string $value): IAccountProperty; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Set the scope of a property |
|
| 49 | - * |
|
| 50 | - * @since 15.0.0 |
|
| 51 | - * |
|
| 52 | - * @param string $scope |
|
| 53 | - * @return IAccountProperty |
|
| 54 | - */ |
|
| 55 | - public function setScope(string $scope): IAccountProperty; |
|
| 47 | + /** |
|
| 48 | + * Set the scope of a property |
|
| 49 | + * |
|
| 50 | + * @since 15.0.0 |
|
| 51 | + * |
|
| 52 | + * @param string $scope |
|
| 53 | + * @return IAccountProperty |
|
| 54 | + */ |
|
| 55 | + public function setScope(string $scope): IAccountProperty; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Set the verification status of a property |
|
| 59 | - * |
|
| 60 | - * @since 15.0.0 |
|
| 61 | - * |
|
| 62 | - * @param string $verified |
|
| 63 | - * @return IAccountProperty |
|
| 64 | - */ |
|
| 65 | - public function setVerified(string $verified): IAccountProperty; |
|
| 57 | + /** |
|
| 58 | + * Set the verification status of a property |
|
| 59 | + * |
|
| 60 | + * @since 15.0.0 |
|
| 61 | + * |
|
| 62 | + * @param string $verified |
|
| 63 | + * @return IAccountProperty |
|
| 64 | + */ |
|
| 65 | + public function setVerified(string $verified): IAccountProperty; |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Get the name of a property |
|
| 69 | - * |
|
| 70 | - * @since 15.0.0 |
|
| 71 | - * |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - public function getName(): string; |
|
| 67 | + /** |
|
| 68 | + * Get the name of a property |
|
| 69 | + * |
|
| 70 | + * @since 15.0.0 |
|
| 71 | + * |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + public function getName(): string; |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Get the value of a property |
|
| 78 | - * |
|
| 79 | - * @since 15.0.0 |
|
| 80 | - * |
|
| 81 | - * @return string |
|
| 82 | - */ |
|
| 83 | - public function getValue(): string; |
|
| 76 | + /** |
|
| 77 | + * Get the value of a property |
|
| 78 | + * |
|
| 79 | + * @since 15.0.0 |
|
| 80 | + * |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 83 | + public function getValue(): string; |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Get the scope of a property |
|
| 87 | - * |
|
| 88 | - * @since 15.0.0 |
|
| 89 | - * |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - public function getScope(): string; |
|
| 85 | + /** |
|
| 86 | + * Get the scope of a property |
|
| 87 | + * |
|
| 88 | + * @since 15.0.0 |
|
| 89 | + * |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + public function getScope(): string; |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Get the verification status of a property |
|
| 96 | - * |
|
| 97 | - * @since 15.0.0 |
|
| 98 | - * |
|
| 99 | - * @return string |
|
| 100 | - */ |
|
| 101 | - public function getVerified(): string; |
|
| 94 | + /** |
|
| 95 | + * Get the verification status of a property |
|
| 96 | + * |
|
| 97 | + * @since 15.0.0 |
|
| 98 | + * |
|
| 99 | + * @return string |
|
| 100 | + */ |
|
| 101 | + public function getVerified(): string; |
|
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | |
@@ -36,57 +36,57 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | interface IAccount extends \JsonSerializable { |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Set a property with data |
|
| 41 | - * |
|
| 42 | - * @since 15.0.0 |
|
| 43 | - * |
|
| 44 | - * @param string $property Must be one of the PROPERTY_ prefixed constants of \OCP\Accounts\IAccountManager |
|
| 45 | - * @param string $value |
|
| 46 | - * @param string $scope Must be one of the VISIBILITY_ prefixed constants of \OCP\Accounts\IAccountManager |
|
| 47 | - * @param string $verified \OCP\Accounts\IAccountManager::NOT_VERIFIED | \OCP\Accounts\IAccountManager::VERIFICATION_IN_PROGRESS | \OCP\Accounts\IAccountManager::VERIFIED |
|
| 48 | - * @return IAccount |
|
| 49 | - */ |
|
| 50 | - public function setProperty(string $property, string $value, string $scope, string $verified): IAccount; |
|
| 39 | + /** |
|
| 40 | + * Set a property with data |
|
| 41 | + * |
|
| 42 | + * @since 15.0.0 |
|
| 43 | + * |
|
| 44 | + * @param string $property Must be one of the PROPERTY_ prefixed constants of \OCP\Accounts\IAccountManager |
|
| 45 | + * @param string $value |
|
| 46 | + * @param string $scope Must be one of the VISIBILITY_ prefixed constants of \OCP\Accounts\IAccountManager |
|
| 47 | + * @param string $verified \OCP\Accounts\IAccountManager::NOT_VERIFIED | \OCP\Accounts\IAccountManager::VERIFICATION_IN_PROGRESS | \OCP\Accounts\IAccountManager::VERIFIED |
|
| 48 | + * @return IAccount |
|
| 49 | + */ |
|
| 50 | + public function setProperty(string $property, string $value, string $scope, string $verified): IAccount; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Get a property by its key |
|
| 54 | - * |
|
| 55 | - * @since 15.0.0 |
|
| 56 | - * |
|
| 57 | - * @param string $property Must be one of the PROPERTY_ prefixed constants of \OCP\Accounts\IAccountManager |
|
| 58 | - * @return IAccountProperty |
|
| 59 | - * @throws PropertyDoesNotExistException |
|
| 60 | - */ |
|
| 61 | - public function getProperty(string $property): IAccountProperty; |
|
| 52 | + /** |
|
| 53 | + * Get a property by its key |
|
| 54 | + * |
|
| 55 | + * @since 15.0.0 |
|
| 56 | + * |
|
| 57 | + * @param string $property Must be one of the PROPERTY_ prefixed constants of \OCP\Accounts\IAccountManager |
|
| 58 | + * @return IAccountProperty |
|
| 59 | + * @throws PropertyDoesNotExistException |
|
| 60 | + */ |
|
| 61 | + public function getProperty(string $property): IAccountProperty; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Get all properties of an account |
|
| 65 | - * |
|
| 66 | - * @since 15.0.0 |
|
| 67 | - * |
|
| 68 | - * @return IAccountProperty[] |
|
| 69 | - */ |
|
| 70 | - public function getProperties(): array; |
|
| 63 | + /** |
|
| 64 | + * Get all properties of an account |
|
| 65 | + * |
|
| 66 | + * @since 15.0.0 |
|
| 67 | + * |
|
| 68 | + * @return IAccountProperty[] |
|
| 69 | + */ |
|
| 70 | + public function getProperties(): array; |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Get all properties that match the provided filters for scope and verification status |
|
| 74 | - * |
|
| 75 | - * @since 15.0.0 |
|
| 76 | - * |
|
| 77 | - * @param string $scope Must be one of the VISIBILITY_ prefixed constants of \OCP\Accounts\IAccountManager |
|
| 78 | - * @param string $verified \OCP\Accounts\IAccountManager::NOT_VERIFIED | \OCP\Accounts\IAccountManager::VERIFICATION_IN_PROGRESS | \OCP\Accounts\IAccountManager::VERIFIED |
|
| 79 | - * @return IAccountProperty[] |
|
| 80 | - */ |
|
| 81 | - public function getFilteredProperties(string $scope, string $verified): array; |
|
| 72 | + /** |
|
| 73 | + * Get all properties that match the provided filters for scope and verification status |
|
| 74 | + * |
|
| 75 | + * @since 15.0.0 |
|
| 76 | + * |
|
| 77 | + * @param string $scope Must be one of the VISIBILITY_ prefixed constants of \OCP\Accounts\IAccountManager |
|
| 78 | + * @param string $verified \OCP\Accounts\IAccountManager::NOT_VERIFIED | \OCP\Accounts\IAccountManager::VERIFICATION_IN_PROGRESS | \OCP\Accounts\IAccountManager::VERIFIED |
|
| 79 | + * @return IAccountProperty[] |
|
| 80 | + */ |
|
| 81 | + public function getFilteredProperties(string $scope, string $verified): array; |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Get the related user for the account data |
|
| 85 | - * |
|
| 86 | - * @since 15.0.0 |
|
| 87 | - * |
|
| 88 | - * @return IUser |
|
| 89 | - */ |
|
| 90 | - public function getUser(): IUser; |
|
| 83 | + /** |
|
| 84 | + * Get the related user for the account data |
|
| 85 | + * |
|
| 86 | + * @since 15.0.0 |
|
| 87 | + * |
|
| 88 | + * @return IUser |
|
| 89 | + */ |
|
| 90 | + public function getUser(): IUser; |
|
| 91 | 91 | |
| 92 | 92 | } |
@@ -33,49 +33,49 @@ |
||
| 33 | 33 | |
| 34 | 34 | class Account implements IAccount { |
| 35 | 35 | |
| 36 | - /** @var IAccountProperty[] */ |
|
| 37 | - private $properties = []; |
|
| 36 | + /** @var IAccountProperty[] */ |
|
| 37 | + private $properties = []; |
|
| 38 | 38 | |
| 39 | - /** @var IUser */ |
|
| 40 | - private $user; |
|
| 39 | + /** @var IUser */ |
|
| 40 | + private $user; |
|
| 41 | 41 | |
| 42 | - public function __construct(IUser $user) { |
|
| 43 | - $this->user = $user; |
|
| 44 | - } |
|
| 42 | + public function __construct(IUser $user) { |
|
| 43 | + $this->user = $user; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function setProperty(string $property, string $value, string $scope, string $verified): IAccount { |
|
| 47 | - $this->properties[$property] = new AccountProperty($property, $value, $scope, $verified); |
|
| 48 | - return $this; |
|
| 49 | - } |
|
| 46 | + public function setProperty(string $property, string $value, string $scope, string $verified): IAccount { |
|
| 47 | + $this->properties[$property] = new AccountProperty($property, $value, $scope, $verified); |
|
| 48 | + return $this; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function getProperty(string $property): IAccountProperty { |
|
| 52 | - if (!array_key_exists($property, $this->properties)) { |
|
| 53 | - throw new PropertyDoesNotExistException($property); |
|
| 54 | - } |
|
| 55 | - return $this->properties[$property]; |
|
| 56 | - } |
|
| 51 | + public function getProperty(string $property): IAccountProperty { |
|
| 52 | + if (!array_key_exists($property, $this->properties)) { |
|
| 53 | + throw new PropertyDoesNotExistException($property); |
|
| 54 | + } |
|
| 55 | + return $this->properties[$property]; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function getProperties(): array { |
|
| 59 | - return $this->properties; |
|
| 60 | - } |
|
| 58 | + public function getProperties(): array { |
|
| 59 | + return $this->properties; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function getFilteredProperties(string $scope = null, string $verified = null): array { |
|
| 63 | - return \array_filter($this->properties, function(IAccountProperty $obj) use ($scope, $verified){ |
|
| 64 | - if ($scope !== null && $scope !== $obj->getScope()) { |
|
| 65 | - return false; |
|
| 66 | - } |
|
| 67 | - if ($verified !== null && $verified !== $obj->getVerified()) { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 70 | - return true; |
|
| 71 | - }); |
|
| 72 | - } |
|
| 62 | + public function getFilteredProperties(string $scope = null, string $verified = null): array { |
|
| 63 | + return \array_filter($this->properties, function(IAccountProperty $obj) use ($scope, $verified){ |
|
| 64 | + if ($scope !== null && $scope !== $obj->getScope()) { |
|
| 65 | + return false; |
|
| 66 | + } |
|
| 67 | + if ($verified !== null && $verified !== $obj->getVerified()) { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | + return true; |
|
| 71 | + }); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - public function jsonSerialize() { |
|
| 75 | - return $this->properties; |
|
| 76 | - } |
|
| 74 | + public function jsonSerialize() { |
|
| 75 | + return $this->properties; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - public function getUser(): IUser { |
|
| 79 | - return $this->user; |
|
| 80 | - } |
|
| 78 | + public function getUser(): IUser { |
|
| 79 | + return $this->user; |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -30,111 +30,111 @@ |
||
| 30 | 30 | |
| 31 | 31 | class AccountProperty implements IAccountProperty { |
| 32 | 32 | |
| 33 | - /** @var string */ |
|
| 34 | - private $name; |
|
| 35 | - /** @var string */ |
|
| 36 | - private $value; |
|
| 37 | - /** @var string */ |
|
| 38 | - private $scope; |
|
| 39 | - /** @var string */ |
|
| 40 | - private $verified; |
|
| 33 | + /** @var string */ |
|
| 34 | + private $name; |
|
| 35 | + /** @var string */ |
|
| 36 | + private $value; |
|
| 37 | + /** @var string */ |
|
| 38 | + private $scope; |
|
| 39 | + /** @var string */ |
|
| 40 | + private $verified; |
|
| 41 | 41 | |
| 42 | - public function __construct(string $name, string $value, string $scope, string $verified) { |
|
| 43 | - $this->name = $name; |
|
| 44 | - $this->value = $value; |
|
| 45 | - $this->scope = $scope; |
|
| 46 | - $this->verified = $verified; |
|
| 47 | - } |
|
| 42 | + public function __construct(string $name, string $value, string $scope, string $verified) { |
|
| 43 | + $this->name = $name; |
|
| 44 | + $this->value = $value; |
|
| 45 | + $this->scope = $scope; |
|
| 46 | + $this->verified = $verified; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public function jsonSerialize() { |
|
| 50 | - return [ |
|
| 51 | - 'name' => $this->getName(), |
|
| 52 | - 'value' => $this->getValue(), |
|
| 53 | - 'scope' => $this->getScope(), |
|
| 54 | - 'verified' => $this->getVerified() |
|
| 55 | - ]; |
|
| 56 | - } |
|
| 49 | + public function jsonSerialize() { |
|
| 50 | + return [ |
|
| 51 | + 'name' => $this->getName(), |
|
| 52 | + 'value' => $this->getValue(), |
|
| 53 | + 'scope' => $this->getScope(), |
|
| 54 | + 'verified' => $this->getVerified() |
|
| 55 | + ]; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Set the value of a property |
|
| 60 | - * |
|
| 61 | - * @since 15.0.0 |
|
| 62 | - * |
|
| 63 | - * @param string $value |
|
| 64 | - * @return IAccountProperty |
|
| 65 | - */ |
|
| 66 | - public function setValue(string $value): IAccountProperty { |
|
| 67 | - $this->value = $value; |
|
| 68 | - return $this; |
|
| 69 | - } |
|
| 58 | + /** |
|
| 59 | + * Set the value of a property |
|
| 60 | + * |
|
| 61 | + * @since 15.0.0 |
|
| 62 | + * |
|
| 63 | + * @param string $value |
|
| 64 | + * @return IAccountProperty |
|
| 65 | + */ |
|
| 66 | + public function setValue(string $value): IAccountProperty { |
|
| 67 | + $this->value = $value; |
|
| 68 | + return $this; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Set the scope of a property |
|
| 73 | - * |
|
| 74 | - * @since 15.0.0 |
|
| 75 | - * |
|
| 76 | - * @param string $scope |
|
| 77 | - * @return IAccountProperty |
|
| 78 | - */ |
|
| 79 | - public function setScope(string $scope): IAccountProperty { |
|
| 80 | - $this->scope = $scope; |
|
| 81 | - return $this; |
|
| 82 | - } |
|
| 71 | + /** |
|
| 72 | + * Set the scope of a property |
|
| 73 | + * |
|
| 74 | + * @since 15.0.0 |
|
| 75 | + * |
|
| 76 | + * @param string $scope |
|
| 77 | + * @return IAccountProperty |
|
| 78 | + */ |
|
| 79 | + public function setScope(string $scope): IAccountProperty { |
|
| 80 | + $this->scope = $scope; |
|
| 81 | + return $this; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Set the verification status of a property |
|
| 86 | - * |
|
| 87 | - * @since 15.0.0 |
|
| 88 | - * |
|
| 89 | - * @param string $verified |
|
| 90 | - * @return IAccountProperty |
|
| 91 | - */ |
|
| 92 | - public function setVerified(string $verified): IAccountProperty { |
|
| 93 | - $this->verified = $verified; |
|
| 94 | - return $this; |
|
| 95 | - } |
|
| 84 | + /** |
|
| 85 | + * Set the verification status of a property |
|
| 86 | + * |
|
| 87 | + * @since 15.0.0 |
|
| 88 | + * |
|
| 89 | + * @param string $verified |
|
| 90 | + * @return IAccountProperty |
|
| 91 | + */ |
|
| 92 | + public function setVerified(string $verified): IAccountProperty { |
|
| 93 | + $this->verified = $verified; |
|
| 94 | + return $this; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Get the name of a property |
|
| 99 | - * |
|
| 100 | - * @since 15.0.0 |
|
| 101 | - * |
|
| 102 | - * @return string |
|
| 103 | - */ |
|
| 104 | - public function getName(): string { |
|
| 105 | - return $this->name; |
|
| 106 | - } |
|
| 97 | + /** |
|
| 98 | + * Get the name of a property |
|
| 99 | + * |
|
| 100 | + * @since 15.0.0 |
|
| 101 | + * |
|
| 102 | + * @return string |
|
| 103 | + */ |
|
| 104 | + public function getName(): string { |
|
| 105 | + return $this->name; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Get the value of a property |
|
| 110 | - * |
|
| 111 | - * @since 15.0.0 |
|
| 112 | - * |
|
| 113 | - * @return string |
|
| 114 | - */ |
|
| 115 | - public function getValue(): string { |
|
| 116 | - return $this->value; |
|
| 117 | - } |
|
| 108 | + /** |
|
| 109 | + * Get the value of a property |
|
| 110 | + * |
|
| 111 | + * @since 15.0.0 |
|
| 112 | + * |
|
| 113 | + * @return string |
|
| 114 | + */ |
|
| 115 | + public function getValue(): string { |
|
| 116 | + return $this->value; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * Get the scope of a property |
|
| 121 | - * |
|
| 122 | - * @since 15.0.0 |
|
| 123 | - * |
|
| 124 | - * @return string |
|
| 125 | - */ |
|
| 126 | - public function getScope(): string { |
|
| 127 | - return $this->scope; |
|
| 128 | - } |
|
| 119 | + /** |
|
| 120 | + * Get the scope of a property |
|
| 121 | + * |
|
| 122 | + * @since 15.0.0 |
|
| 123 | + * |
|
| 124 | + * @return string |
|
| 125 | + */ |
|
| 126 | + public function getScope(): string { |
|
| 127 | + return $this->scope; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Get the verification status of a property |
|
| 132 | - * |
|
| 133 | - * @since 15.0.0 |
|
| 134 | - * |
|
| 135 | - * @return string |
|
| 136 | - */ |
|
| 137 | - public function getVerified(): string { |
|
| 138 | - return $this->verified; |
|
| 139 | - } |
|
| 130 | + /** |
|
| 131 | + * Get the verification status of a property |
|
| 132 | + * |
|
| 133 | + * @since 15.0.0 |
|
| 134 | + * |
|
| 135 | + * @return string |
|
| 136 | + */ |
|
| 137 | + public function getVerified(): string { |
|
| 138 | + return $this->verified; |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -45,298 +45,298 @@ |
||
| 45 | 45 | */ |
| 46 | 46 | class AccountManager implements IAccountManager { |
| 47 | 47 | |
| 48 | - /** @var IDBConnection database connection */ |
|
| 49 | - private $connection; |
|
| 50 | - |
|
| 51 | - /** @var string table name */ |
|
| 52 | - private $table = 'accounts'; |
|
| 53 | - |
|
| 54 | - /** @var EventDispatcherInterface */ |
|
| 55 | - private $eventDispatcher; |
|
| 56 | - |
|
| 57 | - /** @var IJobList */ |
|
| 58 | - private $jobList; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * AccountManager constructor. |
|
| 62 | - * |
|
| 63 | - * @param IDBConnection $connection |
|
| 64 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 65 | - * @param IJobList $jobList |
|
| 66 | - */ |
|
| 67 | - public function __construct(IDBConnection $connection, |
|
| 68 | - EventDispatcherInterface $eventDispatcher, |
|
| 69 | - IJobList $jobList) { |
|
| 70 | - $this->connection = $connection; |
|
| 71 | - $this->eventDispatcher = $eventDispatcher; |
|
| 72 | - $this->jobList = $jobList; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * update user record |
|
| 77 | - * |
|
| 78 | - * @param IUser $user |
|
| 79 | - * @param $data |
|
| 80 | - */ |
|
| 81 | - public function updateUser(IUser $user, $data) { |
|
| 82 | - $userData = $this->getUser($user); |
|
| 83 | - $updated = true; |
|
| 84 | - if (empty($userData)) { |
|
| 85 | - $this->insertNewUser($user, $data); |
|
| 86 | - } elseif ($userData !== $data) { |
|
| 87 | - $data = $this->checkEmailVerification($userData, $data, $user); |
|
| 88 | - $data = $this->updateVerifyStatus($userData, $data); |
|
| 89 | - $this->updateExistingUser($user, $data); |
|
| 90 | - } else { |
|
| 91 | - // nothing needs to be done if new and old data set are the same |
|
| 92 | - $updated = false; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - if ($updated) { |
|
| 96 | - $this->eventDispatcher->dispatch( |
|
| 97 | - 'OC\AccountManager::userUpdated', |
|
| 98 | - new GenericEvent($user, $data) |
|
| 99 | - ); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * delete user from accounts table |
|
| 105 | - * |
|
| 106 | - * @param IUser $user |
|
| 107 | - */ |
|
| 108 | - public function deleteUser(IUser $user) { |
|
| 109 | - $uid = $user->getUID(); |
|
| 110 | - $query = $this->connection->getQueryBuilder(); |
|
| 111 | - $query->delete($this->table) |
|
| 112 | - ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
| 113 | - ->execute(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * get stored data from a given user |
|
| 118 | - * |
|
| 119 | - * @param IUser $user |
|
| 120 | - * @return array |
|
| 121 | - */ |
|
| 122 | - public function getUser(IUser $user) { |
|
| 123 | - $uid = $user->getUID(); |
|
| 124 | - $query = $this->connection->getQueryBuilder(); |
|
| 125 | - $query->select('data')->from($this->table) |
|
| 126 | - ->where($query->expr()->eq('uid', $query->createParameter('uid'))) |
|
| 127 | - ->setParameter('uid', $uid); |
|
| 128 | - $query->execute(); |
|
| 129 | - $result = $query->execute()->fetchAll(); |
|
| 130 | - |
|
| 131 | - if (empty($result)) { |
|
| 132 | - $userData = $this->buildDefaultUserRecord($user); |
|
| 133 | - $this->insertNewUser($user, $userData); |
|
| 134 | - return $userData; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $userDataArray = json_decode($result[0]['data'], true); |
|
| 138 | - |
|
| 139 | - $userDataArray = $this->addMissingDefaultValues($userDataArray); |
|
| 140 | - |
|
| 141 | - return $userDataArray; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * check if we need to ask the server for email verification, if yes we create a cronjob |
|
| 146 | - * |
|
| 147 | - * @param $oldData |
|
| 148 | - * @param $newData |
|
| 149 | - * @param IUser $user |
|
| 150 | - * @return array |
|
| 151 | - */ |
|
| 152 | - protected function checkEmailVerification($oldData, $newData, IUser $user) { |
|
| 153 | - if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) { |
|
| 154 | - $this->jobList->add(VerifyUserData::class, |
|
| 155 | - [ |
|
| 156 | - 'verificationCode' => '', |
|
| 157 | - 'data' => $newData[self::PROPERTY_EMAIL]['value'], |
|
| 158 | - 'type' => self::PROPERTY_EMAIL, |
|
| 159 | - 'uid' => $user->getUID(), |
|
| 160 | - 'try' => 0, |
|
| 161 | - 'lastRun' => time() |
|
| 162 | - ] |
|
| 163 | - ); |
|
| 164 | - $newData[AccountManager::PROPERTY_EMAIL]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - return $newData; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * make sure that all expected data are set |
|
| 172 | - * |
|
| 173 | - * @param array $userData |
|
| 174 | - * @return array |
|
| 175 | - */ |
|
| 176 | - protected function addMissingDefaultValues(array $userData) { |
|
| 177 | - |
|
| 178 | - foreach ($userData as $key => $value) { |
|
| 179 | - if (!isset($userData[$key]['verified'])) { |
|
| 180 | - $userData[$key]['verified'] = self::NOT_VERIFIED; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - return $userData; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * reset verification status if personal data changed |
|
| 189 | - * |
|
| 190 | - * @param array $oldData |
|
| 191 | - * @param array $newData |
|
| 192 | - * @return array |
|
| 193 | - */ |
|
| 194 | - protected function updateVerifyStatus($oldData, $newData) { |
|
| 195 | - |
|
| 196 | - // which account was already verified successfully? |
|
| 197 | - $twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED; |
|
| 198 | - $websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED; |
|
| 199 | - $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED; |
|
| 200 | - |
|
| 201 | - // keep old verification status if we don't have a new one |
|
| 202 | - if(!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
| 203 | - // keep old verification status if value didn't changed and an old value exists |
|
| 204 | - $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']); |
|
| 205 | - $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - if(!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
| 209 | - // keep old verification status if value didn't changed and an old value exists |
|
| 210 | - $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']); |
|
| 211 | - $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - if(!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
| 215 | - // keep old verification status if value didn't changed and an old value exists |
|
| 216 | - $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']); |
|
| 217 | - $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - // reset verification status if a value from a previously verified data was changed |
|
| 221 | - if($twitterVerified && |
|
| 222 | - $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value'] |
|
| 223 | - ) { |
|
| 224 | - $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - if($websiteVerified && |
|
| 228 | - $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value'] |
|
| 229 | - ) { |
|
| 230 | - $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - if($emailVerified && |
|
| 234 | - $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value'] |
|
| 235 | - ) { |
|
| 236 | - $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $newData; |
|
| 240 | - |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * add new user to accounts table |
|
| 245 | - * |
|
| 246 | - * @param IUser $user |
|
| 247 | - * @param array $data |
|
| 248 | - */ |
|
| 249 | - protected function insertNewUser(IUser $user, $data) { |
|
| 250 | - $uid = $user->getUID(); |
|
| 251 | - $jsonEncodedData = json_encode($data); |
|
| 252 | - $query = $this->connection->getQueryBuilder(); |
|
| 253 | - $query->insert($this->table) |
|
| 254 | - ->values( |
|
| 255 | - [ |
|
| 256 | - 'uid' => $query->createNamedParameter($uid), |
|
| 257 | - 'data' => $query->createNamedParameter($jsonEncodedData), |
|
| 258 | - ] |
|
| 259 | - ) |
|
| 260 | - ->execute(); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * update existing user in accounts table |
|
| 265 | - * |
|
| 266 | - * @param IUser $user |
|
| 267 | - * @param array $data |
|
| 268 | - */ |
|
| 269 | - protected function updateExistingUser(IUser $user, $data) { |
|
| 270 | - $uid = $user->getUID(); |
|
| 271 | - $jsonEncodedData = json_encode($data); |
|
| 272 | - $query = $this->connection->getQueryBuilder(); |
|
| 273 | - $query->update($this->table) |
|
| 274 | - ->set('data', $query->createNamedParameter($jsonEncodedData)) |
|
| 275 | - ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
| 276 | - ->execute(); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * build default user record in case not data set exists yet |
|
| 281 | - * |
|
| 282 | - * @param IUser $user |
|
| 283 | - * @return array |
|
| 284 | - */ |
|
| 285 | - protected function buildDefaultUserRecord(IUser $user) { |
|
| 286 | - return [ |
|
| 287 | - self::PROPERTY_DISPLAYNAME => |
|
| 288 | - [ |
|
| 289 | - 'value' => $user->getDisplayName(), |
|
| 290 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
| 291 | - 'verified' => self::NOT_VERIFIED, |
|
| 292 | - ], |
|
| 293 | - self::PROPERTY_ADDRESS => |
|
| 294 | - [ |
|
| 295 | - 'value' => '', |
|
| 296 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
| 297 | - 'verified' => self::NOT_VERIFIED, |
|
| 298 | - ], |
|
| 299 | - self::PROPERTY_WEBSITE => |
|
| 300 | - [ |
|
| 301 | - 'value' => '', |
|
| 302 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
| 303 | - 'verified' => self::NOT_VERIFIED, |
|
| 304 | - ], |
|
| 305 | - self::PROPERTY_EMAIL => |
|
| 306 | - [ |
|
| 307 | - 'value' => $user->getEMailAddress(), |
|
| 308 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
| 309 | - 'verified' => self::NOT_VERIFIED, |
|
| 310 | - ], |
|
| 311 | - self::PROPERTY_AVATAR => |
|
| 312 | - [ |
|
| 313 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY |
|
| 314 | - ], |
|
| 315 | - self::PROPERTY_PHONE => |
|
| 316 | - [ |
|
| 317 | - 'value' => '', |
|
| 318 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
| 319 | - 'verified' => self::NOT_VERIFIED, |
|
| 320 | - ], |
|
| 321 | - self::PROPERTY_TWITTER => |
|
| 322 | - [ |
|
| 323 | - 'value' => '', |
|
| 324 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
| 325 | - 'verified' => self::NOT_VERIFIED, |
|
| 326 | - ], |
|
| 327 | - ]; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - private function parseAccountData(IUser $user, $data): Account { |
|
| 331 | - $account = new Account($user); |
|
| 332 | - foreach($data as $property => $accountData) { |
|
| 333 | - $account->setProperty($property, $accountData['value'], $accountData['scope'], $accountData['verified']); |
|
| 334 | - } |
|
| 335 | - return $account; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - public function getAccount(IUser $user): IAccount { |
|
| 339 | - return $this->parseAccountData($user, $this->getUser($user)); |
|
| 340 | - } |
|
| 48 | + /** @var IDBConnection database connection */ |
|
| 49 | + private $connection; |
|
| 50 | + |
|
| 51 | + /** @var string table name */ |
|
| 52 | + private $table = 'accounts'; |
|
| 53 | + |
|
| 54 | + /** @var EventDispatcherInterface */ |
|
| 55 | + private $eventDispatcher; |
|
| 56 | + |
|
| 57 | + /** @var IJobList */ |
|
| 58 | + private $jobList; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * AccountManager constructor. |
|
| 62 | + * |
|
| 63 | + * @param IDBConnection $connection |
|
| 64 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 65 | + * @param IJobList $jobList |
|
| 66 | + */ |
|
| 67 | + public function __construct(IDBConnection $connection, |
|
| 68 | + EventDispatcherInterface $eventDispatcher, |
|
| 69 | + IJobList $jobList) { |
|
| 70 | + $this->connection = $connection; |
|
| 71 | + $this->eventDispatcher = $eventDispatcher; |
|
| 72 | + $this->jobList = $jobList; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * update user record |
|
| 77 | + * |
|
| 78 | + * @param IUser $user |
|
| 79 | + * @param $data |
|
| 80 | + */ |
|
| 81 | + public function updateUser(IUser $user, $data) { |
|
| 82 | + $userData = $this->getUser($user); |
|
| 83 | + $updated = true; |
|
| 84 | + if (empty($userData)) { |
|
| 85 | + $this->insertNewUser($user, $data); |
|
| 86 | + } elseif ($userData !== $data) { |
|
| 87 | + $data = $this->checkEmailVerification($userData, $data, $user); |
|
| 88 | + $data = $this->updateVerifyStatus($userData, $data); |
|
| 89 | + $this->updateExistingUser($user, $data); |
|
| 90 | + } else { |
|
| 91 | + // nothing needs to be done if new and old data set are the same |
|
| 92 | + $updated = false; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + if ($updated) { |
|
| 96 | + $this->eventDispatcher->dispatch( |
|
| 97 | + 'OC\AccountManager::userUpdated', |
|
| 98 | + new GenericEvent($user, $data) |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * delete user from accounts table |
|
| 105 | + * |
|
| 106 | + * @param IUser $user |
|
| 107 | + */ |
|
| 108 | + public function deleteUser(IUser $user) { |
|
| 109 | + $uid = $user->getUID(); |
|
| 110 | + $query = $this->connection->getQueryBuilder(); |
|
| 111 | + $query->delete($this->table) |
|
| 112 | + ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
| 113 | + ->execute(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * get stored data from a given user |
|
| 118 | + * |
|
| 119 | + * @param IUser $user |
|
| 120 | + * @return array |
|
| 121 | + */ |
|
| 122 | + public function getUser(IUser $user) { |
|
| 123 | + $uid = $user->getUID(); |
|
| 124 | + $query = $this->connection->getQueryBuilder(); |
|
| 125 | + $query->select('data')->from($this->table) |
|
| 126 | + ->where($query->expr()->eq('uid', $query->createParameter('uid'))) |
|
| 127 | + ->setParameter('uid', $uid); |
|
| 128 | + $query->execute(); |
|
| 129 | + $result = $query->execute()->fetchAll(); |
|
| 130 | + |
|
| 131 | + if (empty($result)) { |
|
| 132 | + $userData = $this->buildDefaultUserRecord($user); |
|
| 133 | + $this->insertNewUser($user, $userData); |
|
| 134 | + return $userData; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $userDataArray = json_decode($result[0]['data'], true); |
|
| 138 | + |
|
| 139 | + $userDataArray = $this->addMissingDefaultValues($userDataArray); |
|
| 140 | + |
|
| 141 | + return $userDataArray; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * check if we need to ask the server for email verification, if yes we create a cronjob |
|
| 146 | + * |
|
| 147 | + * @param $oldData |
|
| 148 | + * @param $newData |
|
| 149 | + * @param IUser $user |
|
| 150 | + * @return array |
|
| 151 | + */ |
|
| 152 | + protected function checkEmailVerification($oldData, $newData, IUser $user) { |
|
| 153 | + if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) { |
|
| 154 | + $this->jobList->add(VerifyUserData::class, |
|
| 155 | + [ |
|
| 156 | + 'verificationCode' => '', |
|
| 157 | + 'data' => $newData[self::PROPERTY_EMAIL]['value'], |
|
| 158 | + 'type' => self::PROPERTY_EMAIL, |
|
| 159 | + 'uid' => $user->getUID(), |
|
| 160 | + 'try' => 0, |
|
| 161 | + 'lastRun' => time() |
|
| 162 | + ] |
|
| 163 | + ); |
|
| 164 | + $newData[AccountManager::PROPERTY_EMAIL]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + return $newData; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * make sure that all expected data are set |
|
| 172 | + * |
|
| 173 | + * @param array $userData |
|
| 174 | + * @return array |
|
| 175 | + */ |
|
| 176 | + protected function addMissingDefaultValues(array $userData) { |
|
| 177 | + |
|
| 178 | + foreach ($userData as $key => $value) { |
|
| 179 | + if (!isset($userData[$key]['verified'])) { |
|
| 180 | + $userData[$key]['verified'] = self::NOT_VERIFIED; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + return $userData; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * reset verification status if personal data changed |
|
| 189 | + * |
|
| 190 | + * @param array $oldData |
|
| 191 | + * @param array $newData |
|
| 192 | + * @return array |
|
| 193 | + */ |
|
| 194 | + protected function updateVerifyStatus($oldData, $newData) { |
|
| 195 | + |
|
| 196 | + // which account was already verified successfully? |
|
| 197 | + $twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED; |
|
| 198 | + $websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED; |
|
| 199 | + $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED; |
|
| 200 | + |
|
| 201 | + // keep old verification status if we don't have a new one |
|
| 202 | + if(!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
| 203 | + // keep old verification status if value didn't changed and an old value exists |
|
| 204 | + $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']); |
|
| 205 | + $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + if(!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
| 209 | + // keep old verification status if value didn't changed and an old value exists |
|
| 210 | + $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']); |
|
| 211 | + $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + if(!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
| 215 | + // keep old verification status if value didn't changed and an old value exists |
|
| 216 | + $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']); |
|
| 217 | + $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + // reset verification status if a value from a previously verified data was changed |
|
| 221 | + if($twitterVerified && |
|
| 222 | + $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value'] |
|
| 223 | + ) { |
|
| 224 | + $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + if($websiteVerified && |
|
| 228 | + $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value'] |
|
| 229 | + ) { |
|
| 230 | + $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + if($emailVerified && |
|
| 234 | + $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value'] |
|
| 235 | + ) { |
|
| 236 | + $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $newData; |
|
| 240 | + |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * add new user to accounts table |
|
| 245 | + * |
|
| 246 | + * @param IUser $user |
|
| 247 | + * @param array $data |
|
| 248 | + */ |
|
| 249 | + protected function insertNewUser(IUser $user, $data) { |
|
| 250 | + $uid = $user->getUID(); |
|
| 251 | + $jsonEncodedData = json_encode($data); |
|
| 252 | + $query = $this->connection->getQueryBuilder(); |
|
| 253 | + $query->insert($this->table) |
|
| 254 | + ->values( |
|
| 255 | + [ |
|
| 256 | + 'uid' => $query->createNamedParameter($uid), |
|
| 257 | + 'data' => $query->createNamedParameter($jsonEncodedData), |
|
| 258 | + ] |
|
| 259 | + ) |
|
| 260 | + ->execute(); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * update existing user in accounts table |
|
| 265 | + * |
|
| 266 | + * @param IUser $user |
|
| 267 | + * @param array $data |
|
| 268 | + */ |
|
| 269 | + protected function updateExistingUser(IUser $user, $data) { |
|
| 270 | + $uid = $user->getUID(); |
|
| 271 | + $jsonEncodedData = json_encode($data); |
|
| 272 | + $query = $this->connection->getQueryBuilder(); |
|
| 273 | + $query->update($this->table) |
|
| 274 | + ->set('data', $query->createNamedParameter($jsonEncodedData)) |
|
| 275 | + ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
| 276 | + ->execute(); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * build default user record in case not data set exists yet |
|
| 281 | + * |
|
| 282 | + * @param IUser $user |
|
| 283 | + * @return array |
|
| 284 | + */ |
|
| 285 | + protected function buildDefaultUserRecord(IUser $user) { |
|
| 286 | + return [ |
|
| 287 | + self::PROPERTY_DISPLAYNAME => |
|
| 288 | + [ |
|
| 289 | + 'value' => $user->getDisplayName(), |
|
| 290 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
| 291 | + 'verified' => self::NOT_VERIFIED, |
|
| 292 | + ], |
|
| 293 | + self::PROPERTY_ADDRESS => |
|
| 294 | + [ |
|
| 295 | + 'value' => '', |
|
| 296 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
| 297 | + 'verified' => self::NOT_VERIFIED, |
|
| 298 | + ], |
|
| 299 | + self::PROPERTY_WEBSITE => |
|
| 300 | + [ |
|
| 301 | + 'value' => '', |
|
| 302 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
| 303 | + 'verified' => self::NOT_VERIFIED, |
|
| 304 | + ], |
|
| 305 | + self::PROPERTY_EMAIL => |
|
| 306 | + [ |
|
| 307 | + 'value' => $user->getEMailAddress(), |
|
| 308 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
| 309 | + 'verified' => self::NOT_VERIFIED, |
|
| 310 | + ], |
|
| 311 | + self::PROPERTY_AVATAR => |
|
| 312 | + [ |
|
| 313 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY |
|
| 314 | + ], |
|
| 315 | + self::PROPERTY_PHONE => |
|
| 316 | + [ |
|
| 317 | + 'value' => '', |
|
| 318 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
| 319 | + 'verified' => self::NOT_VERIFIED, |
|
| 320 | + ], |
|
| 321 | + self::PROPERTY_TWITTER => |
|
| 322 | + [ |
|
| 323 | + 'value' => '', |
|
| 324 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
| 325 | + 'verified' => self::NOT_VERIFIED, |
|
| 326 | + ], |
|
| 327 | + ]; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + private function parseAccountData(IUser $user, $data): Account { |
|
| 331 | + $account = new Account($user); |
|
| 332 | + foreach($data as $property => $accountData) { |
|
| 333 | + $account->setProperty($property, $accountData['value'], $accountData['scope'], $accountData['verified']); |
|
| 334 | + } |
|
| 335 | + return $account; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + public function getAccount(IUser $user): IAccount { |
|
| 339 | + return $this->parseAccountData($user, $this->getUser($user)); |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | 342 | } |
@@ -199,38 +199,38 @@ discard block |
||
| 199 | 199 | $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED; |
| 200 | 200 | |
| 201 | 201 | // keep old verification status if we don't have a new one |
| 202 | - if(!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
| 202 | + if (!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
| 203 | 203 | // keep old verification status if value didn't changed and an old value exists |
| 204 | 204 | $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']); |
| 205 | 205 | $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - if(!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
| 208 | + if (!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
| 209 | 209 | // keep old verification status if value didn't changed and an old value exists |
| 210 | 210 | $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']); |
| 211 | 211 | $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - if(!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
| 214 | + if (!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
| 215 | 215 | // keep old verification status if value didn't changed and an old value exists |
| 216 | 216 | $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']); |
| 217 | 217 | $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | // reset verification status if a value from a previously verified data was changed |
| 221 | - if($twitterVerified && |
|
| 221 | + if ($twitterVerified && |
|
| 222 | 222 | $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value'] |
| 223 | 223 | ) { |
| 224 | 224 | $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - if($websiteVerified && |
|
| 227 | + if ($websiteVerified && |
|
| 228 | 228 | $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value'] |
| 229 | 229 | ) { |
| 230 | 230 | $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - if($emailVerified && |
|
| 233 | + if ($emailVerified && |
|
| 234 | 234 | $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value'] |
| 235 | 235 | ) { |
| 236 | 236 | $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED; |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | |
| 330 | 330 | private function parseAccountData(IUser $user, $data): Account { |
| 331 | 331 | $account = new Account($user); |
| 332 | - foreach($data as $property => $accountData) { |
|
| 332 | + foreach ($data as $property => $accountData) { |
|
| 333 | 333 | $account->setProperty($property, $accountData['value'], $accountData['scope'], $accountData['verified']); |
| 334 | 334 | } |
| 335 | 335 | return $account; |