Completed
Pull Request — master (#3869)
by Björn
253:56 queued 242:57
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.
settings/Controller/UsersController.php 2 patches
Indentation   +845 added lines, -845 removed lines patch added patch discarded remove patch
@@ -57,850 +57,850 @@
 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
-		$cloudId = $user->getCloudId();
567
-		$message = "My Federated Cloud ID: " . $cloudId;
568
-		$privateKey = $this->keyManager->getKey($user)->getPrivate();
569
-		openssl_sign(json_encode($message), $signature, $privateKey, OPENSSL_ALGO_SHA512);
570
-		$signatureBase64 = base64_encode($signature);
571
-
572
-		$code = $message . ' ' . $signatureBase64;
573
-
574
-		switch ($account) {
575
-			case 'verify-twitter':
576
-				$msg = $this->l10n->t('In order to verify your Twitter account post following tweet on Twitter:');
577
-				$code = substr($code, 0 , 140);
578
-				break;
579
-			case 'verify-website':
580
-				$msg = $this->l10n->t('In order to verify your Website store following content in your webroot at \'CloudIdVerificationCode.txt\':');
581
-				break;
582
-			default:
583
-				return new DataResponse([], Http::STATUS_BAD_REQUEST);
584
-				break;
585
-		}
586
-
587
-		return new DataResponse(['msg' => $msg, 'code' => $code]);
588
-	}
589
-
590
-	/**
591
-	 * @NoAdminRequired
592
-	 * @NoSubadminRequired
593
-	 * @PasswordConfirmationRequired
594
-	 *
595
-	 * @param string $avatarScope
596
-	 * @param string $displayname
597
-	 * @param string $displaynameScope
598
-	 * @param string $phone
599
-	 * @param string $phoneScope
600
-	 * @param string $email
601
-	 * @param string $emailScope
602
-	 * @param string $website
603
-	 * @param string $websiteScope
604
-	 * @param string $address
605
-	 * @param string $addressScope
606
-	 * @param string $twitter
607
-	 * @param string $twitterScope
608
-	 * @return DataResponse
609
-	 */
610
-	public function setUserSettings($avatarScope,
611
-									$displayname,
612
-									$displaynameScope,
613
-									$phone,
614
-									$phoneScope,
615
-									$email,
616
-									$emailScope,
617
-									$website,
618
-									$websiteScope,
619
-									$address,
620
-									$addressScope,
621
-									$twitter,
622
-									$twitterScope
623
-	) {
624
-
625
-		if(!empty($email) && !$this->mailer->validateMailAddress($email)) {
626
-			return new DataResponse(
627
-				array(
628
-					'status' => 'error',
629
-					'data' => array(
630
-						'message' => (string)$this->l10n->t('Invalid mail address')
631
-					)
632
-				),
633
-				Http::STATUS_UNPROCESSABLE_ENTITY
634
-			);
635
-		}
636
-
637
-		$data = [
638
-			AccountManager::PROPERTY_AVATAR =>  ['scope' => $avatarScope],
639
-			AccountManager::PROPERTY_DISPLAYNAME => ['value' => $displayname, 'scope' => $displaynameScope],
640
-			AccountManager::PROPERTY_EMAIL=> ['value' => $email, 'scope' => $emailScope],
641
-			AccountManager::PROPERTY_WEBSITE => ['value' => $website, 'scope' => $websiteScope],
642
-			AccountManager::PROPERTY_ADDRESS => ['value' => $address, 'scope' => $addressScope],
643
-			AccountManager::PROPERTY_PHONE => ['value' => $phone, 'scope' => $phoneScope],
644
-			AccountManager::PROPERTY_TWITTER => ['value' => $twitter, 'scope' => $twitterScope]
645
-		];
646
-
647
-		$user = $this->userSession->getUser();
648
-
649
-		try {
650
-			$this->saveUserSettings($user, $data);
651
-			return new DataResponse(
652
-				array(
653
-					'status' => 'success',
654
-					'data' => array(
655
-						'userId' => $user->getUID(),
656
-						'avatarScope' => $avatarScope,
657
-						'displayname' => $displayname,
658
-						'displaynameScope' => $displaynameScope,
659
-						'email' => $email,
660
-						'emailScope' => $emailScope,
661
-						'website' => $website,
662
-						'websiteScope' => $websiteScope,
663
-						'address' => $address,
664
-						'addressScope' => $addressScope,
665
-						'message' => (string)$this->l10n->t('Settings saved')
666
-					)
667
-				),
668
-				Http::STATUS_OK
669
-			);
670
-		} catch (ForbiddenException $e) {
671
-			return new DataResponse([
672
-				'status' => 'error',
673
-				'data' => [
674
-					'message' => $e->getMessage()
675
-				],
676
-			]);
677
-		}
678
-
679
-	}
680
-
681
-
682
-	/**
683
-	 * update account manager with new user data
684
-	 *
685
-	 * @param IUser $user
686
-	 * @param array $data
687
-	 * @throws ForbiddenException
688
-	 */
689
-	protected function saveUserSettings(IUser $user, $data) {
690
-
691
-		// keep the user back-end up-to-date with the latest display name and email
692
-		// address
693
-		$oldDisplayName = $user->getDisplayName();
694
-		$oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName;
695
-		if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value'])
696
-			&& $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value']
697
-		) {
698
-			$result = $user->setDisplayName($data[AccountManager::PROPERTY_DISPLAYNAME]['value']);
699
-			if ($result === false) {
700
-				throw new ForbiddenException($this->l10n->t('Unable to change full name'));
701
-			}
702
-		}
703
-
704
-		$oldEmailAddress = $user->getEMailAddress();
705
-		$oldEmailAddress = is_null($oldEmailAddress) ? '' : $oldEmailAddress;
706
-		if (isset($data[AccountManager::PROPERTY_EMAIL]['value'])
707
-			&& $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value']
708
-		) {
709
-			// this is the only permission a backend provides and is also used
710
-			// for the permission of setting a email address
711
-			if (!$user->canChangeDisplayName()) {
712
-				throw new ForbiddenException($this->l10n->t('Unable to change email address'));
713
-			}
714
-			$user->setEMailAddress($data[AccountManager::PROPERTY_EMAIL]['value']);
715
-		}
716
-
717
-		$this->accountManager->updateUser($user, $data);
718
-	}
719
-
720
-	/**
721
-	 * Count all unique users visible for the current admin/subadmin.
722
-	 *
723
-	 * @NoAdminRequired
724
-	 *
725
-	 * @return DataResponse
726
-	 */
727
-	public function stats() {
728
-		$userCount = 0;
729
-		if ($this->isAdmin) {
730
-			$countByBackend = $this->userManager->countUsers();
731
-
732
-			if (!empty($countByBackend)) {
733
-				foreach ($countByBackend as $count) {
734
-					$userCount += $count;
735
-				}
736
-			}
737
-		} else {
738
-			$groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser());
739
-
740
-			$uniqueUsers = [];
741
-			foreach ($groups as $group) {
742
-				foreach($group->getUsers() as $uid => $displayName) {
743
-					$uniqueUsers[$uid] = true;
744
-				}
745
-			}
746
-
747
-			$userCount = count($uniqueUsers);
748
-		}
749
-
750
-		return new DataResponse(
751
-			[
752
-				'totalUsers' => $userCount
753
-			]
754
-		);
755
-	}
756
-
757
-
758
-	/**
759
-	 * Set the displayName of a user
760
-	 *
761
-	 * @NoAdminRequired
762
-	 * @NoSubadminRequired
763
-	 * @PasswordConfirmationRequired
764
-	 * @todo merge into saveUserSettings
765
-	 *
766
-	 * @param string $username
767
-	 * @param string $displayName
768
-	 * @return DataResponse
769
-	 */
770
-	public function setDisplayName($username, $displayName) {
771
-		$currentUser = $this->userSession->getUser();
772
-		$user = $this->userManager->get($username);
773
-
774
-		if ($user === null ||
775
-			!$user->canChangeDisplayName() ||
776
-			(
777
-				!$this->groupManager->isAdmin($currentUser->getUID()) &&
778
-				!$this->groupManager->getSubAdmin()->isUserAccessible($currentUser, $user) &&
779
-				$currentUser->getUID() !== $username
780
-
781
-			)
782
-		) {
783
-			return new DataResponse([
784
-				'status' => 'error',
785
-				'data' => [
786
-					'message' => $this->l10n->t('Authentication error'),
787
-				],
788
-			]);
789
-		}
790
-
791
-		$userData = $this->accountManager->getUser($user);
792
-		$userData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $displayName;
793
-
794
-
795
-		try {
796
-			$this->saveUserSettings($user, $userData);
797
-			return new DataResponse([
798
-				'status' => 'success',
799
-				'data' => [
800
-					'message' => $this->l10n->t('Your full name has been changed.'),
801
-					'username' => $username,
802
-					'displayName' => $displayName,
803
-				],
804
-			]);
805
-		} catch (ForbiddenException $e) {
806
-			return new DataResponse([
807
-				'status' => 'error',
808
-				'data' => [
809
-					'message' => $e->getMessage(),
810
-					'displayName' => $user->getDisplayName(),
811
-				],
812
-			]);
813
-		}
814
-	}
815
-
816
-	/**
817
-	 * Set the mail address of a user
818
-	 *
819
-	 * @NoAdminRequired
820
-	 * @NoSubadminRequired
821
-	 * @PasswordConfirmationRequired
822
-	 *
823
-	 * @param string $id
824
-	 * @param string $mailAddress
825
-	 * @return DataResponse
826
-	 */
827
-	public function setEMailAddress($id, $mailAddress) {
828
-		$user = $this->userManager->get($id);
829
-		if (!$this->isAdmin
830
-			&& !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)
831
-		) {
832
-			return new DataResponse(
833
-				array(
834
-					'status' => 'error',
835
-					'data' => array(
836
-						'message' => (string)$this->l10n->t('Forbidden')
837
-					)
838
-				),
839
-				Http::STATUS_FORBIDDEN
840
-			);
841
-		}
842
-
843
-		if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) {
844
-			return new DataResponse(
845
-				array(
846
-					'status' => 'error',
847
-					'data' => array(
848
-						'message' => (string)$this->l10n->t('Invalid mail address')
849
-					)
850
-				),
851
-				Http::STATUS_UNPROCESSABLE_ENTITY
852
-			);
853
-		}
854
-
855
-		if (!$user) {
856
-			return new DataResponse(
857
-				array(
858
-					'status' => 'error',
859
-					'data' => array(
860
-						'message' => (string)$this->l10n->t('Invalid user')
861
-					)
862
-				),
863
-				Http::STATUS_UNPROCESSABLE_ENTITY
864
-			);
865
-		}
866
-		// this is the only permission a backend provides and is also used
867
-		// for the permission of setting a email address
868
-		if (!$user->canChangeDisplayName()) {
869
-			return new DataResponse(
870
-				array(
871
-					'status' => 'error',
872
-					'data' => array(
873
-						'message' => (string)$this->l10n->t('Unable to change mail address')
874
-					)
875
-				),
876
-				Http::STATUS_FORBIDDEN
877
-			);
878
-		}
879
-
880
-		$userData = $this->accountManager->getUser($user);
881
-		$userData[AccountManager::PROPERTY_EMAIL]['value'] = $mailAddress;
882
-
883
-		try {
884
-			$this->saveUserSettings($user, $userData);
885
-			return new DataResponse(
886
-				array(
887
-					'status' => 'success',
888
-					'data' => array(
889
-						'username' => $id,
890
-						'mailAddress' => $mailAddress,
891
-						'message' => (string)$this->l10n->t('Email saved')
892
-					)
893
-				),
894
-				Http::STATUS_OK
895
-			);
896
-		} catch (ForbiddenException $e) {
897
-			return new DataResponse([
898
-				'status' => 'error',
899
-				'data' => [
900
-					'message' => $e->getMessage()
901
-				],
902
-			]);
903
-		}
904
-	}
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
+        $cloudId = $user->getCloudId();
567
+        $message = "My Federated Cloud ID: " . $cloudId;
568
+        $privateKey = $this->keyManager->getKey($user)->getPrivate();
569
+        openssl_sign(json_encode($message), $signature, $privateKey, OPENSSL_ALGO_SHA512);
570
+        $signatureBase64 = base64_encode($signature);
571
+
572
+        $code = $message . ' ' . $signatureBase64;
573
+
574
+        switch ($account) {
575
+            case 'verify-twitter':
576
+                $msg = $this->l10n->t('In order to verify your Twitter account post following tweet on Twitter:');
577
+                $code = substr($code, 0 , 140);
578
+                break;
579
+            case 'verify-website':
580
+                $msg = $this->l10n->t('In order to verify your Website store following content in your webroot at \'CloudIdVerificationCode.txt\':');
581
+                break;
582
+            default:
583
+                return new DataResponse([], Http::STATUS_BAD_REQUEST);
584
+                break;
585
+        }
586
+
587
+        return new DataResponse(['msg' => $msg, 'code' => $code]);
588
+    }
589
+
590
+    /**
591
+     * @NoAdminRequired
592
+     * @NoSubadminRequired
593
+     * @PasswordConfirmationRequired
594
+     *
595
+     * @param string $avatarScope
596
+     * @param string $displayname
597
+     * @param string $displaynameScope
598
+     * @param string $phone
599
+     * @param string $phoneScope
600
+     * @param string $email
601
+     * @param string $emailScope
602
+     * @param string $website
603
+     * @param string $websiteScope
604
+     * @param string $address
605
+     * @param string $addressScope
606
+     * @param string $twitter
607
+     * @param string $twitterScope
608
+     * @return DataResponse
609
+     */
610
+    public function setUserSettings($avatarScope,
611
+                                    $displayname,
612
+                                    $displaynameScope,
613
+                                    $phone,
614
+                                    $phoneScope,
615
+                                    $email,
616
+                                    $emailScope,
617
+                                    $website,
618
+                                    $websiteScope,
619
+                                    $address,
620
+                                    $addressScope,
621
+                                    $twitter,
622
+                                    $twitterScope
623
+    ) {
624
+
625
+        if(!empty($email) && !$this->mailer->validateMailAddress($email)) {
626
+            return new DataResponse(
627
+                array(
628
+                    'status' => 'error',
629
+                    'data' => array(
630
+                        'message' => (string)$this->l10n->t('Invalid mail address')
631
+                    )
632
+                ),
633
+                Http::STATUS_UNPROCESSABLE_ENTITY
634
+            );
635
+        }
636
+
637
+        $data = [
638
+            AccountManager::PROPERTY_AVATAR =>  ['scope' => $avatarScope],
639
+            AccountManager::PROPERTY_DISPLAYNAME => ['value' => $displayname, 'scope' => $displaynameScope],
640
+            AccountManager::PROPERTY_EMAIL=> ['value' => $email, 'scope' => $emailScope],
641
+            AccountManager::PROPERTY_WEBSITE => ['value' => $website, 'scope' => $websiteScope],
642
+            AccountManager::PROPERTY_ADDRESS => ['value' => $address, 'scope' => $addressScope],
643
+            AccountManager::PROPERTY_PHONE => ['value' => $phone, 'scope' => $phoneScope],
644
+            AccountManager::PROPERTY_TWITTER => ['value' => $twitter, 'scope' => $twitterScope]
645
+        ];
646
+
647
+        $user = $this->userSession->getUser();
648
+
649
+        try {
650
+            $this->saveUserSettings($user, $data);
651
+            return new DataResponse(
652
+                array(
653
+                    'status' => 'success',
654
+                    'data' => array(
655
+                        'userId' => $user->getUID(),
656
+                        'avatarScope' => $avatarScope,
657
+                        'displayname' => $displayname,
658
+                        'displaynameScope' => $displaynameScope,
659
+                        'email' => $email,
660
+                        'emailScope' => $emailScope,
661
+                        'website' => $website,
662
+                        'websiteScope' => $websiteScope,
663
+                        'address' => $address,
664
+                        'addressScope' => $addressScope,
665
+                        'message' => (string)$this->l10n->t('Settings saved')
666
+                    )
667
+                ),
668
+                Http::STATUS_OK
669
+            );
670
+        } catch (ForbiddenException $e) {
671
+            return new DataResponse([
672
+                'status' => 'error',
673
+                'data' => [
674
+                    'message' => $e->getMessage()
675
+                ],
676
+            ]);
677
+        }
678
+
679
+    }
680
+
681
+
682
+    /**
683
+     * update account manager with new user data
684
+     *
685
+     * @param IUser $user
686
+     * @param array $data
687
+     * @throws ForbiddenException
688
+     */
689
+    protected function saveUserSettings(IUser $user, $data) {
690
+
691
+        // keep the user back-end up-to-date with the latest display name and email
692
+        // address
693
+        $oldDisplayName = $user->getDisplayName();
694
+        $oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName;
695
+        if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value'])
696
+            && $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value']
697
+        ) {
698
+            $result = $user->setDisplayName($data[AccountManager::PROPERTY_DISPLAYNAME]['value']);
699
+            if ($result === false) {
700
+                throw new ForbiddenException($this->l10n->t('Unable to change full name'));
701
+            }
702
+        }
703
+
704
+        $oldEmailAddress = $user->getEMailAddress();
705
+        $oldEmailAddress = is_null($oldEmailAddress) ? '' : $oldEmailAddress;
706
+        if (isset($data[AccountManager::PROPERTY_EMAIL]['value'])
707
+            && $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value']
708
+        ) {
709
+            // this is the only permission a backend provides and is also used
710
+            // for the permission of setting a email address
711
+            if (!$user->canChangeDisplayName()) {
712
+                throw new ForbiddenException($this->l10n->t('Unable to change email address'));
713
+            }
714
+            $user->setEMailAddress($data[AccountManager::PROPERTY_EMAIL]['value']);
715
+        }
716
+
717
+        $this->accountManager->updateUser($user, $data);
718
+    }
719
+
720
+    /**
721
+     * Count all unique users visible for the current admin/subadmin.
722
+     *
723
+     * @NoAdminRequired
724
+     *
725
+     * @return DataResponse
726
+     */
727
+    public function stats() {
728
+        $userCount = 0;
729
+        if ($this->isAdmin) {
730
+            $countByBackend = $this->userManager->countUsers();
731
+
732
+            if (!empty($countByBackend)) {
733
+                foreach ($countByBackend as $count) {
734
+                    $userCount += $count;
735
+                }
736
+            }
737
+        } else {
738
+            $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser());
739
+
740
+            $uniqueUsers = [];
741
+            foreach ($groups as $group) {
742
+                foreach($group->getUsers() as $uid => $displayName) {
743
+                    $uniqueUsers[$uid] = true;
744
+                }
745
+            }
746
+
747
+            $userCount = count($uniqueUsers);
748
+        }
749
+
750
+        return new DataResponse(
751
+            [
752
+                'totalUsers' => $userCount
753
+            ]
754
+        );
755
+    }
756
+
757
+
758
+    /**
759
+     * Set the displayName of a user
760
+     *
761
+     * @NoAdminRequired
762
+     * @NoSubadminRequired
763
+     * @PasswordConfirmationRequired
764
+     * @todo merge into saveUserSettings
765
+     *
766
+     * @param string $username
767
+     * @param string $displayName
768
+     * @return DataResponse
769
+     */
770
+    public function setDisplayName($username, $displayName) {
771
+        $currentUser = $this->userSession->getUser();
772
+        $user = $this->userManager->get($username);
773
+
774
+        if ($user === null ||
775
+            !$user->canChangeDisplayName() ||
776
+            (
777
+                !$this->groupManager->isAdmin($currentUser->getUID()) &&
778
+                !$this->groupManager->getSubAdmin()->isUserAccessible($currentUser, $user) &&
779
+                $currentUser->getUID() !== $username
780
+
781
+            )
782
+        ) {
783
+            return new DataResponse([
784
+                'status' => 'error',
785
+                'data' => [
786
+                    'message' => $this->l10n->t('Authentication error'),
787
+                ],
788
+            ]);
789
+        }
790
+
791
+        $userData = $this->accountManager->getUser($user);
792
+        $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $displayName;
793
+
794
+
795
+        try {
796
+            $this->saveUserSettings($user, $userData);
797
+            return new DataResponse([
798
+                'status' => 'success',
799
+                'data' => [
800
+                    'message' => $this->l10n->t('Your full name has been changed.'),
801
+                    'username' => $username,
802
+                    'displayName' => $displayName,
803
+                ],
804
+            ]);
805
+        } catch (ForbiddenException $e) {
806
+            return new DataResponse([
807
+                'status' => 'error',
808
+                'data' => [
809
+                    'message' => $e->getMessage(),
810
+                    'displayName' => $user->getDisplayName(),
811
+                ],
812
+            ]);
813
+        }
814
+    }
815
+
816
+    /**
817
+     * Set the mail address of a user
818
+     *
819
+     * @NoAdminRequired
820
+     * @NoSubadminRequired
821
+     * @PasswordConfirmationRequired
822
+     *
823
+     * @param string $id
824
+     * @param string $mailAddress
825
+     * @return DataResponse
826
+     */
827
+    public function setEMailAddress($id, $mailAddress) {
828
+        $user = $this->userManager->get($id);
829
+        if (!$this->isAdmin
830
+            && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)
831
+        ) {
832
+            return new DataResponse(
833
+                array(
834
+                    'status' => 'error',
835
+                    'data' => array(
836
+                        'message' => (string)$this->l10n->t('Forbidden')
837
+                    )
838
+                ),
839
+                Http::STATUS_FORBIDDEN
840
+            );
841
+        }
842
+
843
+        if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) {
844
+            return new DataResponse(
845
+                array(
846
+                    'status' => 'error',
847
+                    'data' => array(
848
+                        'message' => (string)$this->l10n->t('Invalid mail address')
849
+                    )
850
+                ),
851
+                Http::STATUS_UNPROCESSABLE_ENTITY
852
+            );
853
+        }
854
+
855
+        if (!$user) {
856
+            return new DataResponse(
857
+                array(
858
+                    'status' => 'error',
859
+                    'data' => array(
860
+                        'message' => (string)$this->l10n->t('Invalid user')
861
+                    )
862
+                ),
863
+                Http::STATUS_UNPROCESSABLE_ENTITY
864
+            );
865
+        }
866
+        // this is the only permission a backend provides and is also used
867
+        // for the permission of setting a email address
868
+        if (!$user->canChangeDisplayName()) {
869
+            return new DataResponse(
870
+                array(
871
+                    'status' => 'error',
872
+                    'data' => array(
873
+                        'message' => (string)$this->l10n->t('Unable to change mail address')
874
+                    )
875
+                ),
876
+                Http::STATUS_FORBIDDEN
877
+            );
878
+        }
879
+
880
+        $userData = $this->accountManager->getUser($user);
881
+        $userData[AccountManager::PROPERTY_EMAIL]['value'] = $mailAddress;
882
+
883
+        try {
884
+            $this->saveUserSettings($user, $userData);
885
+            return new DataResponse(
886
+                array(
887
+                    'status' => 'success',
888
+                    'data' => array(
889
+                        'username' => $id,
890
+                        'mailAddress' => $mailAddress,
891
+                        'message' => (string)$this->l10n->t('Email saved')
892
+                    )
893
+                ),
894
+                Http::STATUS_OK
895
+            );
896
+        } catch (ForbiddenException $e) {
897
+            return new DataResponse([
898
+                'status' => 'error',
899
+                'data' => [
900
+                    'message' => $e->getMessage()
901
+                ],
902
+            ]);
903
+        }
904
+    }
905 905
 
906 906
 }
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
@@ -564,17 +564,17 @@  discard block
 block discarded – undo
564 564
 
565 565
 		$user = $this->userSession->getUser();
566 566
 		$cloudId = $user->getCloudId();
567
-		$message = "My Federated Cloud ID: " . $cloudId;
567
+		$message = "My Federated Cloud ID: ".$cloudId;
568 568
 		$privateKey = $this->keyManager->getKey($user)->getPrivate();
569 569
 		openssl_sign(json_encode($message), $signature, $privateKey, OPENSSL_ALGO_SHA512);
570 570
 		$signatureBase64 = base64_encode($signature);
571 571
 
572
-		$code = $message . ' ' . $signatureBase64;
572
+		$code = $message.' '.$signatureBase64;
573 573
 
574 574
 		switch ($account) {
575 575
 			case 'verify-twitter':
576 576
 				$msg = $this->l10n->t('In order to verify your Twitter account post following tweet on Twitter:');
577
-				$code = substr($code, 0 , 140);
577
+				$code = substr($code, 0, 140);
578 578
 				break;
579 579
 			case 'verify-website':
580 580
 				$msg = $this->l10n->t('In order to verify your Website store following content in your webroot at \'CloudIdVerificationCode.txt\':');
@@ -622,12 +622,12 @@  discard block
 block discarded – undo
622 622
 									$twitterScope
623 623
 	) {
624 624
 
625
-		if(!empty($email) && !$this->mailer->validateMailAddress($email)) {
625
+		if (!empty($email) && !$this->mailer->validateMailAddress($email)) {
626 626
 			return new DataResponse(
627 627
 				array(
628 628
 					'status' => 'error',
629 629
 					'data' => array(
630
-						'message' => (string)$this->l10n->t('Invalid mail address')
630
+						'message' => (string) $this->l10n->t('Invalid mail address')
631 631
 					)
632 632
 				),
633 633
 				Http::STATUS_UNPROCESSABLE_ENTITY
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
 						'websiteScope' => $websiteScope,
663 663
 						'address' => $address,
664 664
 						'addressScope' => $addressScope,
665
-						'message' => (string)$this->l10n->t('Settings saved')
665
+						'message' => (string) $this->l10n->t('Settings saved')
666 666
 					)
667 667
 				),
668 668
 				Http::STATUS_OK
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
 
740 740
 			$uniqueUsers = [];
741 741
 			foreach ($groups as $group) {
742
-				foreach($group->getUsers() as $uid => $displayName) {
742
+				foreach ($group->getUsers() as $uid => $displayName) {
743 743
 					$uniqueUsers[$uid] = true;
744 744
 				}
745 745
 			}
@@ -833,19 +833,19 @@  discard block
 block discarded – undo
833 833
 				array(
834 834
 					'status' => 'error',
835 835
 					'data' => array(
836
-						'message' => (string)$this->l10n->t('Forbidden')
836
+						'message' => (string) $this->l10n->t('Forbidden')
837 837
 					)
838 838
 				),
839 839
 				Http::STATUS_FORBIDDEN
840 840
 			);
841 841
 		}
842 842
 
843
-		if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) {
843
+		if ($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) {
844 844
 			return new DataResponse(
845 845
 				array(
846 846
 					'status' => 'error',
847 847
 					'data' => array(
848
-						'message' => (string)$this->l10n->t('Invalid mail address')
848
+						'message' => (string) $this->l10n->t('Invalid mail address')
849 849
 					)
850 850
 				),
851 851
 				Http::STATUS_UNPROCESSABLE_ENTITY
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
 				array(
858 858
 					'status' => 'error',
859 859
 					'data' => array(
860
-						'message' => (string)$this->l10n->t('Invalid user')
860
+						'message' => (string) $this->l10n->t('Invalid user')
861 861
 					)
862 862
 				),
863 863
 				Http::STATUS_UNPROCESSABLE_ENTITY
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
 				array(
871 871
 					'status' => 'error',
872 872
 					'data' => array(
873
-						'message' => (string)$this->l10n->t('Unable to change mail address')
873
+						'message' => (string) $this->l10n->t('Unable to change mail address')
874 874
 					)
875 875
 				),
876 876
 				Http::STATUS_FORBIDDEN
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
 					'data' => array(
889 889
 						'username' => $id,
890 890
 						'mailAddress' => $mailAddress,
891
-						'message' => (string)$this->l10n->t('Email saved')
891
+						'message' => (string) $this->l10n->t('Email saved')
892 892
 					)
893 893
 				),
894 894
 				Http::STATUS_OK
Please login to merge, or discard this patch.