Completed
Pull Request — master (#9555)
by John
16:47
created
settings/Controller/UsersController.php 1 patch
Indentation   +372 added lines, -372 removed lines patch added patch discarded remove patch
@@ -65,407 +65,407 @@
 block discarded – undo
65 65
  * @package OC\Settings\Controller
66 66
  */
67 67
 class UsersController extends Controller {
68
-	/** @var IUserManager */
69
-	private $userManager;
70
-	/** @var IGroupManager */
71
-	private $groupManager;
72
-	/** @var IUserSession */
73
-	private $userSession;
74
-	/** @var IConfig */
75
-	private $config;
76
-	/** @var bool */
77
-	private $isAdmin;
78
-	/** @var IL10N */
79
-	private $l10n;
80
-	/** @var IMailer */
81
-	private $mailer;
82
-	/** @var IFactory */
83
-	private $l10nFactory;
84
-	/** @var IAppManager */
85
-	private $appManager;
86
-	/** @var AccountManager */
87
-	private $accountManager;
88
-	/** @var Manager */
89
-	private $keyManager;
90
-	/** @var IJobList */
91
-	private $jobList;
92
-	/** @var IManager */
93
-	private $encryptionManager;
68
+    /** @var IUserManager */
69
+    private $userManager;
70
+    /** @var IGroupManager */
71
+    private $groupManager;
72
+    /** @var IUserSession */
73
+    private $userSession;
74
+    /** @var IConfig */
75
+    private $config;
76
+    /** @var bool */
77
+    private $isAdmin;
78
+    /** @var IL10N */
79
+    private $l10n;
80
+    /** @var IMailer */
81
+    private $mailer;
82
+    /** @var IFactory */
83
+    private $l10nFactory;
84
+    /** @var IAppManager */
85
+    private $appManager;
86
+    /** @var AccountManager */
87
+    private $accountManager;
88
+    /** @var Manager */
89
+    private $keyManager;
90
+    /** @var IJobList */
91
+    private $jobList;
92
+    /** @var IManager */
93
+    private $encryptionManager;
94 94
 
95 95
 
96
-	public function __construct(string $appName,
97
-								IRequest $request,
98
-								IUserManager $userManager,
99
-								IGroupManager $groupManager,
100
-								IUserSession $userSession,
101
-								IConfig $config,
102
-								bool $isAdmin,
103
-								IL10N $l10n,
104
-								IMailer $mailer,
105
-								IFactory $l10nFactory,
106
-								IAppManager $appManager,
107
-								AccountManager $accountManager,
108
-								Manager $keyManager,
109
-								IJobList $jobList,
110
-								IManager $encryptionManager) {
111
-		parent::__construct($appName, $request);
112
-		$this->userManager = $userManager;
113
-		$this->groupManager = $groupManager;
114
-		$this->userSession = $userSession;
115
-		$this->config = $config;
116
-		$this->isAdmin = $isAdmin;
117
-		$this->l10n = $l10n;
118
-		$this->mailer = $mailer;
119
-		$this->l10nFactory = $l10nFactory;
120
-		$this->appManager = $appManager;
121
-		$this->accountManager = $accountManager;
122
-		$this->keyManager = $keyManager;
123
-		$this->jobList = $jobList;
124
-		$this->encryptionManager = $encryptionManager;
125
-	}
96
+    public function __construct(string $appName,
97
+                                IRequest $request,
98
+                                IUserManager $userManager,
99
+                                IGroupManager $groupManager,
100
+                                IUserSession $userSession,
101
+                                IConfig $config,
102
+                                bool $isAdmin,
103
+                                IL10N $l10n,
104
+                                IMailer $mailer,
105
+                                IFactory $l10nFactory,
106
+                                IAppManager $appManager,
107
+                                AccountManager $accountManager,
108
+                                Manager $keyManager,
109
+                                IJobList $jobList,
110
+                                IManager $encryptionManager) {
111
+        parent::__construct($appName, $request);
112
+        $this->userManager = $userManager;
113
+        $this->groupManager = $groupManager;
114
+        $this->userSession = $userSession;
115
+        $this->config = $config;
116
+        $this->isAdmin = $isAdmin;
117
+        $this->l10n = $l10n;
118
+        $this->mailer = $mailer;
119
+        $this->l10nFactory = $l10nFactory;
120
+        $this->appManager = $appManager;
121
+        $this->accountManager = $accountManager;
122
+        $this->keyManager = $keyManager;
123
+        $this->jobList = $jobList;
124
+        $this->encryptionManager = $encryptionManager;
125
+    }
126 126
 
127 127
 
128
-	/**
129
-	 * @NoCSRFRequired
130
-	 * @NoAdminRequired
131
-	 * 
132
-	 * Display users list template
133
-	 * 
134
-	 * @return TemplateResponse
135
-	 */
136
-	public function usersListByGroup() {
137
-		return $this->usersList();
138
-	}
128
+    /**
129
+     * @NoCSRFRequired
130
+     * @NoAdminRequired
131
+     * 
132
+     * Display users list template
133
+     * 
134
+     * @return TemplateResponse
135
+     */
136
+    public function usersListByGroup() {
137
+        return $this->usersList();
138
+    }
139 139
 
140
-	/**
141
-	 * @NoCSRFRequired
142
-	 * @NoAdminRequired
143
-	 * 
144
-	 * Display users list template
145
-	 * 
146
-	 * @return TemplateResponse
147
-	 */
148
-	public function usersList() {
149
-		$user = $this->userSession->getUser();
150
-		$uid = $user->getUID();
140
+    /**
141
+     * @NoCSRFRequired
142
+     * @NoAdminRequired
143
+     * 
144
+     * Display users list template
145
+     * 
146
+     * @return TemplateResponse
147
+     */
148
+    public function usersList() {
149
+        $user = $this->userSession->getUser();
150
+        $uid = $user->getUID();
151 151
 
152
-		\OC::$server->getNavigationManager()->setActiveEntry('core_users');
152
+        \OC::$server->getNavigationManager()->setActiveEntry('core_users');
153 153
 				
154
-		/* SORT OPTION: SORT_USERCOUNT or SORT_GROUPNAME */
155
-		$sortGroupsBy = \OC\Group\MetaData::SORT_USERCOUNT;
156
-		if ($this->config->getSystemValue('sort_groups_by_name', false)) {
157
-			$sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
158
-		} else {
159
-			$isLDAPUsed = false;
160
-			if ($this->appManager->isEnabledForUser('user_ldap')) {
161
-				$isLDAPUsed =
162
-					$this->groupManager->isBackendUsed('\OCA\User_LDAP\Group_LDAP')
163
-					|| $this->groupManager->isBackendUsed('\OCA\User_LDAP\Group_Proxy');
164
-				if ($isLDAPUsed) {
165
-					// LDAP user count can be slow, so we sort by group name here
166
-					$sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
167
-				}
168
-			}
169
-		}
154
+        /* SORT OPTION: SORT_USERCOUNT or SORT_GROUPNAME */
155
+        $sortGroupsBy = \OC\Group\MetaData::SORT_USERCOUNT;
156
+        if ($this->config->getSystemValue('sort_groups_by_name', false)) {
157
+            $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
158
+        } else {
159
+            $isLDAPUsed = false;
160
+            if ($this->appManager->isEnabledForUser('user_ldap')) {
161
+                $isLDAPUsed =
162
+                    $this->groupManager->isBackendUsed('\OCA\User_LDAP\Group_LDAP')
163
+                    || $this->groupManager->isBackendUsed('\OCA\User_LDAP\Group_Proxy');
164
+                if ($isLDAPUsed) {
165
+                    // LDAP user count can be slow, so we sort by group name here
166
+                    $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
167
+                }
168
+            }
169
+        }
170 170
 		
171
-		/* ENCRYPTION CONFIG */
172
-		$isEncryptionEnabled = $this->encryptionManager->isEnabled();
173
-		$useMasterKey = $this->config->getAppValue('encryption', 'useMasterKey', true);
174
-		// If masterKey enabled, then you can change password. This is to avoid data loss!
175
-		$canChangePassword = ($isEncryptionEnabled && $useMasterKey) || $useMasterKey;
171
+        /* ENCRYPTION CONFIG */
172
+        $isEncryptionEnabled = $this->encryptionManager->isEnabled();
173
+        $useMasterKey = $this->config->getAppValue('encryption', 'useMasterKey', true);
174
+        // If masterKey enabled, then you can change password. This is to avoid data loss!
175
+        $canChangePassword = ($isEncryptionEnabled && $useMasterKey) || $useMasterKey;
176 176
 		
177 177
 		
178
-		/* GROUPS */		
179
-		$groupsInfo = new \OC\Group\MetaData(
180
-			$uid,
181
-			$this->isAdmin,
182
-			$this->groupManager,
183
-			$this->userSession
184
-		);
178
+        /* GROUPS */		
179
+        $groupsInfo = new \OC\Group\MetaData(
180
+            $uid,
181
+            $this->isAdmin,
182
+            $this->groupManager,
183
+            $this->userSession
184
+        );
185 185
 		
186
-		$groupsInfo->setSorting($sortGroupsBy);
187
-		list($adminGroup, $groups) = $groupsInfo->get();
186
+        $groupsInfo->setSorting($sortGroupsBy);
187
+        list($adminGroup, $groups) = $groupsInfo->get();
188 188
 		
189
-		if ($this->isAdmin) {
190
-			$subAdmins = $this->groupManager->getSubAdmin()->getAllSubAdmins();
191
-			// New class returns IUser[] so convert back
192
-			$result = [];
193
-			foreach ($subAdmins as $subAdmin) {
194
-				$result[] = [
195
-					'gid' => $subAdmin['group']->getGID(),
196
-					'uid' => $subAdmin['user']->getUID(),
197
-				];
198
-			}
199
-			$subAdmins = $result;
200
-		} else {
201
-			/* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
202
-			$gids = array();
203
-			foreach($groups as $group) {
204
-				if (isset($group['id'])) {
205
-					$gids[] = $group['id'];
206
-				}
207
-			}
208
-			$subAdmins = false;
209
-		}
189
+        if ($this->isAdmin) {
190
+            $subAdmins = $this->groupManager->getSubAdmin()->getAllSubAdmins();
191
+            // New class returns IUser[] so convert back
192
+            $result = [];
193
+            foreach ($subAdmins as $subAdmin) {
194
+                $result[] = [
195
+                    'gid' => $subAdmin['group']->getGID(),
196
+                    'uid' => $subAdmin['user']->getUID(),
197
+                ];
198
+            }
199
+            $subAdmins = $result;
200
+        } else {
201
+            /* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
202
+            $gids = array();
203
+            foreach($groups as $group) {
204
+                if (isset($group['id'])) {
205
+                    $gids[] = $group['id'];
206
+                }
207
+            }
208
+            $subAdmins = false;
209
+        }
210 210
 		
211
-		$disabledUsers = $isLDAPUsed ? 0 : $this->userManager->countDisabledUsers();
212
-		$disabledUsersGroup = [
213
-			'id' => 'disabled',
214
-			'name' => 'Disabled users',
215
-			'usercount' => $disabledUsers
216
-		];
217
-		$allGroups = array_merge_recursive($adminGroup, $groups);
211
+        $disabledUsers = $isLDAPUsed ? 0 : $this->userManager->countDisabledUsers();
212
+        $disabledUsersGroup = [
213
+            'id' => 'disabled',
214
+            'name' => 'Disabled users',
215
+            'usercount' => $disabledUsers
216
+        ];
217
+        $allGroups = array_merge_recursive($adminGroup, $groups);
218 218
 		
219
-		/* QUOTAS PRESETS */
220
-		$quotaPreset = $this->config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
221
-		$quotaPreset = explode(',', $quotaPreset);
222
-		foreach ($quotaPreset as &$preset) {
223
-			$preset = trim($preset);
224
-		}
225
-		$quotaPreset = array_diff($quotaPreset, array('default', 'none'));
226
-		$defaultQuota = $this->config->getAppValue('files', 'default_quota', 'none');
219
+        /* QUOTAS PRESETS */
220
+        $quotaPreset = $this->config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
221
+        $quotaPreset = explode(',', $quotaPreset);
222
+        foreach ($quotaPreset as &$preset) {
223
+            $preset = trim($preset);
224
+        }
225
+        $quotaPreset = array_diff($quotaPreset, array('default', 'none'));
226
+        $defaultQuota = $this->config->getAppValue('files', 'default_quota', 'none');
227 227
 		
228
-		\OC::$server->getEventDispatcher()->dispatch('OC\Settings\Users::loadAdditionalScripts');
228
+        \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Users::loadAdditionalScripts');
229 229
 		
230
-		/* TOTAL USERS COUNT */
231
-		$userCount = array_reduce($this->userManager->countUsers(), function($v, $w) {
232
-			return $v + (int)$w;
233
-		}, 0);
230
+        /* TOTAL USERS COUNT */
231
+        $userCount = array_reduce($this->userManager->countUsers(), function($v, $w) {
232
+            return $v + (int)$w;
233
+        }, 0);
234 234
 		
235
-		/* LANGUAGES */
236
-		$languages = $this->l10nFactory->getLanguages();
235
+        /* LANGUAGES */
236
+        $languages = $this->l10nFactory->getLanguages();
237 237
 		
238
-		/* FINAL DATA */
239
-		$serverData = array();
240
-		// groups
241
-		$serverData['groups'] = array_merge_recursive($adminGroup, [$disabledUsersGroup], $groups);
242
-		// Various data
243
-		$serverData['isAdmin'] = $this->isAdmin;
244
-		$serverData['subadmins'] = $subAdmins;
245
-		$serverData['sortGroups'] = $sortGroupsBy;
246
-		$serverData['quotaPreset'] = $quotaPreset;
247
-		$serverData['userCount'] = $userCount-$disabledUsers;
248
-		$serverData['languages'] = $languages;
249
-		$serverData['defaultLanguage'] = $this->config->getSystemValue('default_language', 'en');
250
-		// Settings
251
-		$serverData['defaultQuota'] = $defaultQuota;
252
-		$serverData['canChangePassword'] = $canChangePassword;
238
+        /* FINAL DATA */
239
+        $serverData = array();
240
+        // groups
241
+        $serverData['groups'] = array_merge_recursive($adminGroup, [$disabledUsersGroup], $groups);
242
+        // Various data
243
+        $serverData['isAdmin'] = $this->isAdmin;
244
+        $serverData['subadmins'] = $subAdmins;
245
+        $serverData['sortGroups'] = $sortGroupsBy;
246
+        $serverData['quotaPreset'] = $quotaPreset;
247
+        $serverData['userCount'] = $userCount-$disabledUsers;
248
+        $serverData['languages'] = $languages;
249
+        $serverData['defaultLanguage'] = $this->config->getSystemValue('default_language', 'en');
250
+        // Settings
251
+        $serverData['defaultQuota'] = $defaultQuota;
252
+        $serverData['canChangePassword'] = $canChangePassword;
253 253
 
254
-		return new TemplateResponse('settings', 'settings', ['serverData' => $serverData]);
255
-	}
254
+        return new TemplateResponse('settings', 'settings', ['serverData' => $serverData]);
255
+    }
256 256
 
257
-	/**
258
-	 * @NoAdminRequired
259
-	 * @NoSubadminRequired
260
-	 * @PasswordConfirmationRequired
261
-	 *
262
-	 * @param string $avatarScope
263
-	 * @param string $displayname
264
-	 * @param string $displaynameScope
265
-	 * @param string $phone
266
-	 * @param string $phoneScope
267
-	 * @param string $email
268
-	 * @param string $emailScope
269
-	 * @param string $website
270
-	 * @param string $websiteScope
271
-	 * @param string $address
272
-	 * @param string $addressScope
273
-	 * @param string $twitter
274
-	 * @param string $twitterScope
275
-	 * @return DataResponse
276
-	 */
277
-	public function setUserSettings($avatarScope,
278
-									$displayname,
279
-									$displaynameScope,
280
-									$phone,
281
-									$phoneScope,
282
-									$email,
283
-									$emailScope,
284
-									$website,
285
-									$websiteScope,
286
-									$address,
287
-									$addressScope,
288
-									$twitter,
289
-									$twitterScope
290
-	) {
291
-		if (!empty($email) && !$this->mailer->validateMailAddress($email)) {
292
-			return new DataResponse(
293
-				[
294
-					'status' => 'error',
295
-					'data' => [
296
-						'message' => $this->l10n->t('Invalid mail address')
297
-					]
298
-				],
299
-				Http::STATUS_UNPROCESSABLE_ENTITY
300
-			);
301
-		}
302
-		$user = $this->userSession->getUser();
303
-		$data = $this->accountManager->getUser($user);
304
-		$data[AccountManager::PROPERTY_AVATAR] = ['scope' => $avatarScope];
305
-		if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
306
-			$data[AccountManager::PROPERTY_DISPLAYNAME] = ['value' => $displayname, 'scope' => $displaynameScope];
307
-			$data[AccountManager::PROPERTY_EMAIL] = ['value' => $email, 'scope' => $emailScope];
308
-		}
309
-		if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
310
-			$federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application();
311
-			$shareProvider = $federatedFileSharing->getFederatedShareProvider();
312
-			if ($shareProvider->isLookupServerUploadEnabled()) {
313
-				$data[AccountManager::PROPERTY_WEBSITE] = ['value' => $website, 'scope' => $websiteScope];
314
-				$data[AccountManager::PROPERTY_ADDRESS] = ['value' => $address, 'scope' => $addressScope];
315
-				$data[AccountManager::PROPERTY_PHONE] = ['value' => $phone, 'scope' => $phoneScope];
316
-				$data[AccountManager::PROPERTY_TWITTER] = ['value' => $twitter, 'scope' => $twitterScope];
317
-			}
318
-		}
319
-		try {
320
-			$this->saveUserSettings($user, $data);
321
-			return new DataResponse(
322
-				[
323
-					'status' => 'success',
324
-					'data' => [
325
-						'userId' => $user->getUID(),
326
-						'avatarScope' => $data[AccountManager::PROPERTY_AVATAR]['scope'],
327
-						'displayname' => $data[AccountManager::PROPERTY_DISPLAYNAME]['value'],
328
-						'displaynameScope' => $data[AccountManager::PROPERTY_DISPLAYNAME]['scope'],
329
-						'email' => $data[AccountManager::PROPERTY_EMAIL]['value'],
330
-						'emailScope' => $data[AccountManager::PROPERTY_EMAIL]['scope'],
331
-						'website' => $data[AccountManager::PROPERTY_WEBSITE]['value'],
332
-						'websiteScope' => $data[AccountManager::PROPERTY_WEBSITE]['scope'],
333
-						'address' => $data[AccountManager::PROPERTY_ADDRESS]['value'],
334
-						'addressScope' => $data[AccountManager::PROPERTY_ADDRESS]['scope'],
335
-						'message' => $this->l10n->t('Settings saved')
336
-					]
337
-				],
338
-				Http::STATUS_OK
339
-			);
340
-		} catch (ForbiddenException $e) {
341
-			return new DataResponse([
342
-				'status' => 'error',
343
-				'data' => [
344
-					'message' => $e->getMessage()
345
-				],
346
-			]);
347
-		}
348
-	}
349
-	/**
350
-	 * update account manager with new user data
351
-	 *
352
-	 * @param IUser $user
353
-	 * @param array $data
354
-	 * @throws ForbiddenException
355
-	 */
356
-	protected function saveUserSettings(IUser $user, array $data) {
357
-		// keep the user back-end up-to-date with the latest display name and email
358
-		// address
359
-		$oldDisplayName = $user->getDisplayName();
360
-		$oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName;
361
-		if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value'])
362
-			&& $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value']
363
-		) {
364
-			$result = $user->setDisplayName($data[AccountManager::PROPERTY_DISPLAYNAME]['value']);
365
-			if ($result === false) {
366
-				throw new ForbiddenException($this->l10n->t('Unable to change full name'));
367
-			}
368
-		}
369
-		$oldEmailAddress = $user->getEMailAddress();
370
-		$oldEmailAddress = is_null($oldEmailAddress) ? '' : $oldEmailAddress;
371
-		if (isset($data[AccountManager::PROPERTY_EMAIL]['value'])
372
-			&& $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value']
373
-		) {
374
-			// this is the only permission a backend provides and is also used
375
-			// for the permission of setting a email address
376
-			if (!$user->canChangeDisplayName()) {
377
-				throw new ForbiddenException($this->l10n->t('Unable to change email address'));
378
-			}
379
-			$user->setEMailAddress($data[AccountManager::PROPERTY_EMAIL]['value']);
380
-		}
381
-		$this->accountManager->updateUser($user, $data);
382
-	}
257
+    /**
258
+     * @NoAdminRequired
259
+     * @NoSubadminRequired
260
+     * @PasswordConfirmationRequired
261
+     *
262
+     * @param string $avatarScope
263
+     * @param string $displayname
264
+     * @param string $displaynameScope
265
+     * @param string $phone
266
+     * @param string $phoneScope
267
+     * @param string $email
268
+     * @param string $emailScope
269
+     * @param string $website
270
+     * @param string $websiteScope
271
+     * @param string $address
272
+     * @param string $addressScope
273
+     * @param string $twitter
274
+     * @param string $twitterScope
275
+     * @return DataResponse
276
+     */
277
+    public function setUserSettings($avatarScope,
278
+                                    $displayname,
279
+                                    $displaynameScope,
280
+                                    $phone,
281
+                                    $phoneScope,
282
+                                    $email,
283
+                                    $emailScope,
284
+                                    $website,
285
+                                    $websiteScope,
286
+                                    $address,
287
+                                    $addressScope,
288
+                                    $twitter,
289
+                                    $twitterScope
290
+    ) {
291
+        if (!empty($email) && !$this->mailer->validateMailAddress($email)) {
292
+            return new DataResponse(
293
+                [
294
+                    'status' => 'error',
295
+                    'data' => [
296
+                        'message' => $this->l10n->t('Invalid mail address')
297
+                    ]
298
+                ],
299
+                Http::STATUS_UNPROCESSABLE_ENTITY
300
+            );
301
+        }
302
+        $user = $this->userSession->getUser();
303
+        $data = $this->accountManager->getUser($user);
304
+        $data[AccountManager::PROPERTY_AVATAR] = ['scope' => $avatarScope];
305
+        if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
306
+            $data[AccountManager::PROPERTY_DISPLAYNAME] = ['value' => $displayname, 'scope' => $displaynameScope];
307
+            $data[AccountManager::PROPERTY_EMAIL] = ['value' => $email, 'scope' => $emailScope];
308
+        }
309
+        if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
310
+            $federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application();
311
+            $shareProvider = $federatedFileSharing->getFederatedShareProvider();
312
+            if ($shareProvider->isLookupServerUploadEnabled()) {
313
+                $data[AccountManager::PROPERTY_WEBSITE] = ['value' => $website, 'scope' => $websiteScope];
314
+                $data[AccountManager::PROPERTY_ADDRESS] = ['value' => $address, 'scope' => $addressScope];
315
+                $data[AccountManager::PROPERTY_PHONE] = ['value' => $phone, 'scope' => $phoneScope];
316
+                $data[AccountManager::PROPERTY_TWITTER] = ['value' => $twitter, 'scope' => $twitterScope];
317
+            }
318
+        }
319
+        try {
320
+            $this->saveUserSettings($user, $data);
321
+            return new DataResponse(
322
+                [
323
+                    'status' => 'success',
324
+                    'data' => [
325
+                        'userId' => $user->getUID(),
326
+                        'avatarScope' => $data[AccountManager::PROPERTY_AVATAR]['scope'],
327
+                        'displayname' => $data[AccountManager::PROPERTY_DISPLAYNAME]['value'],
328
+                        'displaynameScope' => $data[AccountManager::PROPERTY_DISPLAYNAME]['scope'],
329
+                        'email' => $data[AccountManager::PROPERTY_EMAIL]['value'],
330
+                        'emailScope' => $data[AccountManager::PROPERTY_EMAIL]['scope'],
331
+                        'website' => $data[AccountManager::PROPERTY_WEBSITE]['value'],
332
+                        'websiteScope' => $data[AccountManager::PROPERTY_WEBSITE]['scope'],
333
+                        'address' => $data[AccountManager::PROPERTY_ADDRESS]['value'],
334
+                        'addressScope' => $data[AccountManager::PROPERTY_ADDRESS]['scope'],
335
+                        'message' => $this->l10n->t('Settings saved')
336
+                    ]
337
+                ],
338
+                Http::STATUS_OK
339
+            );
340
+        } catch (ForbiddenException $e) {
341
+            return new DataResponse([
342
+                'status' => 'error',
343
+                'data' => [
344
+                    'message' => $e->getMessage()
345
+                ],
346
+            ]);
347
+        }
348
+    }
349
+    /**
350
+     * update account manager with new user data
351
+     *
352
+     * @param IUser $user
353
+     * @param array $data
354
+     * @throws ForbiddenException
355
+     */
356
+    protected function saveUserSettings(IUser $user, array $data) {
357
+        // keep the user back-end up-to-date with the latest display name and email
358
+        // address
359
+        $oldDisplayName = $user->getDisplayName();
360
+        $oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName;
361
+        if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value'])
362
+            && $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value']
363
+        ) {
364
+            $result = $user->setDisplayName($data[AccountManager::PROPERTY_DISPLAYNAME]['value']);
365
+            if ($result === false) {
366
+                throw new ForbiddenException($this->l10n->t('Unable to change full name'));
367
+            }
368
+        }
369
+        $oldEmailAddress = $user->getEMailAddress();
370
+        $oldEmailAddress = is_null($oldEmailAddress) ? '' : $oldEmailAddress;
371
+        if (isset($data[AccountManager::PROPERTY_EMAIL]['value'])
372
+            && $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value']
373
+        ) {
374
+            // this is the only permission a backend provides and is also used
375
+            // for the permission of setting a email address
376
+            if (!$user->canChangeDisplayName()) {
377
+                throw new ForbiddenException($this->l10n->t('Unable to change email address'));
378
+            }
379
+            $user->setEMailAddress($data[AccountManager::PROPERTY_EMAIL]['value']);
380
+        }
381
+        $this->accountManager->updateUser($user, $data);
382
+    }
383 383
 
384
-	/**
385
-	 * Set the mail address of a user
386
-	 *
387
-	 * @NoAdminRequired
388
-	 * @NoSubadminRequired
389
-	 * @PasswordConfirmationRequired
390
-	 *
391
-	 * @param string $account
392
-	 * @param bool $onlyVerificationCode only return verification code without updating the data
393
-	 * @return DataResponse
394
-	 */
395
-	public function getVerificationCode(string $account, bool $onlyVerificationCode): DataResponse {
384
+    /**
385
+     * Set the mail address of a user
386
+     *
387
+     * @NoAdminRequired
388
+     * @NoSubadminRequired
389
+     * @PasswordConfirmationRequired
390
+     *
391
+     * @param string $account
392
+     * @param bool $onlyVerificationCode only return verification code without updating the data
393
+     * @return DataResponse
394
+     */
395
+    public function getVerificationCode(string $account, bool $onlyVerificationCode): DataResponse {
396 396
 
397
-		$user = $this->userSession->getUser();
397
+        $user = $this->userSession->getUser();
398 398
 
399
-		if ($user === null) {
400
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
401
-		}
399
+        if ($user === null) {
400
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
401
+        }
402 402
 
403
-		$accountData = $this->accountManager->getUser($user);
404
-		$cloudId = $user->getCloudId();
405
-		$message = 'Use my Federated Cloud ID to share with me: ' . $cloudId;
406
-		$signature = $this->signMessage($user, $message);
403
+        $accountData = $this->accountManager->getUser($user);
404
+        $cloudId = $user->getCloudId();
405
+        $message = 'Use my Federated Cloud ID to share with me: ' . $cloudId;
406
+        $signature = $this->signMessage($user, $message);
407 407
 
408
-		$code = $message . ' ' . $signature;
409
-		$codeMd5 = $message . ' ' . md5($signature);
408
+        $code = $message . ' ' . $signature;
409
+        $codeMd5 = $message . ' ' . md5($signature);
410 410
 
411
-		switch ($account) {
412
-			case 'verify-twitter':
413
-				$accountData[AccountManager::PROPERTY_TWITTER]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
414
-				$msg = $this->l10n->t('In order to verify your Twitter account, post the following tweet on Twitter (please make sure to post it without any line breaks):');
415
-				$code = $codeMd5;
416
-				$type = AccountManager::PROPERTY_TWITTER;
417
-				$data = $accountData[AccountManager::PROPERTY_TWITTER]['value'];
418
-				$accountData[AccountManager::PROPERTY_TWITTER]['signature'] = $signature;
419
-				break;
420
-			case 'verify-website':
421
-				$accountData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
422
-				$msg = $this->l10n->t('In order to verify your Website, store the following content in your web-root at \'.well-known/CloudIdVerificationCode.txt\' (please make sure that the complete text is in one line):');
423
-				$type = AccountManager::PROPERTY_WEBSITE;
424
-				$data = $accountData[AccountManager::PROPERTY_WEBSITE]['value'];
425
-				$accountData[AccountManager::PROPERTY_WEBSITE]['signature'] = $signature;
426
-				break;
427
-			default:
428
-				return new DataResponse([], Http::STATUS_BAD_REQUEST);
429
-		}
411
+        switch ($account) {
412
+            case 'verify-twitter':
413
+                $accountData[AccountManager::PROPERTY_TWITTER]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
414
+                $msg = $this->l10n->t('In order to verify your Twitter account, post the following tweet on Twitter (please make sure to post it without any line breaks):');
415
+                $code = $codeMd5;
416
+                $type = AccountManager::PROPERTY_TWITTER;
417
+                $data = $accountData[AccountManager::PROPERTY_TWITTER]['value'];
418
+                $accountData[AccountManager::PROPERTY_TWITTER]['signature'] = $signature;
419
+                break;
420
+            case 'verify-website':
421
+                $accountData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
422
+                $msg = $this->l10n->t('In order to verify your Website, store the following content in your web-root at \'.well-known/CloudIdVerificationCode.txt\' (please make sure that the complete text is in one line):');
423
+                $type = AccountManager::PROPERTY_WEBSITE;
424
+                $data = $accountData[AccountManager::PROPERTY_WEBSITE]['value'];
425
+                $accountData[AccountManager::PROPERTY_WEBSITE]['signature'] = $signature;
426
+                break;
427
+            default:
428
+                return new DataResponse([], Http::STATUS_BAD_REQUEST);
429
+        }
430 430
 
431
-		if ($onlyVerificationCode === false) {
432
-			$this->accountManager->updateUser($user, $accountData);
431
+        if ($onlyVerificationCode === false) {
432
+            $this->accountManager->updateUser($user, $accountData);
433 433
 
434
-			$this->jobList->add(VerifyUserData::class,
435
-				[
436
-					'verificationCode' => $code,
437
-					'data' => $data,
438
-					'type' => $type,
439
-					'uid' => $user->getUID(),
440
-					'try' => 0,
441
-					'lastRun' => $this->getCurrentTime()
442
-				]
443
-			);
444
-		}
434
+            $this->jobList->add(VerifyUserData::class,
435
+                [
436
+                    'verificationCode' => $code,
437
+                    'data' => $data,
438
+                    'type' => $type,
439
+                    'uid' => $user->getUID(),
440
+                    'try' => 0,
441
+                    'lastRun' => $this->getCurrentTime()
442
+                ]
443
+            );
444
+        }
445 445
 
446
-		return new DataResponse(['msg' => $msg, 'code' => $code]);
447
-	}
446
+        return new DataResponse(['msg' => $msg, 'code' => $code]);
447
+    }
448 448
 
449
-	/**
450
-	 * get current timestamp
451
-	 *
452
-	 * @return int
453
-	 */
454
-	protected function getCurrentTime(): int {
455
-		return time();
456
-	}
449
+    /**
450
+     * get current timestamp
451
+     *
452
+     * @return int
453
+     */
454
+    protected function getCurrentTime(): int {
455
+        return time();
456
+    }
457 457
 
458
-	/**
459
-	 * sign message with users private key
460
-	 *
461
-	 * @param IUser $user
462
-	 * @param string $message
463
-	 *
464
-	 * @return string base64 encoded signature
465
-	 */
466
-	protected function signMessage(IUser $user, string $message): string {
467
-		$privateKey = $this->keyManager->getKey($user)->getPrivate();
468
-		openssl_sign(json_encode($message), $signature, $privateKey, OPENSSL_ALGO_SHA512);
469
-		return base64_encode($signature);
470
-	}
458
+    /**
459
+     * sign message with users private key
460
+     *
461
+     * @param IUser $user
462
+     * @param string $message
463
+     *
464
+     * @return string base64 encoded signature
465
+     */
466
+    protected function signMessage(IUser $user, string $message): string {
467
+        $privateKey = $this->keyManager->getKey($user)->getPrivate();
468
+        openssl_sign(json_encode($message), $signature, $privateKey, OPENSSL_ALGO_SHA512);
469
+        return base64_encode($signature);
470
+    }
471 471
 }
Please login to merge, or discard this patch.