Completed
Pull Request — master (#3869)
by Björn
15:26
created
apps/lookup_server_connector/lib/UpdateLookupServer.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -35,102 +35,102 @@
 block discarded – undo
35 35
  * @package OCA\LookupServerConnector
36 36
  */
37 37
 class UpdateLookupServer {
38
-	/** @var AccountManager */
39
-	private $accountManager;
40
-	/** @var IClientService */
41
-	private $clientService;
42
-	/** @var Signer */
43
-	private $signer;
44
-	/** @var IJobList */
45
-	private $jobList;
46
-	/** @var string URL point to lookup server */
47
-	private $lookupServer = 'https://lookup.nextcloud.com';
38
+    /** @var AccountManager */
39
+    private $accountManager;
40
+    /** @var IClientService */
41
+    private $clientService;
42
+    /** @var Signer */
43
+    private $signer;
44
+    /** @var IJobList */
45
+    private $jobList;
46
+    /** @var string URL point to lookup server */
47
+    private $lookupServer = 'https://lookup.nextcloud.com';
48 48
 
49
-	/**
50
-	 * @param AccountManager $accountManager
51
-	 * @param IClientService $clientService
52
-	 * @param Signer $signer
53
-	 * @param IJobList $jobList
54
-	 * @param string $lookupServer if nothing is given we use the default lookup server
55
-	 */
56
-	public function __construct(AccountManager $accountManager,
57
-								IClientService $clientService,
58
-								Signer $signer,
59
-								IJobList $jobList,
60
-								$lookupServer = '') {
61
-		$this->accountManager = $accountManager;
62
-		$this->clientService = $clientService;
63
-		$this->signer = $signer;
64
-		$this->jobList = $jobList;
65
-		if ($lookupServer !== '') {
66
-			$this->lookupServer = $lookupServer;
67
-		}
68
-		$this->lookupServer = rtrim($this->lookupServer, '/');
69
-		$this->lookupServer .= '/users';
70
-	}
49
+    /**
50
+     * @param AccountManager $accountManager
51
+     * @param IClientService $clientService
52
+     * @param Signer $signer
53
+     * @param IJobList $jobList
54
+     * @param string $lookupServer if nothing is given we use the default lookup server
55
+     */
56
+    public function __construct(AccountManager $accountManager,
57
+                                IClientService $clientService,
58
+                                Signer $signer,
59
+                                IJobList $jobList,
60
+                                $lookupServer = '') {
61
+        $this->accountManager = $accountManager;
62
+        $this->clientService = $clientService;
63
+        $this->signer = $signer;
64
+        $this->jobList = $jobList;
65
+        if ($lookupServer !== '') {
66
+            $this->lookupServer = $lookupServer;
67
+        }
68
+        $this->lookupServer = rtrim($this->lookupServer, '/');
69
+        $this->lookupServer .= '/users';
70
+    }
71 71
 
72
-	/**
73
-	 * @param IUser $user
74
-	 */
75
-	public function userUpdated(IUser $user) {
76
-		$userData = $this->accountManager->getUser($user);
77
-		$publicData = [];
72
+    /**
73
+     * @param IUser $user
74
+     */
75
+    public function userUpdated(IUser $user) {
76
+        $userData = $this->accountManager->getUser($user);
77
+        $publicData = [];
78 78
 
79
-		foreach ($userData as $key => $data) {
80
-			if ($data['scope'] === AccountManager::VISIBILITY_PUBLIC) {
81
-				$publicData[$key] = $data;
82
-			}
83
-		}
79
+        foreach ($userData as $key => $data) {
80
+            if ($data['scope'] === AccountManager::VISIBILITY_PUBLIC) {
81
+                $publicData[$key] = $data;
82
+            }
83
+        }
84 84
 
85
-		$this->sendToLookupServer($user, $publicData);
86
-	}
85
+        $this->sendToLookupServer($user, $publicData);
86
+    }
87 87
 
88
-	/**
89
-	 * send public user data to the lookup server
90
-	 *
91
-	 * @param IUser $user
92
-	 * @param array $publicData
93
-	 */
94
-	protected function sendToLookupServer(IUser $user, array $publicData) {
88
+    /**
89
+     * send public user data to the lookup server
90
+     *
91
+     * @param IUser $user
92
+     * @param array $publicData
93
+     */
94
+    protected function sendToLookupServer(IUser $user, array $publicData) {
95 95
 
96
-		$dataArray = ['federationId' => $user->getCloudId()];
96
+        $dataArray = ['federationId' => $user->getCloudId()];
97 97
 
98
-		if (!empty($publicData)) {
99
-			$dataArray['name'] = isset($publicData[AccountManager::PROPERTY_DISPLAYNAME]) ? $publicData[AccountManager::PROPERTY_DISPLAYNAME]['value'] : '';
100
-			$dataArray['email'] = isset($publicData[AccountManager::PROPERTY_EMAIL]) ? $publicData[AccountManager::PROPERTY_EMAIL]['value'] : '';
101
-			$dataArray['address'] = isset($publicData[AccountManager::PROPERTY_ADDRESS]) ? $publicData[AccountManager::PROPERTY_ADDRESS]['value'] : '';
102
-			$dataArray['website'] = isset($publicData[AccountManager::PROPERTY_WEBSITE]) ? $publicData[AccountManager::PROPERTY_WEBSITE]['value'] : '';
103
-			$dataArray['twitter'] = isset($publicData[AccountManager::PROPERTY_TWITTER]) ? $publicData[AccountManager::PROPERTY_TWITTER]['value'] : '';
104
-			$dataArray['phone'] = isset($publicData[AccountManager::PROPERTY_PHONE]) ? $publicData[AccountManager::PROPERTY_PHONE]['value'] : '';
105
-		}
98
+        if (!empty($publicData)) {
99
+            $dataArray['name'] = isset($publicData[AccountManager::PROPERTY_DISPLAYNAME]) ? $publicData[AccountManager::PROPERTY_DISPLAYNAME]['value'] : '';
100
+            $dataArray['email'] = isset($publicData[AccountManager::PROPERTY_EMAIL]) ? $publicData[AccountManager::PROPERTY_EMAIL]['value'] : '';
101
+            $dataArray['address'] = isset($publicData[AccountManager::PROPERTY_ADDRESS]) ? $publicData[AccountManager::PROPERTY_ADDRESS]['value'] : '';
102
+            $dataArray['website'] = isset($publicData[AccountManager::PROPERTY_WEBSITE]) ? $publicData[AccountManager::PROPERTY_WEBSITE]['value'] : '';
103
+            $dataArray['twitter'] = isset($publicData[AccountManager::PROPERTY_TWITTER]) ? $publicData[AccountManager::PROPERTY_TWITTER]['value'] : '';
104
+            $dataArray['phone'] = isset($publicData[AccountManager::PROPERTY_PHONE]) ? $publicData[AccountManager::PROPERTY_PHONE]['value'] : '';
105
+        }
106 106
 
107
-		$dataArray = $this->signer->sign('lookupserver', $dataArray, $user);
108
-		$httpClient = $this->clientService->newClient();
109
-		try {
110
-			if (empty($publicData)) {
111
-				$httpClient->delete($this->lookupServer,
112
-					[
113
-						'body' => json_encode($dataArray),
114
-						'timeout' => 10,
115
-						'connect_timeout' => 3,
116
-					]
117
-				);
118
-			} else {
119
-				$httpClient->post($this->lookupServer,
120
-					[
121
-						'body' => json_encode($dataArray),
122
-						'timeout' => 10,
123
-						'connect_timeout' => 3,
124
-					]
125
-				);
126
-			}
127
-		} catch (\Exception $e) {
128
-			$this->jobList->add(RetryJob::class,
129
-				[
130
-					'dataArray' => $dataArray,
131
-					'retryNo' => 0,
132
-				]
133
-			);
134
-		}
135
-	}
107
+        $dataArray = $this->signer->sign('lookupserver', $dataArray, $user);
108
+        $httpClient = $this->clientService->newClient();
109
+        try {
110
+            if (empty($publicData)) {
111
+                $httpClient->delete($this->lookupServer,
112
+                    [
113
+                        'body' => json_encode($dataArray),
114
+                        'timeout' => 10,
115
+                        'connect_timeout' => 3,
116
+                    ]
117
+                );
118
+            } else {
119
+                $httpClient->post($this->lookupServer,
120
+                    [
121
+                        'body' => json_encode($dataArray),
122
+                        'timeout' => 10,
123
+                        'connect_timeout' => 3,
124
+                    ]
125
+                );
126
+            }
127
+        } catch (\Exception $e) {
128
+            $this->jobList->add(RetryJob::class,
129
+                [
130
+                    'dataArray' => $dataArray,
131
+                    'retryNo' => 0,
132
+                ]
133
+            );
134
+        }
135
+    }
136 136
 }
Please login to merge, or discard this patch.
apps/lookup_server_connector/appinfo/app.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -22,26 +22,26 @@
 block discarded – undo
22 22
 $dispatcher = \OC::$server->getEventDispatcher();
23 23
 
24 24
 $dispatcher->addListener('OC\AccountManager::userUpdated', function(\Symfony\Component\EventDispatcher\GenericEvent $event) {
25
-	$user = $event->getSubject();
25
+    $user = $event->getSubject();
26 26
 
27
-	$keyManager = new \OC\Security\IdentityProof\Manager(
28
-		\OC::$server->getAppDataDir('identityproof'),
29
-		\OC::$server->getCrypto()
30
-	);
27
+    $keyManager = new \OC\Security\IdentityProof\Manager(
28
+        \OC::$server->getAppDataDir('identityproof'),
29
+        \OC::$server->getCrypto()
30
+    );
31 31
 
32
-	$config = \OC::$server->getConfig();
33
-	$lookupServer = $config->getSystemValue('lookup_server', '');
32
+    $config = \OC::$server->getConfig();
33
+    $lookupServer = $config->getSystemValue('lookup_server', '');
34 34
 
35
-	$updateLookupServer = new \OCA\LookupServerConnector\UpdateLookupServer(
36
-		new \OC\Accounts\AccountManager(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher()),
37
-		\OC::$server->getHTTPClientService(),
38
-		new \OC\Security\IdentityProof\Signer(
39
-			$keyManager,
40
-			new \OC\AppFramework\Utility\TimeFactory(),
41
-			\OC::$server->getUserManager()
42
-		),
43
-		\OC::$server->getJobList(),
44
-		$lookupServer
45
-	);
46
-	$updateLookupServer->userUpdated($user);
35
+    $updateLookupServer = new \OCA\LookupServerConnector\UpdateLookupServer(
36
+        new \OC\Accounts\AccountManager(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher()),
37
+        \OC::$server->getHTTPClientService(),
38
+        new \OC\Security\IdentityProof\Signer(
39
+            $keyManager,
40
+            new \OC\AppFramework\Utility\TimeFactory(),
41
+            \OC::$server->getUserManager()
42
+        ),
43
+        \OC::$server->getJobList(),
44
+        $lookupServer
45
+    );
46
+    $updateLookupServer->userUpdated($user);
47 47
 });
Please login to merge, or discard this patch.
settings/routes.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -36,73 +36,73 @@
 block discarded – undo
36 36
 
37 37
 $application = new Application();
38 38
 $application->registerRoutes($this, [
39
-	'resources' => [
40
-		'groups' => ['url' => '/settings/users/groups'],
41
-		'users' => ['url' => '/settings/users/users'],
42
-		'AuthSettings' => ['url' => '/settings/personal/authtokens'],
43
-	],
44
-	'routes' => [
45
-		['name' => 'MailSettings#setMailSettings', 'url' => '/settings/admin/mailsettings', 'verb' => 'POST'],
46
-		['name' => 'MailSettings#storeCredentials', 'url' => '/settings/admin/mailsettings/credentials', 'verb' => 'POST'],
47
-		['name' => 'MailSettings#sendTestMail', 'url' => '/settings/admin/mailtest', 'verb' => 'POST'],
48
-		['name' => 'Encryption#startMigration', 'url' => '/settings/admin/startmigration', 'verb' => 'POST'],
49
-		['name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'],
50
-		['name' => 'AppSettings#viewApps', 'url' => '/settings/apps', 'verb' => 'GET'],
51
-		['name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET'],
52
-		['name' => 'SecuritySettings#trustedDomains', 'url' => '/settings/admin/security/trustedDomains', 'verb' => 'POST'],
53
-		['name' => 'Users#setDisplayName', 'url' => '/settings/users/{username}/displayName', 'verb' => 'POST'],
54
-		['name' => 'Users#setEMailAddress', 'url' => '/settings/users/{id}/mailAddress', 'verb' => 'PUT'],
55
-		['name' => 'Users#setUserSettings', 'url' => '/settings/users/{username}/settings', 'verb' => 'PUT'],
56
-		['name' => 'Users#getVerificationCode', 'url' => '/settings/users/{account}/verify', 'verb' => 'GET'],
57
-		['name' => 'Users#stats', 'url' => '/settings/users/stats', 'verb' => 'GET'],
58
-		['name' => 'LogSettings#setLogLevel', 'url' => '/settings/admin/log/level', 'verb' => 'POST'],
59
-		['name' => 'LogSettings#getEntries', 'url' => '/settings/admin/log/entries', 'verb' => 'GET'],
60
-		['name' => 'LogSettings#download', 'url' => '/settings/admin/log/download', 'verb' => 'GET'],
61
-		['name' => 'CheckSetup#check', 'url' => '/settings/ajax/checksetup', 'verb' => 'GET'],
62
-		['name' => 'CheckSetup#getFailedIntegrityCheckFiles', 'url' => '/settings/integrity/failed', 'verb' => 'GET'],
63
-		['name' => 'CheckSetup#rescanFailedIntegrityCheck', 'url' => '/settings/integrity/rescan', 'verb' => 'GET'],
64
-		['name' => 'Certificate#addPersonalRootCertificate', 'url' => '/settings/personal/certificate', 'verb' => 'POST'],
65
-		['name' => 'Certificate#removePersonalRootCertificate', 'url' => '/settings/personal/certificate/{certificateIdentifier}', 'verb' => 'DELETE'],
66
-		['name' => 'Certificate#addSystemRootCertificate', 'url' => '/settings/admin/certificate', 'verb' => 'POST'],
67
-		['name' => 'Certificate#removeSystemRootCertificate', 'url' => '/settings/admin/certificate/{certificateIdentifier}', 'verb' => 'DELETE'],
68
-		['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'server']],
69
-		['name' => 'AdminSettings#form', 'url' => '/settings/admin/{section}', 'verb' => 'GET'],
70
-		['name' => 'ChangePassword#changePersonalPassword', 'url' => '/settings/personal/changepassword', 'verb' => 'POST'],
71
-		['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST'],
72
-		['name' => 'Personal#setLanguage', 'url' => '/settings/ajax/setlanguage.php', 'verb' => 'POST'],
73
-	]
39
+    'resources' => [
40
+        'groups' => ['url' => '/settings/users/groups'],
41
+        'users' => ['url' => '/settings/users/users'],
42
+        'AuthSettings' => ['url' => '/settings/personal/authtokens'],
43
+    ],
44
+    'routes' => [
45
+        ['name' => 'MailSettings#setMailSettings', 'url' => '/settings/admin/mailsettings', 'verb' => 'POST'],
46
+        ['name' => 'MailSettings#storeCredentials', 'url' => '/settings/admin/mailsettings/credentials', 'verb' => 'POST'],
47
+        ['name' => 'MailSettings#sendTestMail', 'url' => '/settings/admin/mailtest', 'verb' => 'POST'],
48
+        ['name' => 'Encryption#startMigration', 'url' => '/settings/admin/startmigration', 'verb' => 'POST'],
49
+        ['name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'],
50
+        ['name' => 'AppSettings#viewApps', 'url' => '/settings/apps', 'verb' => 'GET'],
51
+        ['name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET'],
52
+        ['name' => 'SecuritySettings#trustedDomains', 'url' => '/settings/admin/security/trustedDomains', 'verb' => 'POST'],
53
+        ['name' => 'Users#setDisplayName', 'url' => '/settings/users/{username}/displayName', 'verb' => 'POST'],
54
+        ['name' => 'Users#setEMailAddress', 'url' => '/settings/users/{id}/mailAddress', 'verb' => 'PUT'],
55
+        ['name' => 'Users#setUserSettings', 'url' => '/settings/users/{username}/settings', 'verb' => 'PUT'],
56
+        ['name' => 'Users#getVerificationCode', 'url' => '/settings/users/{account}/verify', 'verb' => 'GET'],
57
+        ['name' => 'Users#stats', 'url' => '/settings/users/stats', 'verb' => 'GET'],
58
+        ['name' => 'LogSettings#setLogLevel', 'url' => '/settings/admin/log/level', 'verb' => 'POST'],
59
+        ['name' => 'LogSettings#getEntries', 'url' => '/settings/admin/log/entries', 'verb' => 'GET'],
60
+        ['name' => 'LogSettings#download', 'url' => '/settings/admin/log/download', 'verb' => 'GET'],
61
+        ['name' => 'CheckSetup#check', 'url' => '/settings/ajax/checksetup', 'verb' => 'GET'],
62
+        ['name' => 'CheckSetup#getFailedIntegrityCheckFiles', 'url' => '/settings/integrity/failed', 'verb' => 'GET'],
63
+        ['name' => 'CheckSetup#rescanFailedIntegrityCheck', 'url' => '/settings/integrity/rescan', 'verb' => 'GET'],
64
+        ['name' => 'Certificate#addPersonalRootCertificate', 'url' => '/settings/personal/certificate', 'verb' => 'POST'],
65
+        ['name' => 'Certificate#removePersonalRootCertificate', 'url' => '/settings/personal/certificate/{certificateIdentifier}', 'verb' => 'DELETE'],
66
+        ['name' => 'Certificate#addSystemRootCertificate', 'url' => '/settings/admin/certificate', 'verb' => 'POST'],
67
+        ['name' => 'Certificate#removeSystemRootCertificate', 'url' => '/settings/admin/certificate/{certificateIdentifier}', 'verb' => 'DELETE'],
68
+        ['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'server']],
69
+        ['name' => 'AdminSettings#form', 'url' => '/settings/admin/{section}', 'verb' => 'GET'],
70
+        ['name' => 'ChangePassword#changePersonalPassword', 'url' => '/settings/personal/changepassword', 'verb' => 'POST'],
71
+        ['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST'],
72
+        ['name' => 'Personal#setLanguage', 'url' => '/settings/ajax/setlanguage.php', 'verb' => 'POST'],
73
+    ]
74 74
 ]);
75 75
 
76 76
 /** @var $this \OCP\Route\IRouter */
77 77
 
78 78
 // Settings pages
79 79
 $this->create('settings_help', '/settings/help')
80
-	->actionInclude('settings/help.php');
80
+    ->actionInclude('settings/help.php');
81 81
 $this->create('settings_personal', '/settings/personal')
82
-	->actionInclude('settings/personal.php');
82
+    ->actionInclude('settings/personal.php');
83 83
 $this->create('settings_users', '/settings/users')
84
-	->actionInclude('settings/users.php');
84
+    ->actionInclude('settings/users.php');
85 85
 // Settings ajax actions
86 86
 // users
87 87
 $this->create('settings_ajax_setquota', '/settings/ajax/setquota.php')
88
-	->actionInclude('settings/ajax/setquota.php');
88
+    ->actionInclude('settings/ajax/setquota.php');
89 89
 $this->create('settings_ajax_togglegroups', '/settings/ajax/togglegroups.php')
90
-	->actionInclude('settings/ajax/togglegroups.php');
90
+    ->actionInclude('settings/ajax/togglegroups.php');
91 91
 $this->create('settings_ajax_togglesubadmins', '/settings/ajax/togglesubadmins.php')
92
-	->actionInclude('settings/ajax/togglesubadmins.php');
92
+    ->actionInclude('settings/ajax/togglesubadmins.php');
93 93
 $this->create('settings_ajax_changegorupname', '/settings/ajax/changegroupname.php')
94
-	->actionInclude('settings/ajax/changegroupname.php');
94
+    ->actionInclude('settings/ajax/changegroupname.php');
95 95
 // apps
96 96
 $this->create('settings_ajax_enableapp', '/settings/ajax/enableapp.php')
97
-	->actionInclude('settings/ajax/enableapp.php');
97
+    ->actionInclude('settings/ajax/enableapp.php');
98 98
 $this->create('settings_ajax_disableapp', '/settings/ajax/disableapp.php')
99
-	->actionInclude('settings/ajax/disableapp.php');
99
+    ->actionInclude('settings/ajax/disableapp.php');
100 100
 $this->create('settings_ajax_updateapp', '/settings/ajax/updateapp.php')
101
-	->actionInclude('settings/ajax/updateapp.php');
101
+    ->actionInclude('settings/ajax/updateapp.php');
102 102
 $this->create('settings_ajax_uninstallapp', '/settings/ajax/uninstallapp.php')
103
-	->actionInclude('settings/ajax/uninstallapp.php');
103
+    ->actionInclude('settings/ajax/uninstallapp.php');
104 104
 $this->create('settings_ajax_navigationdetect', '/settings/ajax/navigationdetect.php')
105
-	->actionInclude('settings/ajax/navigationdetect.php');
105
+    ->actionInclude('settings/ajax/navigationdetect.php');
106 106
 // admin
107 107
 $this->create('settings_ajax_excludegroups', '/settings/ajax/excludegroups.php')
108
-	->actionInclude('settings/ajax/excludegroups.php');
108
+    ->actionInclude('settings/ajax/excludegroups.php');
Please login to merge, or discard this patch.
settings/templates/personal.php 1 patch
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -22,10 +22,10 @@  discard block
 block discarded – undo
22 22
 
23 23
 <div id="app-navigation">
24 24
 	<ul class="with-icon">
25
-	<?php foreach($_['forms'] as $form) {
25
+	<?php foreach ($_['forms'] as $form) {
26 26
 		if (isset($form['anchor'])) {
27
-			$anchor = '#' . $form['anchor'];
28
-			$class = 'nav-icon-' . $form['anchor'];
27
+			$anchor = '#'.$form['anchor'];
28
+			$class = 'nav-icon-'.$form['anchor'];
29 29
 			$sectionName = $form['section-name'];
30 30
 			print_unescaped(sprintf("<li><a href='%s' class='%s'>%s</a></li>", \OCP\Util::sanitizeHTML($anchor),
31 31
 			\OCP\Util::sanitizeHTML($class), \OCP\Util::sanitizeHTML($sectionName)));
@@ -37,15 +37,15 @@  discard block
 block discarded – undo
37 37
 <div id="app-content">
38 38
 
39 39
 <div id="quota" class="section">
40
-	<div style="width:<?php p($_['usage_relative']);?>%"
41
-		<?php if($_['usage_relative'] > 80): ?> class="quota-warning" <?php endif; ?>>
40
+	<div style="width:<?php p($_['usage_relative']); ?>%"
41
+		<?php if ($_['usage_relative'] > 80): ?> class="quota-warning" <?php endif; ?>>
42 42
 		<p id="quotatext">
43 43
 			<?php if ($_['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED): ?>
44 44
 				<?php print_unescaped($l->t('You are using <strong>%s</strong> of <strong>%s</strong>',
45
-					[$_['usage'], $_['total_space']]));?>
45
+					[$_['usage'], $_['total_space']])); ?>
46 46
 			<?php else: ?>
47 47
 				<?php print_unescaped($l->t('You are using <strong>%s</strong> of <strong>%s</strong> (<strong>%s %%</strong>)',
48
-					[$_['usage'], $_['total_space'],  $_['usage_relative']]));?>
48
+					[$_['usage'], $_['total_space'], $_['usage_relative']])); ?>
49 49
 			<?php endif ?>
50 50
 		</p>
51 51
 	</div>
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
 				<span class="icon-password"/>
92 92
 			</h2>
93 93
 			<input type="text" id="displayname" name="displayname"
94
-				<?php if(!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?>
94
+				<?php if (!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?>
95 95
 				value="<?php p($_['displayName']) ?>"
96 96
 				autocomplete="on" autocapitalize="none" autocorrect="off" />
97
-			<?php if(!$_['displayNameChangeSupported']) { ?>
98
-				<span><?php if(isset($_['displayName']) && !empty($_['displayName'])) { p($_['displayName']); } else { p($l->t('No display name set')); } ?></span>
97
+			<?php if (!$_['displayNameChangeSupported']) { ?>
98
+				<span><?php if (isset($_['displayName']) && !empty($_['displayName'])) { p($_['displayName']); } else { p($l->t('No display name set')); } ?></span>
99 99
 			<?php } ?>
100 100
 			<span class="icon-checkmark hidden"/>
101 101
 			<input type="hidden" id="displaynamescope" value="<?php p($_['displayNameScope']) ?>">
@@ -109,13 +109,13 @@  discard block
 block discarded – undo
109 109
 			</h2>
110 110
 			<span class="verify" id="verify-email">Verify</span>
111 111
 			<input type="email" name="email" id="email" value="<?php p($_['email']); ?>"
112
-				<?php if(!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?>
112
+				<?php if (!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?>
113 113
 				placeholder="<?php p($l->t('Your email address')); ?>"
114 114
 				autocomplete="on" autocapitalize="none" autocorrect="off" />
115
-			<?php if(!$_['displayNameChangeSupported']) { ?>
116
-				<span><?php if(isset($_['email']) && !empty($_['email'])) { p($_['email']); } else { p($l->t('No email address set')); }?></span>
115
+			<?php if (!$_['displayNameChangeSupported']) { ?>
116
+				<span><?php if (isset($_['email']) && !empty($_['email'])) { p($_['email']); } else { p($l->t('No email address set')); }?></span>
117 117
 			<?php } ?>
118
-			<?php if($_['displayNameChangeSupported']) { ?>
118
+			<?php if ($_['displayNameChangeSupported']) { ?>
119 119
 				<br />
120 120
 				<em><?php p($l->t('For password reset and notifications')); ?></em>
121 121
 			<?php } ?>
@@ -193,19 +193,19 @@  discard block
 block discarded – undo
193 193
 </div>
194 194
 
195 195
 <?php
196
-if($_['passwordChangeSupported']) {
196
+if ($_['passwordChangeSupported']) {
197 197
 	script('jquery-showpassword');
198 198
 ?>
199 199
 <form id="passwordform" class="section">
200
-	<h2 class="inlineblock"><?php p($l->t('Password'));?></h2>
200
+	<h2 class="inlineblock"><?php p($l->t('Password')); ?></h2>
201 201
 	<div id="password-error-msg" class="msg success inlineblock" style="display: none;">Saved</div>
202 202
 	<br>
203 203
 	<label for="pass1" class="hidden-visually"><?php p($l->t('Current password')); ?>: </label>
204 204
 	<input type="password" id="pass1" name="oldpassword"
205
-		placeholder="<?php p($l->t('Current password'));?>"
205
+		placeholder="<?php p($l->t('Current password')); ?>"
206 206
 		autocomplete="off" autocapitalize="none" autocorrect="off" />
207 207
 	<div class="personal-show-container">
208
-		<label for="pass2" class="hidden-visually"><?php p($l->t('New password'));?>: </label>
208
+		<label for="pass2" class="hidden-visually"><?php p($l->t('New password')); ?>: </label>
209 209
 		<input type="password" id="pass2" name="newpassword"
210 210
 			placeholder="<?php p($l->t('New password')); ?>"
211 211
 			data-typetoggle="#personal-show"
@@ -221,44 +221,44 @@  discard block
 block discarded – undo
221 221
 
222 222
 <form id="language" class="section">
223 223
 	<h2>
224
-		<label for="languageinput"><?php p($l->t('Language'));?></label>
224
+		<label for="languageinput"><?php p($l->t('Language')); ?></label>
225 225
 	</h2>
226
-	<select id="languageinput" name="lang" data-placeholder="<?php p($l->t('Language'));?>">
227
-		<option value="<?php p($_['activelanguage']['code']);?>">
228
-			<?php p($_['activelanguage']['name']);?>
226
+	<select id="languageinput" name="lang" data-placeholder="<?php p($l->t('Language')); ?>">
227
+		<option value="<?php p($_['activelanguage']['code']); ?>">
228
+			<?php p($_['activelanguage']['name']); ?>
229 229
 		</option>
230
-		<?php foreach($_['commonlanguages'] as $language):?>
231
-			<option value="<?php p($language['code']);?>">
232
-				<?php p($language['name']);?>
230
+		<?php foreach ($_['commonlanguages'] as $language):?>
231
+			<option value="<?php p($language['code']); ?>">
232
+				<?php p($language['name']); ?>
233 233
 			</option>
234
-		<?php endforeach;?>
234
+		<?php endforeach; ?>
235 235
 		<optgroup label="––––––––––"></optgroup>
236
-		<?php foreach($_['languages'] as $language):?>
237
-			<option value="<?php p($language['code']);?>">
238
-				<?php p($language['name']);?>
236
+		<?php foreach ($_['languages'] as $language):?>
237
+			<option value="<?php p($language['code']); ?>">
238
+				<?php p($language['name']); ?>
239 239
 			</option>
240
-		<?php endforeach;?>
240
+		<?php endforeach; ?>
241 241
 	</select>
242 242
 	<a href="https://www.transifex.com/nextcloud/nextcloud/"
243 243
 		target="_blank" rel="noreferrer">
244
-		<em><?php p($l->t('Help translate'));?></em>
244
+		<em><?php p($l->t('Help translate')); ?></em>
245 245
 	</a>
246 246
 </form>
247 247
 
248 248
 
249 249
 <div id="clientsbox" class="section clientsbox">
250
-	<h2><?php p($l->t('Get the apps to sync your files'));?></h2>
250
+	<h2><?php p($l->t('Get the apps to sync your files')); ?></h2>
251 251
 	<a href="<?php p($_['clients']['desktop']); ?>" rel="noreferrer" target="_blank">
252 252
 		<img src="<?php print_unescaped(image_path('core', 'desktopapp.svg')); ?>"
253
-			 alt="<?php p($l->t('Desktop client'));?>" />
253
+			 alt="<?php p($l->t('Desktop client')); ?>" />
254 254
 	</a>
255 255
 	<a href="<?php p($_['clients']['android']); ?>" rel="noreferrer" target="_blank">
256 256
 		<img src="<?php print_unescaped(image_path('core', 'googleplay.png')); ?>"
257
-			 alt="<?php p($l->t('Android app'));?>" />
257
+			 alt="<?php p($l->t('Android app')); ?>" />
258 258
 	</a>
259 259
 	<a href="<?php p($_['clients']['ios']); ?>" rel="noreferrer" target="_blank">
260 260
 		<img src="<?php print_unescaped(image_path('core', 'appstore.svg')); ?>"
261
-			 alt="<?php p($l->t('iOS app'));?>" />
261
+			 alt="<?php p($l->t('iOS app')); ?>" />
262 262
 	</a>
263 263
 
264 264
 		<p>
@@ -274,19 +274,19 @@  discard block
 block discarded – undo
274 274
 				$l->t('If you want to support the project {contributeopen}join development{linkclose} or {contributeopen}spread the word{linkclose}!'))); ?>
275 275
 		</p>
276 276
 
277
-	<?php if(OC_APP::isEnabled('firstrunwizard')) {?>
278
-		<p><a class="button" href="#" id="showWizard"><?php p($l->t('Show First Run Wizard again'));?></a></p>
277
+	<?php if (OC_APP::isEnabled('firstrunwizard')) {?>
278
+		<p><a class="button" href="#" id="showWizard"><?php p($l->t('Show First Run Wizard again')); ?></a></p>
279 279
 	<?php }?>
280 280
 </div>
281 281
 
282 282
 <div id="sessions" class="section">
283
-	<h2><?php p($l->t('Sessions'));?></h2>
284
-	<span class="hidden-when-empty"><?php p($l->t('Web, desktop and mobile clients currently logged in to your account.'));?></span>
283
+	<h2><?php p($l->t('Sessions')); ?></h2>
284
+	<span class="hidden-when-empty"><?php p($l->t('Web, desktop and mobile clients currently logged in to your account.')); ?></span>
285 285
 	<table class="icon-loading">
286 286
 		<thead class="token-list-header">
287 287
 			<tr>
288
-				<th><?php p($l->t('Device'));?></th>
289
-				<th><?php p($l->t('Last activity'));?></th>
288
+				<th><?php p($l->t('Device')); ?></th>
289
+				<th><?php p($l->t('Last activity')); ?></th>
290 290
 				<th></th>
291 291
 			</tr>
292 292
 		</thead>
@@ -296,13 +296,13 @@  discard block
 block discarded – undo
296 296
 </div>
297 297
 
298 298
 <div id="apppasswords" class="section">
299
-	<h2><?php p($l->t('App passwords'));?></h2>
300
-	<p><?php p($l->t('Passcodes that give an app or device permissions to access your account.'));?></p>
299
+	<h2><?php p($l->t('App passwords')); ?></h2>
300
+	<p><?php p($l->t('Passcodes that give an app or device permissions to access your account.')); ?></p>
301 301
 	<table class="icon-loading">
302 302
 		<thead class="hidden-when-empty">
303 303
 			<tr>
304
-				<th><?php p($l->t('Name'));?></th>
305
-				<th><?php p($l->t('Last activity'));?></th>
304
+				<th><?php p($l->t('Name')); ?></th>
305
+				<th><?php p($l->t('Last activity')); ?></th>
306 306
 				<th></th>
307 307
 			</tr>
308 308
 		</thead>
@@ -331,14 +331,14 @@  discard block
 block discarded – undo
331 331
 	</div>
332 332
 </div>
333 333
 
334
-<?php foreach($_['forms'] as $form) {
334
+<?php foreach ($_['forms'] as $form) {
335 335
 	if (isset($form['form'])) {?>
336
-	<div id="<?php isset($form['anchor']) ? p($form['anchor']) : p('');?>"><?php print_unescaped($form['form']);?></div>
336
+	<div id="<?php isset($form['anchor']) ? p($form['anchor']) : p(''); ?>"><?php print_unescaped($form['form']); ?></div>
337 337
 	<?php }
338 338
 };?>
339 339
 
340 340
 <div class="section">
341
-	<h2><?php p($l->t('Version'));?></h2>
341
+	<h2><?php p($l->t('Version')); ?></h2>
342 342
 	<p><a href="<?php print_unescaped($theme->getBaseUrl()); ?>" target="_blank"><?php p($theme->getTitle()); ?></a> <?php p(OC_Util::getHumanVersion()) ?></p>
343 343
 	<p><?php include('settings.development.notice.php'); ?></p>
344 344
 </div>
Please login to merge, or discard this patch.
lib/private/Accounts/AccountManager.php 2 patches
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -38,216 +38,216 @@
 block discarded – undo
38 38
  */
39 39
 class AccountManager {
40 40
 
41
-	/** nobody can see my account details */
42
-	const VISIBILITY_PRIVATE = 'private';
43
-	/** only contacts, especially trusted servers can see my contact details */
44
-	const VISIBILITY_CONTACTS_ONLY = 'contacts';
45
-	/** every body ca see my contact detail, will be published to the lookup server */
46
-	const VISIBILITY_PUBLIC = 'public';
47
-
48
-	const PROPERTY_AVATAR = 'avatar';
49
-	const PROPERTY_DISPLAYNAME = 'displayname';
50
-	const PROPERTY_PHONE = 'phone';
51
-	const PROPERTY_EMAIL = 'email';
52
-	const PROPERTY_WEBSITE = 'website';
53
-	const PROPERTY_ADDRESS = 'address';
54
-	const PROPERTY_TWITTER = 'twitter';
55
-
56
-	const NOT_VERIFIED = '0';
57
-	const VERIFICATION_IN_PROGRESS = '1';
58
-	const VERIFIED = '2';
59
-
60
-	/** @var  IDBConnection database connection */
61
-	private $connection;
62
-
63
-	/** @var string table name */
64
-	private $table = 'accounts';
65
-
66
-	/** @var EventDispatcherInterface */
67
-	private $eventDispatcher;
68
-
69
-	/**
70
-	 * AccountManager constructor.
71
-	 *
72
-	 * @param IDBConnection $connection
73
-	 * @param EventDispatcherInterface $eventDispatcher
74
-	 */
75
-	public function __construct(IDBConnection $connection, EventDispatcherInterface $eventDispatcher) {
76
-		$this->connection = $connection;
77
-		$this->eventDispatcher = $eventDispatcher;
78
-	}
79
-
80
-	/**
81
-	 * update user record
82
-	 *
83
-	 * @param IUser $user
84
-	 * @param $data
85
-	 */
86
-	public function updateUser(IUser $user, $data) {
87
-		$userData = $this->getUser($user);
88
-		$updated = true;
89
-		if (empty($userData)) {
90
-			$this->insertNewUser($user, $data);
91
-		} elseif ($userData !== $data) {
92
-			$data = $this->updateVerifyStatus($userData, $data);
93
-			$this->updateExistingUser($user, $data);
94
-		} else {
95
-			// nothing needs to be done if new and old data set are the same
96
-			$updated = false;
97
-		}
98
-
99
-		if ($updated) {
100
-			$this->eventDispatcher->dispatch(
101
-				'OC\AccountManager::userUpdated',
102
-				new GenericEvent($user)
103
-			);
104
-		}
105
-	}
106
-
107
-	/**
108
-	 * get stored data from a given user
109
-	 *
110
-	 * @param IUser $user
111
-	 * @return array
112
-	 */
113
-	public function getUser(IUser $user) {
114
-		$uid = $user->getUID();
115
-		$query = $this->connection->getQueryBuilder();
116
-		$query->select('data')->from($this->table)
117
-			->where($query->expr()->eq('uid', $query->createParameter('uid')))
118
-			->setParameter('uid', $uid);
119
-		$query->execute();
120
-		$result = $query->execute()->fetchAll();
121
-
122
-		if (empty($result)) {
123
-			$userData = $this->buildDefaultUserRecord($user);
124
-			$this->insertNewUser($user, $userData);
125
-			return $userData;
126
-		}
127
-
128
-		return json_decode($result[0]['data'], true);
129
-	}
130
-
131
-	/**
132
-	 * reset verification status if personal data changed
133
-	 *
134
-	 * @param array $oldData
135
-	 * @param array $newData
136
-	 * @return array
137
-	 */
138
-	protected function updateVerifyStatus($oldData, $newData) {
139
-
140
-		$twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED;
141
-		$websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED;
142
-		$emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED;
143
-
144
-		if($twitterVerified &&
145
-			$oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value']
146
-		) {
147
-			$newData[self::PROPERTY_TWITTER]['value']['verified'] = self::NOT_VERIFIED;
148
-		}
149
-
150
-		if($websiteVerified &&
151
-			$oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value']
152
-		) {
153
-			$newData[self::PROPERTY_WEBSITE]['value']['verified'] = self::NOT_VERIFIED;
154
-		}
155
-
156
-		if($emailVerified &&
157
-			$oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']
158
-		) {
159
-			$newData[self::PROPERTY_EMAIL]['value']['verified'] = self::NOT_VERIFIED;
160
-		}
161
-
162
-		return $newData;
163
-
164
-	}
165
-
166
-	/**
167
-	 * add new user to accounts table
168
-	 *
169
-	 * @param IUser $user
170
-	 * @param array $data
171
-	 */
172
-	protected function insertNewUser(IUser $user, $data) {
173
-		$uid = $user->getUID();
174
-		$jsonEncodedData = json_encode($data);
175
-		$query = $this->connection->getQueryBuilder();
176
-		$query->insert($this->table)
177
-			->values(
178
-				[
179
-					'uid' => $query->createNamedParameter($uid),
180
-					'data' => $query->createNamedParameter($jsonEncodedData),
181
-				]
182
-			)
183
-			->execute();
184
-	}
185
-
186
-	/**
187
-	 * update existing user in accounts table
188
-	 *
189
-	 * @param IUser $user
190
-	 * @param array $data
191
-	 */
192
-	protected function updateExistingUser(IUser $user, $data) {
193
-		$uid = $user->getUID();
194
-		$jsonEncodedData = json_encode($data);
195
-		$query = $this->connection->getQueryBuilder();
196
-		$query->update($this->table)
197
-			->set('data', $query->createNamedParameter($jsonEncodedData))
198
-			->where($query->expr()->eq('uid', $query->createNamedParameter($uid)))
199
-			->execute();
200
-	}
201
-
202
-	/**
203
-	 * build default user record in case not data set exists yet
204
-	 *
205
-	 * @param IUser $user
206
-	 * @return array
207
-	 */
208
-	protected function buildDefaultUserRecord(IUser $user) {
209
-		return [
210
-			self::PROPERTY_DISPLAYNAME =>
211
-				[
212
-					'value' => $user->getDisplayName(),
213
-					'scope' => self::VISIBILITY_CONTACTS_ONLY,
214
-					'verified' => '0',
215
-				],
216
-			self::PROPERTY_ADDRESS =>
217
-				[
218
-					'value' => '',
219
-					'scope' => self::VISIBILITY_PRIVATE,
220
-					'verified' => '0',
221
-				],
222
-			self::PROPERTY_WEBSITE =>
223
-				[
224
-					'value' => '',
225
-					'scope' => self::VISIBILITY_PRIVATE,
226
-					'verified' => '0',
227
-				],
228
-			self::PROPERTY_EMAIL =>
229
-				[
230
-					'value' => $user->getEMailAddress(),
231
-					'scope' => self::VISIBILITY_CONTACTS_ONLY,
232
-					'verified' => '0',
233
-				],
234
-			self::PROPERTY_AVATAR =>
235
-				[
236
-					'scope' => self::VISIBILITY_CONTACTS_ONLY
237
-				],
238
-			self::PROPERTY_PHONE =>
239
-				[
240
-					'value' => '',
241
-					'scope' => self::VISIBILITY_PRIVATE,
242
-					'verified' => '0',
243
-				],
244
-			self::PROPERTY_TWITTER =>
245
-				[
246
-					'value' => '',
247
-					'scope' => self::VISIBILITY_PRIVATE,
248
-					'verified' => '0',
249
-				],
250
-		];
251
-	}
41
+    /** nobody can see my account details */
42
+    const VISIBILITY_PRIVATE = 'private';
43
+    /** only contacts, especially trusted servers can see my contact details */
44
+    const VISIBILITY_CONTACTS_ONLY = 'contacts';
45
+    /** every body ca see my contact detail, will be published to the lookup server */
46
+    const VISIBILITY_PUBLIC = 'public';
47
+
48
+    const PROPERTY_AVATAR = 'avatar';
49
+    const PROPERTY_DISPLAYNAME = 'displayname';
50
+    const PROPERTY_PHONE = 'phone';
51
+    const PROPERTY_EMAIL = 'email';
52
+    const PROPERTY_WEBSITE = 'website';
53
+    const PROPERTY_ADDRESS = 'address';
54
+    const PROPERTY_TWITTER = 'twitter';
55
+
56
+    const NOT_VERIFIED = '0';
57
+    const VERIFICATION_IN_PROGRESS = '1';
58
+    const VERIFIED = '2';
59
+
60
+    /** @var  IDBConnection database connection */
61
+    private $connection;
62
+
63
+    /** @var string table name */
64
+    private $table = 'accounts';
65
+
66
+    /** @var EventDispatcherInterface */
67
+    private $eventDispatcher;
68
+
69
+    /**
70
+     * AccountManager constructor.
71
+     *
72
+     * @param IDBConnection $connection
73
+     * @param EventDispatcherInterface $eventDispatcher
74
+     */
75
+    public function __construct(IDBConnection $connection, EventDispatcherInterface $eventDispatcher) {
76
+        $this->connection = $connection;
77
+        $this->eventDispatcher = $eventDispatcher;
78
+    }
79
+
80
+    /**
81
+     * update user record
82
+     *
83
+     * @param IUser $user
84
+     * @param $data
85
+     */
86
+    public function updateUser(IUser $user, $data) {
87
+        $userData = $this->getUser($user);
88
+        $updated = true;
89
+        if (empty($userData)) {
90
+            $this->insertNewUser($user, $data);
91
+        } elseif ($userData !== $data) {
92
+            $data = $this->updateVerifyStatus($userData, $data);
93
+            $this->updateExistingUser($user, $data);
94
+        } else {
95
+            // nothing needs to be done if new and old data set are the same
96
+            $updated = false;
97
+        }
98
+
99
+        if ($updated) {
100
+            $this->eventDispatcher->dispatch(
101
+                'OC\AccountManager::userUpdated',
102
+                new GenericEvent($user)
103
+            );
104
+        }
105
+    }
106
+
107
+    /**
108
+     * get stored data from a given user
109
+     *
110
+     * @param IUser $user
111
+     * @return array
112
+     */
113
+    public function getUser(IUser $user) {
114
+        $uid = $user->getUID();
115
+        $query = $this->connection->getQueryBuilder();
116
+        $query->select('data')->from($this->table)
117
+            ->where($query->expr()->eq('uid', $query->createParameter('uid')))
118
+            ->setParameter('uid', $uid);
119
+        $query->execute();
120
+        $result = $query->execute()->fetchAll();
121
+
122
+        if (empty($result)) {
123
+            $userData = $this->buildDefaultUserRecord($user);
124
+            $this->insertNewUser($user, $userData);
125
+            return $userData;
126
+        }
127
+
128
+        return json_decode($result[0]['data'], true);
129
+    }
130
+
131
+    /**
132
+     * reset verification status if personal data changed
133
+     *
134
+     * @param array $oldData
135
+     * @param array $newData
136
+     * @return array
137
+     */
138
+    protected function updateVerifyStatus($oldData, $newData) {
139
+
140
+        $twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED;
141
+        $websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED;
142
+        $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED;
143
+
144
+        if($twitterVerified &&
145
+            $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value']
146
+        ) {
147
+            $newData[self::PROPERTY_TWITTER]['value']['verified'] = self::NOT_VERIFIED;
148
+        }
149
+
150
+        if($websiteVerified &&
151
+            $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value']
152
+        ) {
153
+            $newData[self::PROPERTY_WEBSITE]['value']['verified'] = self::NOT_VERIFIED;
154
+        }
155
+
156
+        if($emailVerified &&
157
+            $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']
158
+        ) {
159
+            $newData[self::PROPERTY_EMAIL]['value']['verified'] = self::NOT_VERIFIED;
160
+        }
161
+
162
+        return $newData;
163
+
164
+    }
165
+
166
+    /**
167
+     * add new user to accounts table
168
+     *
169
+     * @param IUser $user
170
+     * @param array $data
171
+     */
172
+    protected function insertNewUser(IUser $user, $data) {
173
+        $uid = $user->getUID();
174
+        $jsonEncodedData = json_encode($data);
175
+        $query = $this->connection->getQueryBuilder();
176
+        $query->insert($this->table)
177
+            ->values(
178
+                [
179
+                    'uid' => $query->createNamedParameter($uid),
180
+                    'data' => $query->createNamedParameter($jsonEncodedData),
181
+                ]
182
+            )
183
+            ->execute();
184
+    }
185
+
186
+    /**
187
+     * update existing user in accounts table
188
+     *
189
+     * @param IUser $user
190
+     * @param array $data
191
+     */
192
+    protected function updateExistingUser(IUser $user, $data) {
193
+        $uid = $user->getUID();
194
+        $jsonEncodedData = json_encode($data);
195
+        $query = $this->connection->getQueryBuilder();
196
+        $query->update($this->table)
197
+            ->set('data', $query->createNamedParameter($jsonEncodedData))
198
+            ->where($query->expr()->eq('uid', $query->createNamedParameter($uid)))
199
+            ->execute();
200
+    }
201
+
202
+    /**
203
+     * build default user record in case not data set exists yet
204
+     *
205
+     * @param IUser $user
206
+     * @return array
207
+     */
208
+    protected function buildDefaultUserRecord(IUser $user) {
209
+        return [
210
+            self::PROPERTY_DISPLAYNAME =>
211
+                [
212
+                    'value' => $user->getDisplayName(),
213
+                    'scope' => self::VISIBILITY_CONTACTS_ONLY,
214
+                    'verified' => '0',
215
+                ],
216
+            self::PROPERTY_ADDRESS =>
217
+                [
218
+                    'value' => '',
219
+                    'scope' => self::VISIBILITY_PRIVATE,
220
+                    'verified' => '0',
221
+                ],
222
+            self::PROPERTY_WEBSITE =>
223
+                [
224
+                    'value' => '',
225
+                    'scope' => self::VISIBILITY_PRIVATE,
226
+                    'verified' => '0',
227
+                ],
228
+            self::PROPERTY_EMAIL =>
229
+                [
230
+                    'value' => $user->getEMailAddress(),
231
+                    'scope' => self::VISIBILITY_CONTACTS_ONLY,
232
+                    'verified' => '0',
233
+                ],
234
+            self::PROPERTY_AVATAR =>
235
+                [
236
+                    'scope' => self::VISIBILITY_CONTACTS_ONLY
237
+                ],
238
+            self::PROPERTY_PHONE =>
239
+                [
240
+                    'value' => '',
241
+                    'scope' => self::VISIBILITY_PRIVATE,
242
+                    'verified' => '0',
243
+                ],
244
+            self::PROPERTY_TWITTER =>
245
+                [
246
+                    'value' => '',
247
+                    'scope' => self::VISIBILITY_PRIVATE,
248
+                    'verified' => '0',
249
+                ],
250
+        ];
251
+    }
252 252
 
253 253
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -141,19 +141,19 @@
 block discarded – undo
141 141
 		$websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED;
142 142
 		$emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED;
143 143
 
144
-		if($twitterVerified &&
144
+		if ($twitterVerified &&
145 145
 			$oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value']
146 146
 		) {
147 147
 			$newData[self::PROPERTY_TWITTER]['value']['verified'] = self::NOT_VERIFIED;
148 148
 		}
149 149
 
150
-		if($websiteVerified &&
150
+		if ($websiteVerified &&
151 151
 			$oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value']
152 152
 		) {
153 153
 			$newData[self::PROPERTY_WEBSITE]['value']['verified'] = self::NOT_VERIFIED;
154 154
 		}
155 155
 
156
-		if($emailVerified &&
156
+		if ($emailVerified &&
157 157
 			$oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']
158 158
 		) {
159 159
 			$newData[self::PROPERTY_EMAIL]['value']['verified'] = self::NOT_VERIFIED;
Please login to merge, or discard this patch.
settings/Controller/UsersController.php 2 patches
Indentation   +855 added lines, -855 removed lines patch added patch discarded remove patch
@@ -57,860 +57,860 @@
 block discarded – undo
57 57
  * @package OC\Settings\Controller
58 58
  */
59 59
 class UsersController extends Controller {
60
-	/** @var IL10N */
61
-	private $l10n;
62
-	/** @var IUserSession */
63
-	private $userSession;
64
-	/** @var bool */
65
-	private $isAdmin;
66
-	/** @var IUserManager */
67
-	private $userManager;
68
-	/** @var IGroupManager */
69
-	private $groupManager;
70
-	/** @var IConfig */
71
-	private $config;
72
-	/** @var ILogger */
73
-	private $log;
74
-	/** @var \OC_Defaults */
75
-	private $defaults;
76
-	/** @var IMailer */
77
-	private $mailer;
78
-	/** @var string */
79
-	private $fromMailAddress;
80
-	/** @var IURLGenerator */
81
-	private $urlGenerator;
82
-	/** @var bool contains the state of the encryption app */
83
-	private $isEncryptionAppEnabled;
84
-	/** @var bool contains the state of the admin recovery setting */
85
-	private $isRestoreEnabled = false;
86
-	/** @var IAvatarManager */
87
-	private $avatarManager;
88
-	/** @var AccountManager */
89
-	private $accountManager;
90
-	/** @var ISecureRandom */
91
-	private $secureRandom;
92
-	/** @var ITimeFactory */
93
-	private $timeFactory;
94
-	/** @var ICrypto */
95
-	private $crypto;
96
-	/** @var Manager */
97
-	private $keyManager;
98
-
99
-
100
-	/**
101
-	 * @param string $appName
102
-	 * @param IRequest $request
103
-	 * @param IUserManager $userManager
104
-	 * @param IGroupManager $groupManager
105
-	 * @param IUserSession $userSession
106
-	 * @param IConfig $config
107
-	 * @param bool $isAdmin
108
-	 * @param IL10N $l10n
109
-	 * @param ILogger $log
110
-	 * @param \OC_Defaults $defaults
111
-	 * @param IMailer $mailer
112
-	 * @param string $fromMailAddress
113
-	 * @param IURLGenerator $urlGenerator
114
-	 * @param IAppManager $appManager
115
-	 * @param IAvatarManager $avatarManager
116
-	 * @param AccountManager $accountManager
117
-	 * @param ISecureRandom $secureRandom
118
-	 * @param ITimeFactory $timeFactory
119
-	 * @param ICrypto $crypto
120
-	 * @param Manager $keyManager
121
-	 */
122
-	public function __construct($appName,
123
-								IRequest $request,
124
-								IUserManager $userManager,
125
-								IGroupManager $groupManager,
126
-								IUserSession $userSession,
127
-								IConfig $config,
128
-								$isAdmin,
129
-								IL10N $l10n,
130
-								ILogger $log,
131
-								\OC_Defaults $defaults,
132
-								IMailer $mailer,
133
-								$fromMailAddress,
134
-								IURLGenerator $urlGenerator,
135
-								IAppManager $appManager,
136
-								IAvatarManager $avatarManager,
137
-								AccountManager $accountManager,
138
-								ISecureRandom $secureRandom,
139
-								ITimeFactory $timeFactory,
140
-								ICrypto $crypto,
141
-								Manager $keyManager) {
142
-		parent::__construct($appName, $request);
143
-		$this->userManager = $userManager;
144
-		$this->groupManager = $groupManager;
145
-		$this->userSession = $userSession;
146
-		$this->config = $config;
147
-		$this->isAdmin = $isAdmin;
148
-		$this->l10n = $l10n;
149
-		$this->log = $log;
150
-		$this->defaults = $defaults;
151
-		$this->mailer = $mailer;
152
-		$this->fromMailAddress = $fromMailAddress;
153
-		$this->urlGenerator = $urlGenerator;
154
-		$this->avatarManager = $avatarManager;
155
-		$this->accountManager = $accountManager;
156
-		$this->secureRandom = $secureRandom;
157
-		$this->timeFactory = $timeFactory;
158
-		$this->crypto = $crypto;
159
-		$this->keyManager = $keyManager;
160
-
161
-		// check for encryption state - TODO see formatUserForIndex
162
-		$this->isEncryptionAppEnabled = $appManager->isEnabledForUser('encryption');
163
-		if($this->isEncryptionAppEnabled) {
164
-			// putting this directly in empty is possible in PHP 5.5+
165
-			$result = $config->getAppValue('encryption', 'recoveryAdminEnabled', 0);
166
-			$this->isRestoreEnabled = !empty($result);
167
-		}
168
-	}
169
-
170
-	/**
171
-	 * @param IUser $user
172
-	 * @param array $userGroups
173
-	 * @return array
174
-	 */
175
-	private function formatUserForIndex(IUser $user, array $userGroups = null) {
176
-
177
-		// TODO: eliminate this encryption specific code below and somehow
178
-		// hook in additional user info from other apps
179
-
180
-		// recovery isn't possible if admin or user has it disabled and encryption
181
-		// is enabled - so we eliminate the else paths in the conditional tree
182
-		// below
183
-		$restorePossible = false;
184
-
185
-		if ($this->isEncryptionAppEnabled) {
186
-			if ($this->isRestoreEnabled) {
187
-				// check for the users recovery setting
188
-				$recoveryMode = $this->config->getUserValue($user->getUID(), 'encryption', 'recoveryEnabled', '0');
189
-				// method call inside empty is possible with PHP 5.5+
190
-				$recoveryModeEnabled = !empty($recoveryMode);
191
-				if ($recoveryModeEnabled) {
192
-					// user also has recovery mode enabled
193
-					$restorePossible = true;
194
-				}
195
-			}
196
-		} else {
197
-			// recovery is possible if encryption is disabled (plain files are
198
-			// available)
199
-			$restorePossible = true;
200
-		}
201
-
202
-		$subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
203
-		foreach($subAdminGroups as $key => $subAdminGroup) {
204
-			$subAdminGroups[$key] = $subAdminGroup->getGID();
205
-		}
206
-
207
-		$displayName = $user->getEMailAddress();
208
-		if (is_null($displayName)) {
209
-			$displayName = '';
210
-		}
211
-
212
-		$avatarAvailable = false;
213
-		try {
214
-			$avatarAvailable = $this->avatarManager->getAvatar($user->getUID())->exists();
215
-		} catch (\Exception $e) {
216
-			//No avatar yet
217
-		}
218
-
219
-		return [
220
-			'name' => $user->getUID(),
221
-			'displayname' => $user->getDisplayName(),
222
-			'groups' => (empty($userGroups)) ? $this->groupManager->getUserGroupIds($user) : $userGroups,
223
-			'subadmin' => $subAdminGroups,
224
-			'quota' => $user->getQuota(),
225
-			'storageLocation' => $user->getHome(),
226
-			'lastLogin' => $user->getLastLogin() * 1000,
227
-			'backend' => $user->getBackendClassName(),
228
-			'email' => $displayName,
229
-			'isRestoreDisabled' => !$restorePossible,
230
-			'isAvatarAvailable' => $avatarAvailable,
231
-		];
232
-	}
233
-
234
-	/**
235
-	 * @param array $userIDs Array with schema [$uid => $displayName]
236
-	 * @return IUser[]
237
-	 */
238
-	private function getUsersForUID(array $userIDs) {
239
-		$users = [];
240
-		foreach ($userIDs as $uid => $displayName) {
241
-			$users[$uid] = $this->userManager->get($uid);
242
-		}
243
-		return $users;
244
-	}
245
-
246
-	/**
247
-	 * @NoAdminRequired
248
-	 *
249
-	 * @param int $offset
250
-	 * @param int $limit
251
-	 * @param string $gid GID to filter for
252
-	 * @param string $pattern Pattern to search for in the username
253
-	 * @param string $backend Backend to filter for (class-name)
254
-	 * @return DataResponse
255
-	 *
256
-	 * TODO: Tidy up and write unit tests - code is mainly static method calls
257
-	 */
258
-	public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '') {
259
-		// FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group.
260
-		if($gid === '_everyone') {
261
-			$gid = '';
262
-		}
263
-
264
-		// Remove backends
265
-		if(!empty($backend)) {
266
-			$activeBackends = $this->userManager->getBackends();
267
-			$this->userManager->clearBackends();
268
-			foreach($activeBackends as $singleActiveBackend) {
269
-				if($backend === get_class($singleActiveBackend)) {
270
-					$this->userManager->registerBackend($singleActiveBackend);
271
-					break;
272
-				}
273
-			}
274
-		}
275
-
276
-		$users = [];
277
-		if ($this->isAdmin) {
278
-
279
-			if($gid !== '') {
280
-				$batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset));
281
-			} else {
282
-				$batch = $this->userManager->search($pattern, $limit, $offset);
283
-			}
284
-
285
-			foreach ($batch as $user) {
286
-				$users[] = $this->formatUserForIndex($user);
287
-			}
288
-
289
-		} else {
290
-			$subAdminOfGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser());
291
-			// New class returns IGroup[] so convert back
292
-			$gids = [];
293
-			foreach ($subAdminOfGroups as $group) {
294
-				$gids[] = $group->getGID();
295
-			}
296
-			$subAdminOfGroups = $gids;
297
-
298
-			// Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group
299
-			if($gid !== '' && !in_array($gid, $subAdminOfGroups)) {
300
-				$gid = '';
301
-			}
302
-
303
-			// Batch all groups the user is subadmin of when a group is specified
304
-			$batch = [];
305
-			if($gid === '') {
306
-				foreach($subAdminOfGroups as $group) {
307
-					$groupUsers = $this->groupManager->displayNamesInGroup($group, $pattern, $limit, $offset);
308
-
309
-					foreach($groupUsers as $uid => $displayName) {
310
-						$batch[$uid] = $displayName;
311
-					}
312
-				}
313
-			} else {
314
-				$batch = $this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset);
315
-			}
316
-			$batch = $this->getUsersForUID($batch);
317
-
318
-			foreach ($batch as $user) {
319
-				// Only add the groups, this user is a subadmin of
320
-				$userGroups = array_values(array_intersect(
321
-					$this->groupManager->getUserGroupIds($user),
322
-					$subAdminOfGroups
323
-				));
324
-				$users[] = $this->formatUserForIndex($user, $userGroups);
325
-			}
326
-		}
327
-
328
-		return new DataResponse($users);
329
-	}
330
-
331
-	/**
332
-	 * @NoAdminRequired
333
-	 * @PasswordConfirmationRequired
334
-	 *
335
-	 * @param string $username
336
-	 * @param string $password
337
-	 * @param array $groups
338
-	 * @param string $email
339
-	 * @return DataResponse
340
-	 */
341
-	public function create($username, $password, array $groups=array(), $email='') {
342
-		if($email !== '' && !$this->mailer->validateMailAddress($email)) {
343
-			return new DataResponse(
344
-				array(
345
-					'message' => (string)$this->l10n->t('Invalid mail address')
346
-				),
347
-				Http::STATUS_UNPROCESSABLE_ENTITY
348
-			);
349
-		}
350
-
351
-		$currentUser = $this->userSession->getUser();
352
-
353
-		if (!$this->isAdmin) {
354
-			if (!empty($groups)) {
355
-				foreach ($groups as $key => $group) {
356
-					$groupObject = $this->groupManager->get($group);
357
-					if($groupObject === null) {
358
-						unset($groups[$key]);
359
-						continue;
360
-					}
361
-
362
-					if (!$this->groupManager->getSubAdmin()->isSubAdminofGroup($currentUser, $groupObject)) {
363
-						unset($groups[$key]);
364
-					}
365
-				}
366
-			}
367
-
368
-			if (empty($groups)) {
369
-				return new DataResponse(
370
-					array(
371
-						'message' => $this->l10n->t('No valid group selected'),
372
-					),
373
-					Http::STATUS_FORBIDDEN
374
-				);
375
-			}
376
-		}
377
-
378
-		if ($this->userManager->userExists($username)) {
379
-			return new DataResponse(
380
-				array(
381
-					'message' => (string)$this->l10n->t('A user with that name already exists.')
382
-				),
383
-				Http::STATUS_CONFLICT
384
-			);
385
-		}
386
-
387
-		$generatedPassword = false;
388
-		if ($password === '') {
389
-			if ($email === '') {
390
-				return new DataResponse(
391
-					array(
392
-						'message' => (string)$this->l10n->t('To send a password link to the user an email address is required.')
393
-					),
394
-					Http::STATUS_UNPROCESSABLE_ENTITY
395
-				);
396
-			}
397
-
398
-			$password = $this->secureRandom->generate(32);
399
-			$generatedPassword = true;
400
-		}
401
-
402
-		try {
403
-			$user = $this->userManager->createUser($username, $password);
404
-		} catch (\Exception $exception) {
405
-			$message = $exception->getMessage();
406
-			if (!$message) {
407
-				$message = $this->l10n->t('Unable to create user.');
408
-			}
409
-			return new DataResponse(
410
-				array(
411
-					'message' => (string) $message,
412
-				),
413
-				Http::STATUS_FORBIDDEN
414
-			);
415
-		}
416
-
417
-		if($user instanceof IUser) {
418
-			if($groups !== null) {
419
-				foreach($groups as $groupName) {
420
-					$group = $this->groupManager->get($groupName);
421
-
422
-					if(empty($group)) {
423
-						$group = $this->groupManager->createGroup($groupName);
424
-					}
425
-					$group->addUser($user);
426
-				}
427
-			}
428
-			/**
429
-			 * Send new user mail only if a mail is set
430
-			 */
431
-			if($email !== '') {
432
-				$user->setEMailAddress($email);
433
-
434
-				if ($generatedPassword) {
435
-					$token = $this->secureRandom->generate(
436
-						21,
437
-						ISecureRandom::CHAR_DIGITS .
438
-						ISecureRandom::CHAR_LOWER .
439
-						ISecureRandom::CHAR_UPPER
440
-					);
441
-					$tokenValue = $this->timeFactory->getTime() . ':' . $token;
442
-					$mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : '';
443
-					$encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress . $this->config->getSystemValue('secret'));
444
-					$this->config->setUserValue($username, 'core', 'lostpassword', $encryptedValue);
445
-
446
-					$link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $username, 'token' => $token]);
447
-				} else {
448
-					$link = $this->urlGenerator->getAbsoluteURL('/');
449
-				}
450
-
451
-				// data for the mail template
452
-				$mailData = array(
453
-					'username' => $username,
454
-					'url' => $link
455
-				);
456
-
457
-				$mail = new TemplateResponse('settings', 'email.new_user', $mailData, 'blank');
458
-				$mailContent = $mail->render();
459
-
460
-				$mail = new TemplateResponse('settings', 'email.new_user_plain_text', $mailData, 'blank');
461
-				$plainTextMailContent = $mail->render();
462
-
463
-				$subject = $this->l10n->t('Your %s account was created', [$this->defaults->getName()]);
464
-
465
-				try {
466
-					$message = $this->mailer->createMessage();
467
-					$message->setTo([$email => $username]);
468
-					$message->setSubject($subject);
469
-					$message->setHtmlBody($mailContent);
470
-					$message->setPlainBody($plainTextMailContent);
471
-					$message->setFrom([$this->fromMailAddress => $this->defaults->getName()]);
472
-					$this->mailer->send($message);
473
-				} catch(\Exception $e) {
474
-					$this->log->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings'));
475
-				}
476
-			}
477
-			// fetch users groups
478
-			$userGroups = $this->groupManager->getUserGroupIds($user);
479
-
480
-			return new DataResponse(
481
-				$this->formatUserForIndex($user, $userGroups),
482
-				Http::STATUS_CREATED
483
-			);
484
-		}
485
-
486
-		return new DataResponse(
487
-			array(
488
-				'message' => (string)$this->l10n->t('Unable to create user.')
489
-			),
490
-			Http::STATUS_FORBIDDEN
491
-		);
492
-
493
-	}
494
-
495
-	/**
496
-	 * @NoAdminRequired
497
-	 * @PasswordConfirmationRequired
498
-	 *
499
-	 * @param string $id
500
-	 * @return DataResponse
501
-	 */
502
-	public function destroy($id) {
503
-		$userId = $this->userSession->getUser()->getUID();
504
-		$user = $this->userManager->get($id);
505
-
506
-		if($userId === $id) {
507
-			return new DataResponse(
508
-				array(
509
-					'status' => 'error',
510
-					'data' => array(
511
-						'message' => (string)$this->l10n->t('Unable to delete user.')
512
-					)
513
-				),
514
-				Http::STATUS_FORBIDDEN
515
-			);
516
-		}
517
-
518
-		if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) {
519
-			return new DataResponse(
520
-				array(
521
-					'status' => 'error',
522
-					'data' => array(
523
-						'message' => (string)$this->l10n->t('Authentication error')
524
-					)
525
-				),
526
-				Http::STATUS_FORBIDDEN
527
-			);
528
-		}
529
-
530
-		if($user) {
531
-			if($user->delete()) {
532
-				return new DataResponse(
533
-					array(
534
-						'status' => 'success',
535
-						'data' => array(
536
-							'username' => $id
537
-						)
538
-					),
539
-					Http::STATUS_NO_CONTENT
540
-				);
541
-			}
542
-		}
543
-
544
-		return new DataResponse(
545
-			array(
546
-				'status' => 'error',
547
-				'data' => array(
548
-					'message' => (string)$this->l10n->t('Unable to delete user.')
549
-				)
550
-			),
551
-			Http::STATUS_FORBIDDEN
552
-		);
553
-	}
554
-
555
-	/**
556
-	 * @NoAdminRequired
557
-	 * @NoSubadminRequired
558
-	 * @PasswordConfirmationRequired
559
-	 *
560
-	 * @param string $account
561
-	 * @return DataResponse
562
-	 */
563
-	public function getVerificationCode($account) {
564
-
565
-		$user = $this->userSession->getUser();
566
-
567
-		if ($user === null) {
568
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
569
-		}
570
-
571
-		$accountData = $this->accountManager->getUser($user);
572
-		$cloudId = $user->getCloudId();
573
-		$message = "Use my Federated Cloud ID to share with me: " . $cloudId;
574
-		$privateKey = $this->keyManager->getKey($user)->getPrivate();
575
-		openssl_sign(json_encode($message), $signature, $privateKey, OPENSSL_ALGO_SHA512);
576
-		$signatureBase64 = base64_encode($signature);
577
-
578
-		$code = $message . ' ' . $signatureBase64;
579
-		$codeMd5 = $message . ' ' . md5($signatureBase64);
580
-
581
-		switch ($account) {
582
-			case 'verify-twitter':
583
-				$accountData[AccountManager::PROPERTY_TWITTER]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
584
-				$msg = $this->l10n->t('In order to verify your Twitter account post following tweet on Twitter:');
585
-				$code = $codeMd5;
586
-				break;
587
-			case 'verify-website':
588
-				$accountData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
589
-				$msg = $this->l10n->t('In order to verify your Website store following content in your webroot at \'CloudIdVerificationCode.txt\':');
590
-				break;
591
-			default:
592
-				return new DataResponse([], Http::STATUS_BAD_REQUEST);
593
-		}
594
-
595
-		$this->accountManager->updateUser($user, $accountData);
596
-
597
-		return new DataResponse(['msg' => $msg, 'code' => $code]);
598
-	}
599
-
600
-	/**
601
-	 * @NoAdminRequired
602
-	 * @NoSubadminRequired
603
-	 * @PasswordConfirmationRequired
604
-	 *
605
-	 * @param string $avatarScope
606
-	 * @param string $displayname
607
-	 * @param string $displaynameScope
608
-	 * @param string $phone
609
-	 * @param string $phoneScope
610
-	 * @param string $email
611
-	 * @param string $emailScope
612
-	 * @param string $website
613
-	 * @param string $websiteScope
614
-	 * @param string $address
615
-	 * @param string $addressScope
616
-	 * @param string $twitter
617
-	 * @param string $twitterScope
618
-	 * @return DataResponse
619
-	 */
620
-	public function setUserSettings($avatarScope,
621
-									$displayname,
622
-									$displaynameScope,
623
-									$phone,
624
-									$phoneScope,
625
-									$email,
626
-									$emailScope,
627
-									$website,
628
-									$websiteScope,
629
-									$address,
630
-									$addressScope,
631
-									$twitter,
632
-									$twitterScope
633
-	) {
634
-
635
-		if(!empty($email) && !$this->mailer->validateMailAddress($email)) {
636
-			return new DataResponse(
637
-				array(
638
-					'status' => 'error',
639
-					'data' => array(
640
-						'message' => (string)$this->l10n->t('Invalid mail address')
641
-					)
642
-				),
643
-				Http::STATUS_UNPROCESSABLE_ENTITY
644
-			);
645
-		}
646
-
647
-		$data = [
648
-			AccountManager::PROPERTY_AVATAR =>  ['scope' => $avatarScope],
649
-			AccountManager::PROPERTY_DISPLAYNAME => ['value' => $displayname, 'scope' => $displaynameScope],
650
-			AccountManager::PROPERTY_EMAIL=> ['value' => $email, 'scope' => $emailScope],
651
-			AccountManager::PROPERTY_WEBSITE => ['value' => $website, 'scope' => $websiteScope],
652
-			AccountManager::PROPERTY_ADDRESS => ['value' => $address, 'scope' => $addressScope],
653
-			AccountManager::PROPERTY_PHONE => ['value' => $phone, 'scope' => $phoneScope],
654
-			AccountManager::PROPERTY_TWITTER => ['value' => $twitter, 'scope' => $twitterScope]
655
-		];
656
-
657
-		$user = $this->userSession->getUser();
658
-
659
-		try {
660
-			$this->saveUserSettings($user, $data);
661
-			return new DataResponse(
662
-				array(
663
-					'status' => 'success',
664
-					'data' => array(
665
-						'userId' => $user->getUID(),
666
-						'avatarScope' => $avatarScope,
667
-						'displayname' => $displayname,
668
-						'displaynameScope' => $displaynameScope,
669
-						'email' => $email,
670
-						'emailScope' => $emailScope,
671
-						'website' => $website,
672
-						'websiteScope' => $websiteScope,
673
-						'address' => $address,
674
-						'addressScope' => $addressScope,
675
-						'message' => (string)$this->l10n->t('Settings saved')
676
-					)
677
-				),
678
-				Http::STATUS_OK
679
-			);
680
-		} catch (ForbiddenException $e) {
681
-			return new DataResponse([
682
-				'status' => 'error',
683
-				'data' => [
684
-					'message' => $e->getMessage()
685
-				],
686
-			]);
687
-		}
688
-
689
-	}
690
-
691
-
692
-	/**
693
-	 * update account manager with new user data
694
-	 *
695
-	 * @param IUser $user
696
-	 * @param array $data
697
-	 * @throws ForbiddenException
698
-	 */
699
-	protected function saveUserSettings(IUser $user, $data) {
700
-
701
-		// keep the user back-end up-to-date with the latest display name and email
702
-		// address
703
-		$oldDisplayName = $user->getDisplayName();
704
-		$oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName;
705
-		if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value'])
706
-			&& $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value']
707
-		) {
708
-			$result = $user->setDisplayName($data[AccountManager::PROPERTY_DISPLAYNAME]['value']);
709
-			if ($result === false) {
710
-				throw new ForbiddenException($this->l10n->t('Unable to change full name'));
711
-			}
712
-		}
713
-
714
-		$oldEmailAddress = $user->getEMailAddress();
715
-		$oldEmailAddress = is_null($oldEmailAddress) ? '' : $oldEmailAddress;
716
-		if (isset($data[AccountManager::PROPERTY_EMAIL]['value'])
717
-			&& $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value']
718
-		) {
719
-			// this is the only permission a backend provides and is also used
720
-			// for the permission of setting a email address
721
-			if (!$user->canChangeDisplayName()) {
722
-				throw new ForbiddenException($this->l10n->t('Unable to change email address'));
723
-			}
724
-			$user->setEMailAddress($data[AccountManager::PROPERTY_EMAIL]['value']);
725
-		}
726
-
727
-		$this->accountManager->updateUser($user, $data);
728
-	}
729
-
730
-	/**
731
-	 * Count all unique users visible for the current admin/subadmin.
732
-	 *
733
-	 * @NoAdminRequired
734
-	 *
735
-	 * @return DataResponse
736
-	 */
737
-	public function stats() {
738
-		$userCount = 0;
739
-		if ($this->isAdmin) {
740
-			$countByBackend = $this->userManager->countUsers();
741
-
742
-			if (!empty($countByBackend)) {
743
-				foreach ($countByBackend as $count) {
744
-					$userCount += $count;
745
-				}
746
-			}
747
-		} else {
748
-			$groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser());
749
-
750
-			$uniqueUsers = [];
751
-			foreach ($groups as $group) {
752
-				foreach($group->getUsers() as $uid => $displayName) {
753
-					$uniqueUsers[$uid] = true;
754
-				}
755
-			}
756
-
757
-			$userCount = count($uniqueUsers);
758
-		}
759
-
760
-		return new DataResponse(
761
-			[
762
-				'totalUsers' => $userCount
763
-			]
764
-		);
765
-	}
766
-
767
-
768
-	/**
769
-	 * Set the displayName of a user
770
-	 *
771
-	 * @NoAdminRequired
772
-	 * @NoSubadminRequired
773
-	 * @PasswordConfirmationRequired
774
-	 * @todo merge into saveUserSettings
775
-	 *
776
-	 * @param string $username
777
-	 * @param string $displayName
778
-	 * @return DataResponse
779
-	 */
780
-	public function setDisplayName($username, $displayName) {
781
-		$currentUser = $this->userSession->getUser();
782
-		$user = $this->userManager->get($username);
783
-
784
-		if ($user === null ||
785
-			!$user->canChangeDisplayName() ||
786
-			(
787
-				!$this->groupManager->isAdmin($currentUser->getUID()) &&
788
-				!$this->groupManager->getSubAdmin()->isUserAccessible($currentUser, $user) &&
789
-				$currentUser->getUID() !== $username
790
-
791
-			)
792
-		) {
793
-			return new DataResponse([
794
-				'status' => 'error',
795
-				'data' => [
796
-					'message' => $this->l10n->t('Authentication error'),
797
-				],
798
-			]);
799
-		}
800
-
801
-		$userData = $this->accountManager->getUser($user);
802
-		$userData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $displayName;
803
-
804
-
805
-		try {
806
-			$this->saveUserSettings($user, $userData);
807
-			return new DataResponse([
808
-				'status' => 'success',
809
-				'data' => [
810
-					'message' => $this->l10n->t('Your full name has been changed.'),
811
-					'username' => $username,
812
-					'displayName' => $displayName,
813
-				],
814
-			]);
815
-		} catch (ForbiddenException $e) {
816
-			return new DataResponse([
817
-				'status' => 'error',
818
-				'data' => [
819
-					'message' => $e->getMessage(),
820
-					'displayName' => $user->getDisplayName(),
821
-				],
822
-			]);
823
-		}
824
-	}
825
-
826
-	/**
827
-	 * Set the mail address of a user
828
-	 *
829
-	 * @NoAdminRequired
830
-	 * @NoSubadminRequired
831
-	 * @PasswordConfirmationRequired
832
-	 *
833
-	 * @param string $id
834
-	 * @param string $mailAddress
835
-	 * @return DataResponse
836
-	 */
837
-	public function setEMailAddress($id, $mailAddress) {
838
-		$user = $this->userManager->get($id);
839
-		if (!$this->isAdmin
840
-			&& !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)
841
-		) {
842
-			return new DataResponse(
843
-				array(
844
-					'status' => 'error',
845
-					'data' => array(
846
-						'message' => (string)$this->l10n->t('Forbidden')
847
-					)
848
-				),
849
-				Http::STATUS_FORBIDDEN
850
-			);
851
-		}
852
-
853
-		if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) {
854
-			return new DataResponse(
855
-				array(
856
-					'status' => 'error',
857
-					'data' => array(
858
-						'message' => (string)$this->l10n->t('Invalid mail address')
859
-					)
860
-				),
861
-				Http::STATUS_UNPROCESSABLE_ENTITY
862
-			);
863
-		}
864
-
865
-		if (!$user) {
866
-			return new DataResponse(
867
-				array(
868
-					'status' => 'error',
869
-					'data' => array(
870
-						'message' => (string)$this->l10n->t('Invalid user')
871
-					)
872
-				),
873
-				Http::STATUS_UNPROCESSABLE_ENTITY
874
-			);
875
-		}
876
-		// this is the only permission a backend provides and is also used
877
-		// for the permission of setting a email address
878
-		if (!$user->canChangeDisplayName()) {
879
-			return new DataResponse(
880
-				array(
881
-					'status' => 'error',
882
-					'data' => array(
883
-						'message' => (string)$this->l10n->t('Unable to change mail address')
884
-					)
885
-				),
886
-				Http::STATUS_FORBIDDEN
887
-			);
888
-		}
889
-
890
-		$userData = $this->accountManager->getUser($user);
891
-		$userData[AccountManager::PROPERTY_EMAIL]['value'] = $mailAddress;
892
-
893
-		try {
894
-			$this->saveUserSettings($user, $userData);
895
-			return new DataResponse(
896
-				array(
897
-					'status' => 'success',
898
-					'data' => array(
899
-						'username' => $id,
900
-						'mailAddress' => $mailAddress,
901
-						'message' => (string)$this->l10n->t('Email saved')
902
-					)
903
-				),
904
-				Http::STATUS_OK
905
-			);
906
-		} catch (ForbiddenException $e) {
907
-			return new DataResponse([
908
-				'status' => 'error',
909
-				'data' => [
910
-					'message' => $e->getMessage()
911
-				],
912
-			]);
913
-		}
914
-	}
60
+    /** @var IL10N */
61
+    private $l10n;
62
+    /** @var IUserSession */
63
+    private $userSession;
64
+    /** @var bool */
65
+    private $isAdmin;
66
+    /** @var IUserManager */
67
+    private $userManager;
68
+    /** @var IGroupManager */
69
+    private $groupManager;
70
+    /** @var IConfig */
71
+    private $config;
72
+    /** @var ILogger */
73
+    private $log;
74
+    /** @var \OC_Defaults */
75
+    private $defaults;
76
+    /** @var IMailer */
77
+    private $mailer;
78
+    /** @var string */
79
+    private $fromMailAddress;
80
+    /** @var IURLGenerator */
81
+    private $urlGenerator;
82
+    /** @var bool contains the state of the encryption app */
83
+    private $isEncryptionAppEnabled;
84
+    /** @var bool contains the state of the admin recovery setting */
85
+    private $isRestoreEnabled = false;
86
+    /** @var IAvatarManager */
87
+    private $avatarManager;
88
+    /** @var AccountManager */
89
+    private $accountManager;
90
+    /** @var ISecureRandom */
91
+    private $secureRandom;
92
+    /** @var ITimeFactory */
93
+    private $timeFactory;
94
+    /** @var ICrypto */
95
+    private $crypto;
96
+    /** @var Manager */
97
+    private $keyManager;
98
+
99
+
100
+    /**
101
+     * @param string $appName
102
+     * @param IRequest $request
103
+     * @param IUserManager $userManager
104
+     * @param IGroupManager $groupManager
105
+     * @param IUserSession $userSession
106
+     * @param IConfig $config
107
+     * @param bool $isAdmin
108
+     * @param IL10N $l10n
109
+     * @param ILogger $log
110
+     * @param \OC_Defaults $defaults
111
+     * @param IMailer $mailer
112
+     * @param string $fromMailAddress
113
+     * @param IURLGenerator $urlGenerator
114
+     * @param IAppManager $appManager
115
+     * @param IAvatarManager $avatarManager
116
+     * @param AccountManager $accountManager
117
+     * @param ISecureRandom $secureRandom
118
+     * @param ITimeFactory $timeFactory
119
+     * @param ICrypto $crypto
120
+     * @param Manager $keyManager
121
+     */
122
+    public function __construct($appName,
123
+                                IRequest $request,
124
+                                IUserManager $userManager,
125
+                                IGroupManager $groupManager,
126
+                                IUserSession $userSession,
127
+                                IConfig $config,
128
+                                $isAdmin,
129
+                                IL10N $l10n,
130
+                                ILogger $log,
131
+                                \OC_Defaults $defaults,
132
+                                IMailer $mailer,
133
+                                $fromMailAddress,
134
+                                IURLGenerator $urlGenerator,
135
+                                IAppManager $appManager,
136
+                                IAvatarManager $avatarManager,
137
+                                AccountManager $accountManager,
138
+                                ISecureRandom $secureRandom,
139
+                                ITimeFactory $timeFactory,
140
+                                ICrypto $crypto,
141
+                                Manager $keyManager) {
142
+        parent::__construct($appName, $request);
143
+        $this->userManager = $userManager;
144
+        $this->groupManager = $groupManager;
145
+        $this->userSession = $userSession;
146
+        $this->config = $config;
147
+        $this->isAdmin = $isAdmin;
148
+        $this->l10n = $l10n;
149
+        $this->log = $log;
150
+        $this->defaults = $defaults;
151
+        $this->mailer = $mailer;
152
+        $this->fromMailAddress = $fromMailAddress;
153
+        $this->urlGenerator = $urlGenerator;
154
+        $this->avatarManager = $avatarManager;
155
+        $this->accountManager = $accountManager;
156
+        $this->secureRandom = $secureRandom;
157
+        $this->timeFactory = $timeFactory;
158
+        $this->crypto = $crypto;
159
+        $this->keyManager = $keyManager;
160
+
161
+        // check for encryption state - TODO see formatUserForIndex
162
+        $this->isEncryptionAppEnabled = $appManager->isEnabledForUser('encryption');
163
+        if($this->isEncryptionAppEnabled) {
164
+            // putting this directly in empty is possible in PHP 5.5+
165
+            $result = $config->getAppValue('encryption', 'recoveryAdminEnabled', 0);
166
+            $this->isRestoreEnabled = !empty($result);
167
+        }
168
+    }
169
+
170
+    /**
171
+     * @param IUser $user
172
+     * @param array $userGroups
173
+     * @return array
174
+     */
175
+    private function formatUserForIndex(IUser $user, array $userGroups = null) {
176
+
177
+        // TODO: eliminate this encryption specific code below and somehow
178
+        // hook in additional user info from other apps
179
+
180
+        // recovery isn't possible if admin or user has it disabled and encryption
181
+        // is enabled - so we eliminate the else paths in the conditional tree
182
+        // below
183
+        $restorePossible = false;
184
+
185
+        if ($this->isEncryptionAppEnabled) {
186
+            if ($this->isRestoreEnabled) {
187
+                // check for the users recovery setting
188
+                $recoveryMode = $this->config->getUserValue($user->getUID(), 'encryption', 'recoveryEnabled', '0');
189
+                // method call inside empty is possible with PHP 5.5+
190
+                $recoveryModeEnabled = !empty($recoveryMode);
191
+                if ($recoveryModeEnabled) {
192
+                    // user also has recovery mode enabled
193
+                    $restorePossible = true;
194
+                }
195
+            }
196
+        } else {
197
+            // recovery is possible if encryption is disabled (plain files are
198
+            // available)
199
+            $restorePossible = true;
200
+        }
201
+
202
+        $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
203
+        foreach($subAdminGroups as $key => $subAdminGroup) {
204
+            $subAdminGroups[$key] = $subAdminGroup->getGID();
205
+        }
206
+
207
+        $displayName = $user->getEMailAddress();
208
+        if (is_null($displayName)) {
209
+            $displayName = '';
210
+        }
211
+
212
+        $avatarAvailable = false;
213
+        try {
214
+            $avatarAvailable = $this->avatarManager->getAvatar($user->getUID())->exists();
215
+        } catch (\Exception $e) {
216
+            //No avatar yet
217
+        }
218
+
219
+        return [
220
+            'name' => $user->getUID(),
221
+            'displayname' => $user->getDisplayName(),
222
+            'groups' => (empty($userGroups)) ? $this->groupManager->getUserGroupIds($user) : $userGroups,
223
+            'subadmin' => $subAdminGroups,
224
+            'quota' => $user->getQuota(),
225
+            'storageLocation' => $user->getHome(),
226
+            'lastLogin' => $user->getLastLogin() * 1000,
227
+            'backend' => $user->getBackendClassName(),
228
+            'email' => $displayName,
229
+            'isRestoreDisabled' => !$restorePossible,
230
+            'isAvatarAvailable' => $avatarAvailable,
231
+        ];
232
+    }
233
+
234
+    /**
235
+     * @param array $userIDs Array with schema [$uid => $displayName]
236
+     * @return IUser[]
237
+     */
238
+    private function getUsersForUID(array $userIDs) {
239
+        $users = [];
240
+        foreach ($userIDs as $uid => $displayName) {
241
+            $users[$uid] = $this->userManager->get($uid);
242
+        }
243
+        return $users;
244
+    }
245
+
246
+    /**
247
+     * @NoAdminRequired
248
+     *
249
+     * @param int $offset
250
+     * @param int $limit
251
+     * @param string $gid GID to filter for
252
+     * @param string $pattern Pattern to search for in the username
253
+     * @param string $backend Backend to filter for (class-name)
254
+     * @return DataResponse
255
+     *
256
+     * TODO: Tidy up and write unit tests - code is mainly static method calls
257
+     */
258
+    public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '') {
259
+        // FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group.
260
+        if($gid === '_everyone') {
261
+            $gid = '';
262
+        }
263
+
264
+        // Remove backends
265
+        if(!empty($backend)) {
266
+            $activeBackends = $this->userManager->getBackends();
267
+            $this->userManager->clearBackends();
268
+            foreach($activeBackends as $singleActiveBackend) {
269
+                if($backend === get_class($singleActiveBackend)) {
270
+                    $this->userManager->registerBackend($singleActiveBackend);
271
+                    break;
272
+                }
273
+            }
274
+        }
275
+
276
+        $users = [];
277
+        if ($this->isAdmin) {
278
+
279
+            if($gid !== '') {
280
+                $batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset));
281
+            } else {
282
+                $batch = $this->userManager->search($pattern, $limit, $offset);
283
+            }
284
+
285
+            foreach ($batch as $user) {
286
+                $users[] = $this->formatUserForIndex($user);
287
+            }
288
+
289
+        } else {
290
+            $subAdminOfGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser());
291
+            // New class returns IGroup[] so convert back
292
+            $gids = [];
293
+            foreach ($subAdminOfGroups as $group) {
294
+                $gids[] = $group->getGID();
295
+            }
296
+            $subAdminOfGroups = $gids;
297
+
298
+            // Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group
299
+            if($gid !== '' && !in_array($gid, $subAdminOfGroups)) {
300
+                $gid = '';
301
+            }
302
+
303
+            // Batch all groups the user is subadmin of when a group is specified
304
+            $batch = [];
305
+            if($gid === '') {
306
+                foreach($subAdminOfGroups as $group) {
307
+                    $groupUsers = $this->groupManager->displayNamesInGroup($group, $pattern, $limit, $offset);
308
+
309
+                    foreach($groupUsers as $uid => $displayName) {
310
+                        $batch[$uid] = $displayName;
311
+                    }
312
+                }
313
+            } else {
314
+                $batch = $this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset);
315
+            }
316
+            $batch = $this->getUsersForUID($batch);
317
+
318
+            foreach ($batch as $user) {
319
+                // Only add the groups, this user is a subadmin of
320
+                $userGroups = array_values(array_intersect(
321
+                    $this->groupManager->getUserGroupIds($user),
322
+                    $subAdminOfGroups
323
+                ));
324
+                $users[] = $this->formatUserForIndex($user, $userGroups);
325
+            }
326
+        }
327
+
328
+        return new DataResponse($users);
329
+    }
330
+
331
+    /**
332
+     * @NoAdminRequired
333
+     * @PasswordConfirmationRequired
334
+     *
335
+     * @param string $username
336
+     * @param string $password
337
+     * @param array $groups
338
+     * @param string $email
339
+     * @return DataResponse
340
+     */
341
+    public function create($username, $password, array $groups=array(), $email='') {
342
+        if($email !== '' && !$this->mailer->validateMailAddress($email)) {
343
+            return new DataResponse(
344
+                array(
345
+                    'message' => (string)$this->l10n->t('Invalid mail address')
346
+                ),
347
+                Http::STATUS_UNPROCESSABLE_ENTITY
348
+            );
349
+        }
350
+
351
+        $currentUser = $this->userSession->getUser();
352
+
353
+        if (!$this->isAdmin) {
354
+            if (!empty($groups)) {
355
+                foreach ($groups as $key => $group) {
356
+                    $groupObject = $this->groupManager->get($group);
357
+                    if($groupObject === null) {
358
+                        unset($groups[$key]);
359
+                        continue;
360
+                    }
361
+
362
+                    if (!$this->groupManager->getSubAdmin()->isSubAdminofGroup($currentUser, $groupObject)) {
363
+                        unset($groups[$key]);
364
+                    }
365
+                }
366
+            }
367
+
368
+            if (empty($groups)) {
369
+                return new DataResponse(
370
+                    array(
371
+                        'message' => $this->l10n->t('No valid group selected'),
372
+                    ),
373
+                    Http::STATUS_FORBIDDEN
374
+                );
375
+            }
376
+        }
377
+
378
+        if ($this->userManager->userExists($username)) {
379
+            return new DataResponse(
380
+                array(
381
+                    'message' => (string)$this->l10n->t('A user with that name already exists.')
382
+                ),
383
+                Http::STATUS_CONFLICT
384
+            );
385
+        }
386
+
387
+        $generatedPassword = false;
388
+        if ($password === '') {
389
+            if ($email === '') {
390
+                return new DataResponse(
391
+                    array(
392
+                        'message' => (string)$this->l10n->t('To send a password link to the user an email address is required.')
393
+                    ),
394
+                    Http::STATUS_UNPROCESSABLE_ENTITY
395
+                );
396
+            }
397
+
398
+            $password = $this->secureRandom->generate(32);
399
+            $generatedPassword = true;
400
+        }
401
+
402
+        try {
403
+            $user = $this->userManager->createUser($username, $password);
404
+        } catch (\Exception $exception) {
405
+            $message = $exception->getMessage();
406
+            if (!$message) {
407
+                $message = $this->l10n->t('Unable to create user.');
408
+            }
409
+            return new DataResponse(
410
+                array(
411
+                    'message' => (string) $message,
412
+                ),
413
+                Http::STATUS_FORBIDDEN
414
+            );
415
+        }
416
+
417
+        if($user instanceof IUser) {
418
+            if($groups !== null) {
419
+                foreach($groups as $groupName) {
420
+                    $group = $this->groupManager->get($groupName);
421
+
422
+                    if(empty($group)) {
423
+                        $group = $this->groupManager->createGroup($groupName);
424
+                    }
425
+                    $group->addUser($user);
426
+                }
427
+            }
428
+            /**
429
+             * Send new user mail only if a mail is set
430
+             */
431
+            if($email !== '') {
432
+                $user->setEMailAddress($email);
433
+
434
+                if ($generatedPassword) {
435
+                    $token = $this->secureRandom->generate(
436
+                        21,
437
+                        ISecureRandom::CHAR_DIGITS .
438
+                        ISecureRandom::CHAR_LOWER .
439
+                        ISecureRandom::CHAR_UPPER
440
+                    );
441
+                    $tokenValue = $this->timeFactory->getTime() . ':' . $token;
442
+                    $mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : '';
443
+                    $encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress . $this->config->getSystemValue('secret'));
444
+                    $this->config->setUserValue($username, 'core', 'lostpassword', $encryptedValue);
445
+
446
+                    $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $username, 'token' => $token]);
447
+                } else {
448
+                    $link = $this->urlGenerator->getAbsoluteURL('/');
449
+                }
450
+
451
+                // data for the mail template
452
+                $mailData = array(
453
+                    'username' => $username,
454
+                    'url' => $link
455
+                );
456
+
457
+                $mail = new TemplateResponse('settings', 'email.new_user', $mailData, 'blank');
458
+                $mailContent = $mail->render();
459
+
460
+                $mail = new TemplateResponse('settings', 'email.new_user_plain_text', $mailData, 'blank');
461
+                $plainTextMailContent = $mail->render();
462
+
463
+                $subject = $this->l10n->t('Your %s account was created', [$this->defaults->getName()]);
464
+
465
+                try {
466
+                    $message = $this->mailer->createMessage();
467
+                    $message->setTo([$email => $username]);
468
+                    $message->setSubject($subject);
469
+                    $message->setHtmlBody($mailContent);
470
+                    $message->setPlainBody($plainTextMailContent);
471
+                    $message->setFrom([$this->fromMailAddress => $this->defaults->getName()]);
472
+                    $this->mailer->send($message);
473
+                } catch(\Exception $e) {
474
+                    $this->log->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings'));
475
+                }
476
+            }
477
+            // fetch users groups
478
+            $userGroups = $this->groupManager->getUserGroupIds($user);
479
+
480
+            return new DataResponse(
481
+                $this->formatUserForIndex($user, $userGroups),
482
+                Http::STATUS_CREATED
483
+            );
484
+        }
485
+
486
+        return new DataResponse(
487
+            array(
488
+                'message' => (string)$this->l10n->t('Unable to create user.')
489
+            ),
490
+            Http::STATUS_FORBIDDEN
491
+        );
492
+
493
+    }
494
+
495
+    /**
496
+     * @NoAdminRequired
497
+     * @PasswordConfirmationRequired
498
+     *
499
+     * @param string $id
500
+     * @return DataResponse
501
+     */
502
+    public function destroy($id) {
503
+        $userId = $this->userSession->getUser()->getUID();
504
+        $user = $this->userManager->get($id);
505
+
506
+        if($userId === $id) {
507
+            return new DataResponse(
508
+                array(
509
+                    'status' => 'error',
510
+                    'data' => array(
511
+                        'message' => (string)$this->l10n->t('Unable to delete user.')
512
+                    )
513
+                ),
514
+                Http::STATUS_FORBIDDEN
515
+            );
516
+        }
517
+
518
+        if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) {
519
+            return new DataResponse(
520
+                array(
521
+                    'status' => 'error',
522
+                    'data' => array(
523
+                        'message' => (string)$this->l10n->t('Authentication error')
524
+                    )
525
+                ),
526
+                Http::STATUS_FORBIDDEN
527
+            );
528
+        }
529
+
530
+        if($user) {
531
+            if($user->delete()) {
532
+                return new DataResponse(
533
+                    array(
534
+                        'status' => 'success',
535
+                        'data' => array(
536
+                            'username' => $id
537
+                        )
538
+                    ),
539
+                    Http::STATUS_NO_CONTENT
540
+                );
541
+            }
542
+        }
543
+
544
+        return new DataResponse(
545
+            array(
546
+                'status' => 'error',
547
+                'data' => array(
548
+                    'message' => (string)$this->l10n->t('Unable to delete user.')
549
+                )
550
+            ),
551
+            Http::STATUS_FORBIDDEN
552
+        );
553
+    }
554
+
555
+    /**
556
+     * @NoAdminRequired
557
+     * @NoSubadminRequired
558
+     * @PasswordConfirmationRequired
559
+     *
560
+     * @param string $account
561
+     * @return DataResponse
562
+     */
563
+    public function getVerificationCode($account) {
564
+
565
+        $user = $this->userSession->getUser();
566
+
567
+        if ($user === null) {
568
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
569
+        }
570
+
571
+        $accountData = $this->accountManager->getUser($user);
572
+        $cloudId = $user->getCloudId();
573
+        $message = "Use my Federated Cloud ID to share with me: " . $cloudId;
574
+        $privateKey = $this->keyManager->getKey($user)->getPrivate();
575
+        openssl_sign(json_encode($message), $signature, $privateKey, OPENSSL_ALGO_SHA512);
576
+        $signatureBase64 = base64_encode($signature);
577
+
578
+        $code = $message . ' ' . $signatureBase64;
579
+        $codeMd5 = $message . ' ' . md5($signatureBase64);
580
+
581
+        switch ($account) {
582
+            case 'verify-twitter':
583
+                $accountData[AccountManager::PROPERTY_TWITTER]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
584
+                $msg = $this->l10n->t('In order to verify your Twitter account post following tweet on Twitter:');
585
+                $code = $codeMd5;
586
+                break;
587
+            case 'verify-website':
588
+                $accountData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
589
+                $msg = $this->l10n->t('In order to verify your Website store following content in your webroot at \'CloudIdVerificationCode.txt\':');
590
+                break;
591
+            default:
592
+                return new DataResponse([], Http::STATUS_BAD_REQUEST);
593
+        }
594
+
595
+        $this->accountManager->updateUser($user, $accountData);
596
+
597
+        return new DataResponse(['msg' => $msg, 'code' => $code]);
598
+    }
599
+
600
+    /**
601
+     * @NoAdminRequired
602
+     * @NoSubadminRequired
603
+     * @PasswordConfirmationRequired
604
+     *
605
+     * @param string $avatarScope
606
+     * @param string $displayname
607
+     * @param string $displaynameScope
608
+     * @param string $phone
609
+     * @param string $phoneScope
610
+     * @param string $email
611
+     * @param string $emailScope
612
+     * @param string $website
613
+     * @param string $websiteScope
614
+     * @param string $address
615
+     * @param string $addressScope
616
+     * @param string $twitter
617
+     * @param string $twitterScope
618
+     * @return DataResponse
619
+     */
620
+    public function setUserSettings($avatarScope,
621
+                                    $displayname,
622
+                                    $displaynameScope,
623
+                                    $phone,
624
+                                    $phoneScope,
625
+                                    $email,
626
+                                    $emailScope,
627
+                                    $website,
628
+                                    $websiteScope,
629
+                                    $address,
630
+                                    $addressScope,
631
+                                    $twitter,
632
+                                    $twitterScope
633
+    ) {
634
+
635
+        if(!empty($email) && !$this->mailer->validateMailAddress($email)) {
636
+            return new DataResponse(
637
+                array(
638
+                    'status' => 'error',
639
+                    'data' => array(
640
+                        'message' => (string)$this->l10n->t('Invalid mail address')
641
+                    )
642
+                ),
643
+                Http::STATUS_UNPROCESSABLE_ENTITY
644
+            );
645
+        }
646
+
647
+        $data = [
648
+            AccountManager::PROPERTY_AVATAR =>  ['scope' => $avatarScope],
649
+            AccountManager::PROPERTY_DISPLAYNAME => ['value' => $displayname, 'scope' => $displaynameScope],
650
+            AccountManager::PROPERTY_EMAIL=> ['value' => $email, 'scope' => $emailScope],
651
+            AccountManager::PROPERTY_WEBSITE => ['value' => $website, 'scope' => $websiteScope],
652
+            AccountManager::PROPERTY_ADDRESS => ['value' => $address, 'scope' => $addressScope],
653
+            AccountManager::PROPERTY_PHONE => ['value' => $phone, 'scope' => $phoneScope],
654
+            AccountManager::PROPERTY_TWITTER => ['value' => $twitter, 'scope' => $twitterScope]
655
+        ];
656
+
657
+        $user = $this->userSession->getUser();
658
+
659
+        try {
660
+            $this->saveUserSettings($user, $data);
661
+            return new DataResponse(
662
+                array(
663
+                    'status' => 'success',
664
+                    'data' => array(
665
+                        'userId' => $user->getUID(),
666
+                        'avatarScope' => $avatarScope,
667
+                        'displayname' => $displayname,
668
+                        'displaynameScope' => $displaynameScope,
669
+                        'email' => $email,
670
+                        'emailScope' => $emailScope,
671
+                        'website' => $website,
672
+                        'websiteScope' => $websiteScope,
673
+                        'address' => $address,
674
+                        'addressScope' => $addressScope,
675
+                        'message' => (string)$this->l10n->t('Settings saved')
676
+                    )
677
+                ),
678
+                Http::STATUS_OK
679
+            );
680
+        } catch (ForbiddenException $e) {
681
+            return new DataResponse([
682
+                'status' => 'error',
683
+                'data' => [
684
+                    'message' => $e->getMessage()
685
+                ],
686
+            ]);
687
+        }
688
+
689
+    }
690
+
691
+
692
+    /**
693
+     * update account manager with new user data
694
+     *
695
+     * @param IUser $user
696
+     * @param array $data
697
+     * @throws ForbiddenException
698
+     */
699
+    protected function saveUserSettings(IUser $user, $data) {
700
+
701
+        // keep the user back-end up-to-date with the latest display name and email
702
+        // address
703
+        $oldDisplayName = $user->getDisplayName();
704
+        $oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName;
705
+        if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value'])
706
+            && $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value']
707
+        ) {
708
+            $result = $user->setDisplayName($data[AccountManager::PROPERTY_DISPLAYNAME]['value']);
709
+            if ($result === false) {
710
+                throw new ForbiddenException($this->l10n->t('Unable to change full name'));
711
+            }
712
+        }
713
+
714
+        $oldEmailAddress = $user->getEMailAddress();
715
+        $oldEmailAddress = is_null($oldEmailAddress) ? '' : $oldEmailAddress;
716
+        if (isset($data[AccountManager::PROPERTY_EMAIL]['value'])
717
+            && $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value']
718
+        ) {
719
+            // this is the only permission a backend provides and is also used
720
+            // for the permission of setting a email address
721
+            if (!$user->canChangeDisplayName()) {
722
+                throw new ForbiddenException($this->l10n->t('Unable to change email address'));
723
+            }
724
+            $user->setEMailAddress($data[AccountManager::PROPERTY_EMAIL]['value']);
725
+        }
726
+
727
+        $this->accountManager->updateUser($user, $data);
728
+    }
729
+
730
+    /**
731
+     * Count all unique users visible for the current admin/subadmin.
732
+     *
733
+     * @NoAdminRequired
734
+     *
735
+     * @return DataResponse
736
+     */
737
+    public function stats() {
738
+        $userCount = 0;
739
+        if ($this->isAdmin) {
740
+            $countByBackend = $this->userManager->countUsers();
741
+
742
+            if (!empty($countByBackend)) {
743
+                foreach ($countByBackend as $count) {
744
+                    $userCount += $count;
745
+                }
746
+            }
747
+        } else {
748
+            $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser());
749
+
750
+            $uniqueUsers = [];
751
+            foreach ($groups as $group) {
752
+                foreach($group->getUsers() as $uid => $displayName) {
753
+                    $uniqueUsers[$uid] = true;
754
+                }
755
+            }
756
+
757
+            $userCount = count($uniqueUsers);
758
+        }
759
+
760
+        return new DataResponse(
761
+            [
762
+                'totalUsers' => $userCount
763
+            ]
764
+        );
765
+    }
766
+
767
+
768
+    /**
769
+     * Set the displayName of a user
770
+     *
771
+     * @NoAdminRequired
772
+     * @NoSubadminRequired
773
+     * @PasswordConfirmationRequired
774
+     * @todo merge into saveUserSettings
775
+     *
776
+     * @param string $username
777
+     * @param string $displayName
778
+     * @return DataResponse
779
+     */
780
+    public function setDisplayName($username, $displayName) {
781
+        $currentUser = $this->userSession->getUser();
782
+        $user = $this->userManager->get($username);
783
+
784
+        if ($user === null ||
785
+            !$user->canChangeDisplayName() ||
786
+            (
787
+                !$this->groupManager->isAdmin($currentUser->getUID()) &&
788
+                !$this->groupManager->getSubAdmin()->isUserAccessible($currentUser, $user) &&
789
+                $currentUser->getUID() !== $username
790
+
791
+            )
792
+        ) {
793
+            return new DataResponse([
794
+                'status' => 'error',
795
+                'data' => [
796
+                    'message' => $this->l10n->t('Authentication error'),
797
+                ],
798
+            ]);
799
+        }
800
+
801
+        $userData = $this->accountManager->getUser($user);
802
+        $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $displayName;
803
+
804
+
805
+        try {
806
+            $this->saveUserSettings($user, $userData);
807
+            return new DataResponse([
808
+                'status' => 'success',
809
+                'data' => [
810
+                    'message' => $this->l10n->t('Your full name has been changed.'),
811
+                    'username' => $username,
812
+                    'displayName' => $displayName,
813
+                ],
814
+            ]);
815
+        } catch (ForbiddenException $e) {
816
+            return new DataResponse([
817
+                'status' => 'error',
818
+                'data' => [
819
+                    'message' => $e->getMessage(),
820
+                    'displayName' => $user->getDisplayName(),
821
+                ],
822
+            ]);
823
+        }
824
+    }
825
+
826
+    /**
827
+     * Set the mail address of a user
828
+     *
829
+     * @NoAdminRequired
830
+     * @NoSubadminRequired
831
+     * @PasswordConfirmationRequired
832
+     *
833
+     * @param string $id
834
+     * @param string $mailAddress
835
+     * @return DataResponse
836
+     */
837
+    public function setEMailAddress($id, $mailAddress) {
838
+        $user = $this->userManager->get($id);
839
+        if (!$this->isAdmin
840
+            && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)
841
+        ) {
842
+            return new DataResponse(
843
+                array(
844
+                    'status' => 'error',
845
+                    'data' => array(
846
+                        'message' => (string)$this->l10n->t('Forbidden')
847
+                    )
848
+                ),
849
+                Http::STATUS_FORBIDDEN
850
+            );
851
+        }
852
+
853
+        if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) {
854
+            return new DataResponse(
855
+                array(
856
+                    'status' => 'error',
857
+                    'data' => array(
858
+                        'message' => (string)$this->l10n->t('Invalid mail address')
859
+                    )
860
+                ),
861
+                Http::STATUS_UNPROCESSABLE_ENTITY
862
+            );
863
+        }
864
+
865
+        if (!$user) {
866
+            return new DataResponse(
867
+                array(
868
+                    'status' => 'error',
869
+                    'data' => array(
870
+                        'message' => (string)$this->l10n->t('Invalid user')
871
+                    )
872
+                ),
873
+                Http::STATUS_UNPROCESSABLE_ENTITY
874
+            );
875
+        }
876
+        // this is the only permission a backend provides and is also used
877
+        // for the permission of setting a email address
878
+        if (!$user->canChangeDisplayName()) {
879
+            return new DataResponse(
880
+                array(
881
+                    'status' => 'error',
882
+                    'data' => array(
883
+                        'message' => (string)$this->l10n->t('Unable to change mail address')
884
+                    )
885
+                ),
886
+                Http::STATUS_FORBIDDEN
887
+            );
888
+        }
889
+
890
+        $userData = $this->accountManager->getUser($user);
891
+        $userData[AccountManager::PROPERTY_EMAIL]['value'] = $mailAddress;
892
+
893
+        try {
894
+            $this->saveUserSettings($user, $userData);
895
+            return new DataResponse(
896
+                array(
897
+                    'status' => 'success',
898
+                    'data' => array(
899
+                        'username' => $id,
900
+                        'mailAddress' => $mailAddress,
901
+                        'message' => (string)$this->l10n->t('Email saved')
902
+                    )
903
+                ),
904
+                Http::STATUS_OK
905
+            );
906
+        } catch (ForbiddenException $e) {
907
+            return new DataResponse([
908
+                'status' => 'error',
909
+                'data' => [
910
+                    'message' => $e->getMessage()
911
+                ],
912
+            ]);
913
+        }
914
+    }
915 915
 
916 916
 }
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 
161 161
 		// check for encryption state - TODO see formatUserForIndex
162 162
 		$this->isEncryptionAppEnabled = $appManager->isEnabledForUser('encryption');
163
-		if($this->isEncryptionAppEnabled) {
163
+		if ($this->isEncryptionAppEnabled) {
164 164
 			// putting this directly in empty is possible in PHP 5.5+
165 165
 			$result = $config->getAppValue('encryption', 'recoveryAdminEnabled', 0);
166 166
 			$this->isRestoreEnabled = !empty($result);
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 		}
201 201
 
202 202
 		$subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
203
-		foreach($subAdminGroups as $key => $subAdminGroup) {
203
+		foreach ($subAdminGroups as $key => $subAdminGroup) {
204 204
 			$subAdminGroups[$key] = $subAdminGroup->getGID();
205 205
 		}
206 206
 
@@ -257,16 +257,16 @@  discard block
 block discarded – undo
257 257
 	 */
258 258
 	public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '') {
259 259
 		// FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group.
260
-		if($gid === '_everyone') {
260
+		if ($gid === '_everyone') {
261 261
 			$gid = '';
262 262
 		}
263 263
 
264 264
 		// Remove backends
265
-		if(!empty($backend)) {
265
+		if (!empty($backend)) {
266 266
 			$activeBackends = $this->userManager->getBackends();
267 267
 			$this->userManager->clearBackends();
268
-			foreach($activeBackends as $singleActiveBackend) {
269
-				if($backend === get_class($singleActiveBackend)) {
268
+			foreach ($activeBackends as $singleActiveBackend) {
269
+				if ($backend === get_class($singleActiveBackend)) {
270 270
 					$this->userManager->registerBackend($singleActiveBackend);
271 271
 					break;
272 272
 				}
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 		$users = [];
277 277
 		if ($this->isAdmin) {
278 278
 
279
-			if($gid !== '') {
279
+			if ($gid !== '') {
280 280
 				$batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset));
281 281
 			} else {
282 282
 				$batch = $this->userManager->search($pattern, $limit, $offset);
@@ -296,17 +296,17 @@  discard block
 block discarded – undo
296 296
 			$subAdminOfGroups = $gids;
297 297
 
298 298
 			// Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group
299
-			if($gid !== '' && !in_array($gid, $subAdminOfGroups)) {
299
+			if ($gid !== '' && !in_array($gid, $subAdminOfGroups)) {
300 300
 				$gid = '';
301 301
 			}
302 302
 
303 303
 			// Batch all groups the user is subadmin of when a group is specified
304 304
 			$batch = [];
305
-			if($gid === '') {
306
-				foreach($subAdminOfGroups as $group) {
305
+			if ($gid === '') {
306
+				foreach ($subAdminOfGroups as $group) {
307 307
 					$groupUsers = $this->groupManager->displayNamesInGroup($group, $pattern, $limit, $offset);
308 308
 
309
-					foreach($groupUsers as $uid => $displayName) {
309
+					foreach ($groupUsers as $uid => $displayName) {
310 310
 						$batch[$uid] = $displayName;
311 311
 					}
312 312
 				}
@@ -338,11 +338,11 @@  discard block
 block discarded – undo
338 338
 	 * @param string $email
339 339
 	 * @return DataResponse
340 340
 	 */
341
-	public function create($username, $password, array $groups=array(), $email='') {
342
-		if($email !== '' && !$this->mailer->validateMailAddress($email)) {
341
+	public function create($username, $password, array $groups = array(), $email = '') {
342
+		if ($email !== '' && !$this->mailer->validateMailAddress($email)) {
343 343
 			return new DataResponse(
344 344
 				array(
345
-					'message' => (string)$this->l10n->t('Invalid mail address')
345
+					'message' => (string) $this->l10n->t('Invalid mail address')
346 346
 				),
347 347
 				Http::STATUS_UNPROCESSABLE_ENTITY
348 348
 			);
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
 			if (!empty($groups)) {
355 355
 				foreach ($groups as $key => $group) {
356 356
 					$groupObject = $this->groupManager->get($group);
357
-					if($groupObject === null) {
357
+					if ($groupObject === null) {
358 358
 						unset($groups[$key]);
359 359
 						continue;
360 360
 					}
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 		if ($this->userManager->userExists($username)) {
379 379
 			return new DataResponse(
380 380
 				array(
381
-					'message' => (string)$this->l10n->t('A user with that name already exists.')
381
+					'message' => (string) $this->l10n->t('A user with that name already exists.')
382 382
 				),
383 383
 				Http::STATUS_CONFLICT
384 384
 			);
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 			if ($email === '') {
390 390
 				return new DataResponse(
391 391
 					array(
392
-						'message' => (string)$this->l10n->t('To send a password link to the user an email address is required.')
392
+						'message' => (string) $this->l10n->t('To send a password link to the user an email address is required.')
393 393
 					),
394 394
 					Http::STATUS_UNPROCESSABLE_ENTITY
395 395
 				);
@@ -414,12 +414,12 @@  discard block
 block discarded – undo
414 414
 			);
415 415
 		}
416 416
 
417
-		if($user instanceof IUser) {
418
-			if($groups !== null) {
419
-				foreach($groups as $groupName) {
417
+		if ($user instanceof IUser) {
418
+			if ($groups !== null) {
419
+				foreach ($groups as $groupName) {
420 420
 					$group = $this->groupManager->get($groupName);
421 421
 
422
-					if(empty($group)) {
422
+					if (empty($group)) {
423 423
 						$group = $this->groupManager->createGroup($groupName);
424 424
 					}
425 425
 					$group->addUser($user);
@@ -428,19 +428,19 @@  discard block
 block discarded – undo
428 428
 			/**
429 429
 			 * Send new user mail only if a mail is set
430 430
 			 */
431
-			if($email !== '') {
431
+			if ($email !== '') {
432 432
 				$user->setEMailAddress($email);
433 433
 
434 434
 				if ($generatedPassword) {
435 435
 					$token = $this->secureRandom->generate(
436 436
 						21,
437
-						ISecureRandom::CHAR_DIGITS .
438
-						ISecureRandom::CHAR_LOWER .
437
+						ISecureRandom::CHAR_DIGITS.
438
+						ISecureRandom::CHAR_LOWER.
439 439
 						ISecureRandom::CHAR_UPPER
440 440
 					);
441
-					$tokenValue = $this->timeFactory->getTime() . ':' . $token;
441
+					$tokenValue = $this->timeFactory->getTime().':'.$token;
442 442
 					$mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : '';
443
-					$encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress . $this->config->getSystemValue('secret'));
443
+					$encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress.$this->config->getSystemValue('secret'));
444 444
 					$this->config->setUserValue($username, 'core', 'lostpassword', $encryptedValue);
445 445
 
446 446
 					$link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $username, 'token' => $token]);
@@ -470,8 +470,8 @@  discard block
 block discarded – undo
470 470
 					$message->setPlainBody($plainTextMailContent);
471 471
 					$message->setFrom([$this->fromMailAddress => $this->defaults->getName()]);
472 472
 					$this->mailer->send($message);
473
-				} catch(\Exception $e) {
474
-					$this->log->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings'));
473
+				} catch (\Exception $e) {
474
+					$this->log->error("Can't send new user mail to $email: ".$e->getMessage(), array('app' => 'settings'));
475 475
 				}
476 476
 			}
477 477
 			// fetch users groups
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 
486 486
 		return new DataResponse(
487 487
 			array(
488
-				'message' => (string)$this->l10n->t('Unable to create user.')
488
+				'message' => (string) $this->l10n->t('Unable to create user.')
489 489
 			),
490 490
 			Http::STATUS_FORBIDDEN
491 491
 		);
@@ -503,32 +503,32 @@  discard block
 block discarded – undo
503 503
 		$userId = $this->userSession->getUser()->getUID();
504 504
 		$user = $this->userManager->get($id);
505 505
 
506
-		if($userId === $id) {
506
+		if ($userId === $id) {
507 507
 			return new DataResponse(
508 508
 				array(
509 509
 					'status' => 'error',
510 510
 					'data' => array(
511
-						'message' => (string)$this->l10n->t('Unable to delete user.')
511
+						'message' => (string) $this->l10n->t('Unable to delete user.')
512 512
 					)
513 513
 				),
514 514
 				Http::STATUS_FORBIDDEN
515 515
 			);
516 516
 		}
517 517
 
518
-		if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) {
518
+		if (!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) {
519 519
 			return new DataResponse(
520 520
 				array(
521 521
 					'status' => 'error',
522 522
 					'data' => array(
523
-						'message' => (string)$this->l10n->t('Authentication error')
523
+						'message' => (string) $this->l10n->t('Authentication error')
524 524
 					)
525 525
 				),
526 526
 				Http::STATUS_FORBIDDEN
527 527
 			);
528 528
 		}
529 529
 
530
-		if($user) {
531
-			if($user->delete()) {
530
+		if ($user) {
531
+			if ($user->delete()) {
532 532
 				return new DataResponse(
533 533
 					array(
534 534
 						'status' => 'success',
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 			array(
546 546
 				'status' => 'error',
547 547
 				'data' => array(
548
-					'message' => (string)$this->l10n->t('Unable to delete user.')
548
+					'message' => (string) $this->l10n->t('Unable to delete user.')
549 549
 				)
550 550
 			),
551 551
 			Http::STATUS_FORBIDDEN
@@ -570,13 +570,13 @@  discard block
 block discarded – undo
570 570
 
571 571
 		$accountData = $this->accountManager->getUser($user);
572 572
 		$cloudId = $user->getCloudId();
573
-		$message = "Use my Federated Cloud ID to share with me: " . $cloudId;
573
+		$message = "Use my Federated Cloud ID to share with me: ".$cloudId;
574 574
 		$privateKey = $this->keyManager->getKey($user)->getPrivate();
575 575
 		openssl_sign(json_encode($message), $signature, $privateKey, OPENSSL_ALGO_SHA512);
576 576
 		$signatureBase64 = base64_encode($signature);
577 577
 
578
-		$code = $message . ' ' . $signatureBase64;
579
-		$codeMd5 = $message . ' ' . md5($signatureBase64);
578
+		$code = $message.' '.$signatureBase64;
579
+		$codeMd5 = $message.' '.md5($signatureBase64);
580 580
 
581 581
 		switch ($account) {
582 582
 			case 'verify-twitter':
@@ -632,12 +632,12 @@  discard block
 block discarded – undo
632 632
 									$twitterScope
633 633
 	) {
634 634
 
635
-		if(!empty($email) && !$this->mailer->validateMailAddress($email)) {
635
+		if (!empty($email) && !$this->mailer->validateMailAddress($email)) {
636 636
 			return new DataResponse(
637 637
 				array(
638 638
 					'status' => 'error',
639 639
 					'data' => array(
640
-						'message' => (string)$this->l10n->t('Invalid mail address')
640
+						'message' => (string) $this->l10n->t('Invalid mail address')
641 641
 					)
642 642
 				),
643 643
 				Http::STATUS_UNPROCESSABLE_ENTITY
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
 						'websiteScope' => $websiteScope,
673 673
 						'address' => $address,
674 674
 						'addressScope' => $addressScope,
675
-						'message' => (string)$this->l10n->t('Settings saved')
675
+						'message' => (string) $this->l10n->t('Settings saved')
676 676
 					)
677 677
 				),
678 678
 				Http::STATUS_OK
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 
750 750
 			$uniqueUsers = [];
751 751
 			foreach ($groups as $group) {
752
-				foreach($group->getUsers() as $uid => $displayName) {
752
+				foreach ($group->getUsers() as $uid => $displayName) {
753 753
 					$uniqueUsers[$uid] = true;
754 754
 				}
755 755
 			}
@@ -843,19 +843,19 @@  discard block
 block discarded – undo
843 843
 				array(
844 844
 					'status' => 'error',
845 845
 					'data' => array(
846
-						'message' => (string)$this->l10n->t('Forbidden')
846
+						'message' => (string) $this->l10n->t('Forbidden')
847 847
 					)
848 848
 				),
849 849
 				Http::STATUS_FORBIDDEN
850 850
 			);
851 851
 		}
852 852
 
853
-		if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) {
853
+		if ($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) {
854 854
 			return new DataResponse(
855 855
 				array(
856 856
 					'status' => 'error',
857 857
 					'data' => array(
858
-						'message' => (string)$this->l10n->t('Invalid mail address')
858
+						'message' => (string) $this->l10n->t('Invalid mail address')
859 859
 					)
860 860
 				),
861 861
 				Http::STATUS_UNPROCESSABLE_ENTITY
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
 				array(
868 868
 					'status' => 'error',
869 869
 					'data' => array(
870
-						'message' => (string)$this->l10n->t('Invalid user')
870
+						'message' => (string) $this->l10n->t('Invalid user')
871 871
 					)
872 872
 				),
873 873
 				Http::STATUS_UNPROCESSABLE_ENTITY
@@ -880,7 +880,7 @@  discard block
 block discarded – undo
880 880
 				array(
881 881
 					'status' => 'error',
882 882
 					'data' => array(
883
-						'message' => (string)$this->l10n->t('Unable to change mail address')
883
+						'message' => (string) $this->l10n->t('Unable to change mail address')
884 884
 					)
885 885
 				),
886 886
 				Http::STATUS_FORBIDDEN
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
 					'data' => array(
899 899
 						'username' => $id,
900 900
 						'mailAddress' => $mailAddress,
901
-						'message' => (string)$this->l10n->t('Email saved')
901
+						'message' => (string) $this->l10n->t('Email saved')
902 902
 					)
903 903
 				),
904 904
 				Http::STATUS_OK
Please login to merge, or discard this patch.