Passed
Push — master ( a4d81b...790ee0 )
by Morris
12:41
created
apps/encryption/templates/settings-admin.php 2 patches
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,10 +9,13 @@  discard block
 block discarded – undo
9 9
 	<h3><?php p($l->t("Default encryption module")); ?></h3>
10 10
 	<?php if(!$_["initStatus"] && $_['masterKeyEnabled'] === false): ?>
11 11
 		<?php p($l->t("Encryption app is enabled but your keys are not initialized, please log-out and log-in again")); ?>
12
-	<?php else: ?>
12
+	<?php else {
13
+    : ?>
13 14
 		<p id="encryptHomeStorageSetting">
14 15
 			<input type="checkbox" class="checkbox" name="encrypt_home_storage" id="encryptHomeStorage"
15
-				   value="1" <?php if ($_['encryptHomeStorage']) print_unescaped('checked="checked"'); ?> />
16
+				   value="1" <?php if ($_['encryptHomeStorage']) print_unescaped('checked="checked"');
17
+}
18
+?> />
16 19
 			<label for="encryptHomeStorage"><?php p($l->t('Encrypt the home storage'));?></label></br>
17 20
 			<em><?php p( $l->t( "Enabling this option encrypts all files stored on the main storage, otherwise only files on external storage will be encrypted" ) ); ?></em>
18 21
 		</p>
@@ -42,7 +45,10 @@  discard block
 block discarded – undo
42 45
 			</p>
43 46
 			<br/><br/>
44 47
 
45
-			<p name="changeRecoveryPasswordBlock" id="encryptionChangeRecoveryKey" <?php if($_['recoveryEnabled'] === '0') print_unescaped('class="hidden"');?>>
48
+			<p name="changeRecoveryPasswordBlock" id="encryptionChangeRecoveryKey" <?php if($_['recoveryEnabled'] === '0') {
49
+    print_unescaped('class="hidden"');
50
+}
51
+?>>
46 52
 				<?php p($l->t("Change recovery key password:")); ?>
47 53
 				<span class="msg"></span>
48 54
 				<br/>
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -7,17 +7,17 @@  discard block
 block discarded – undo
7 7
 ?>
8 8
 <form id="ocDefaultEncryptionModule" class="sub-section">
9 9
 	<h3><?php p($l->t("Default encryption module")); ?></h3>
10
-	<?php if(!$_["initStatus"] && $_['masterKeyEnabled'] === false): ?>
10
+	<?php if (!$_["initStatus"] && $_['masterKeyEnabled'] === false): ?>
11 11
 		<?php p($l->t("Encryption app is enabled but your keys are not initialized, please log-out and log-in again")); ?>
12 12
 	<?php else: ?>
13 13
 		<p id="encryptHomeStorageSetting">
14 14
 			<input type="checkbox" class="checkbox" name="encrypt_home_storage" id="encryptHomeStorage"
15 15
 				   value="1" <?php if ($_['encryptHomeStorage']) print_unescaped('checked="checked"'); ?> />
16
-			<label for="encryptHomeStorage"><?php p($l->t('Encrypt the home storage'));?></label></br>
17
-			<em><?php p( $l->t( "Enabling this option encrypts all files stored on the main storage, otherwise only files on external storage will be encrypted" ) ); ?></em>
16
+			<label for="encryptHomeStorage"><?php p($l->t('Encrypt the home storage')); ?></label></br>
17
+			<em><?php p($l->t("Enabling this option encrypts all files stored on the main storage, otherwise only files on external storage will be encrypted")); ?></em>
18 18
 		</p>
19 19
 		<br />
20
-		<?php if($_['masterKeyEnabled'] === false): ?>
20
+		<?php if ($_['masterKeyEnabled'] === false): ?>
21 21
 			<p id="encryptionSetRecoveryKey">
22 22
 				<?php $_["recoveryEnabled"] === '0' ?  p($l->t("Enable recovery key")) : p($l->t("Disable recovery key")); ?>
23 23
 				<span class="msg"></span>
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 			</p>
43 43
 			<br/><br/>
44 44
 
45
-			<p name="changeRecoveryPasswordBlock" id="encryptionChangeRecoveryKey" <?php if($_['recoveryEnabled'] === '0') print_unescaped('class="hidden"');?>>
45
+			<p name="changeRecoveryPasswordBlock" id="encryptionChangeRecoveryKey" <?php if ($_['recoveryEnabled'] === '0') print_unescaped('class="hidden"'); ?>>
46 46
 				<?php p($l->t("Change recovery key password:")); ?>
47 47
 				<span class="msg"></span>
48 48
 				<br/>
Please login to merge, or discard this patch.
apps/encryption/lib/Migration/SetMasterKeyStatus.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -35,43 +35,43 @@
 block discarded – undo
35 35
 class SetMasterKeyStatus implements IRepairStep {
36 36
 
37 37
 
38
-	/** @var  IConfig */
39
-	private $config;
38
+    /** @var  IConfig */
39
+    private $config;
40 40
 
41 41
 
42
-	public function __construct(IConfig $config) {
43
-		$this->config = $config;
44
-	}
42
+    public function __construct(IConfig $config) {
43
+        $this->config = $config;
44
+    }
45 45
 
46
-	/**
47
-	 * Returns the step's name
48
-	 *
49
-	 * @return string
50
-	 * @since 9.1.0
51
-	 */
52
-	public function getName() {
53
-		return 'Write default encryption module configuration to the database';
54
-	}
46
+    /**
47
+     * Returns the step's name
48
+     *
49
+     * @return string
50
+     * @since 9.1.0
51
+     */
52
+    public function getName() {
53
+        return 'Write default encryption module configuration to the database';
54
+    }
55 55
 
56
-	/**
57
-	 * @param IOutput $output
58
-	 */
59
-	public function run(IOutput $output) {
60
-		if (!$this->shouldRun()) {
61
-			return;
62
-		}
56
+    /**
57
+     * @param IOutput $output
58
+     */
59
+    public function run(IOutput $output) {
60
+        if (!$this->shouldRun()) {
61
+            return;
62
+        }
63 63
 
64
-		// if no config for the master key is set we set it explicitly to '0' in
65
-		// order not to break old installations because the default changed to '1'.
66
-		$configAlreadySet = $this->config->getAppValue('encryption', 'useMasterKey', false);
67
-		if ($configAlreadySet === false) {
68
-			$this->config->setAppValue('encryption', 'useMasterKey', '0');
69
-		}
70
-	}
64
+        // if no config for the master key is set we set it explicitly to '0' in
65
+        // order not to break old installations because the default changed to '1'.
66
+        $configAlreadySet = $this->config->getAppValue('encryption', 'useMasterKey', false);
67
+        if ($configAlreadySet === false) {
68
+            $this->config->setAppValue('encryption', 'useMasterKey', '0');
69
+        }
70
+    }
71 71
 
72
-	protected function shouldRun() {
73
-		$appVersion = $this->config->getAppValue('encryption', 'installed_version', '0.0.0');
74
-		return version_compare($appVersion, '2.0.0', '<');
75
-	}
72
+    protected function shouldRun() {
73
+        $appVersion = $this->config->getAppValue('encryption', 'installed_version', '0.0.0');
74
+        return version_compare($appVersion, '2.0.0', '<');
75
+    }
76 76
 
77 77
 }
Please login to merge, or discard this patch.
apps/encryption/lib/Command/DisableMasterKey.php 2 patches
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -33,57 +33,57 @@
 block discarded – undo
33 33
 
34 34
 class DisableMasterKey extends Command {
35 35
 
36
-	/** @var Util */
37
-	protected $util;
38
-
39
-	/** @var IConfig */
40
-	protected $config;
41
-
42
-	/** @var  QuestionHelper */
43
-	protected $questionHelper;
44
-
45
-	/**
46
-	 * @param Util $util
47
-	 * @param IConfig $config
48
-	 * @param QuestionHelper $questionHelper
49
-	 */
50
-	public function __construct(Util $util,
51
-								IConfig $config,
52
-								QuestionHelper $questionHelper) {
53
-
54
-		$this->util = $util;
55
-		$this->config = $config;
56
-		$this->questionHelper = $questionHelper;
57
-		parent::__construct();
58
-	}
59
-
60
-	protected function configure() {
61
-		$this
62
-			->setName('encryption:disable-master-key')
63
-			->setDescription('Disable the master key and use per-user keys instead. Only available for fresh installations with no existing encrypted data! There is no way to enable it again.');
64
-	}
65
-
66
-	protected function execute(InputInterface $input, OutputInterface $output) {
67
-
68
-		$isMasterKeyEnabled = $this->util->isMasterKeyEnabled();
69
-
70
-		if(!$isMasterKeyEnabled) {
71
-			$output->writeln('Master key already disabled');
72
-		} else {
73
-			$question = new ConfirmationQuestion(
74
-				'Warning: Only perform this operation for a fresh installations with no existing encrypted data! '
75
-				. 'There is no way to enable the master key again. '
76
-				. 'We strongly recommend to keep the master key, it provides significant performance improvements '
77
-				. 'and is easier to handle for both, users and administrators. '
78
-				. 'Do you really want to switch to per-user keys? (y/n) ', false);
79
-			if ($this->questionHelper->ask($input, $output, $question)) {
80
-				$this->config->setAppValue('encryption', 'useMasterKey', '0');
81
-				$output->writeln('Master key successfully disabled.');
82
-			} else {
83
-				$output->writeln('aborted.');
84
-			}
85
-		}
86
-
87
-	}
36
+    /** @var Util */
37
+    protected $util;
38
+
39
+    /** @var IConfig */
40
+    protected $config;
41
+
42
+    /** @var  QuestionHelper */
43
+    protected $questionHelper;
44
+
45
+    /**
46
+     * @param Util $util
47
+     * @param IConfig $config
48
+     * @param QuestionHelper $questionHelper
49
+     */
50
+    public function __construct(Util $util,
51
+                                IConfig $config,
52
+                                QuestionHelper $questionHelper) {
53
+
54
+        $this->util = $util;
55
+        $this->config = $config;
56
+        $this->questionHelper = $questionHelper;
57
+        parent::__construct();
58
+    }
59
+
60
+    protected function configure() {
61
+        $this
62
+            ->setName('encryption:disable-master-key')
63
+            ->setDescription('Disable the master key and use per-user keys instead. Only available for fresh installations with no existing encrypted data! There is no way to enable it again.');
64
+    }
65
+
66
+    protected function execute(InputInterface $input, OutputInterface $output) {
67
+
68
+        $isMasterKeyEnabled = $this->util->isMasterKeyEnabled();
69
+
70
+        if(!$isMasterKeyEnabled) {
71
+            $output->writeln('Master key already disabled');
72
+        } else {
73
+            $question = new ConfirmationQuestion(
74
+                'Warning: Only perform this operation for a fresh installations with no existing encrypted data! '
75
+                . 'There is no way to enable the master key again. '
76
+                . 'We strongly recommend to keep the master key, it provides significant performance improvements '
77
+                . 'and is easier to handle for both, users and administrators. '
78
+                . 'Do you really want to switch to per-user keys? (y/n) ', false);
79
+            if ($this->questionHelper->ask($input, $output, $question)) {
80
+                $this->config->setAppValue('encryption', 'useMasterKey', '0');
81
+                $output->writeln('Master key successfully disabled.');
82
+            } else {
83
+                $output->writeln('aborted.');
84
+            }
85
+        }
86
+
87
+    }
88 88
 
89 89
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@
 block discarded – undo
67 67
 
68 68
 		$isMasterKeyEnabled = $this->util->isMasterKeyEnabled();
69 69
 
70
-		if(!$isMasterKeyEnabled) {
70
+		if (!$isMasterKeyEnabled) {
71 71
 			$output->writeln('Master key already disabled');
72 72
 		} else {
73 73
 			$question = new ConfirmationQuestion(
Please login to merge, or discard this patch.
settings/Controller/PersonalSettingsController.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	protected function getSettings($section) {
68 68
 		$settings = $this->settingsManager->getPersonalSettings($section);
69 69
 		$formatted = $this->formatSettings($settings);
70
-		if($section === 'additional') {
70
+		if ($section === 'additional') {
71 71
 			$formatted['content'] .= $this->getLegacyForms();
72 72
 		}
73 73
 		return $formatted;
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
 	private function getLegacyForms() {
80 80
 		$forms = \OC_App::getForms('personal');
81 81
 
82
-		$forms = array_map(function ($form) {
82
+		$forms = array_map(function($form) {
83 83
 			if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
84
-				$sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
84
+				$sectionName = str_replace('<h2'.$regs['class'].'>', '', $regs[0]);
85 85
 				$sectionName = str_replace('</h2>', '', $sectionName);
86 86
 				$anchor = strtolower($sectionName);
87 87
 				$anchor = str_replace(' ', '-', $anchor);
Please login to merge, or discard this patch.
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -32,72 +32,72 @@
 block discarded – undo
32 32
 use OCP\Template;
33 33
 
34 34
 class PersonalSettingsController extends Controller {
35
-	use CommonSettingsTrait;
35
+    use CommonSettingsTrait;
36 36
 
37
-	public function __construct(
38
-		$appName,
39
-		IRequest $request,
40
-		INavigationManager $navigationManager,
41
-		ISettingsManager $settingsManager
42
-	) {
43
-		parent::__construct($appName, $request);
44
-		$this->navigationManager = $navigationManager;
45
-		$this->settingsManager = $settingsManager;
46
-	}
37
+    public function __construct(
38
+        $appName,
39
+        IRequest $request,
40
+        INavigationManager $navigationManager,
41
+        ISettingsManager $settingsManager
42
+    ) {
43
+        parent::__construct($appName, $request);
44
+        $this->navigationManager = $navigationManager;
45
+        $this->settingsManager = $settingsManager;
46
+    }
47 47
 
48
-	/**
49
-	 * @param string $section
50
-	 * @return TemplateResponse
51
-	 *
52
-	 * @NoCSRFRequired
53
-	 * @NoAdminRequired
54
-	 * @NoSubadminRequired
55
-	 */
56
-	public function index($section) {
57
-		return $this->getIndexResponse('personal', $section);
48
+    /**
49
+     * @param string $section
50
+     * @return TemplateResponse
51
+     *
52
+     * @NoCSRFRequired
53
+     * @NoAdminRequired
54
+     * @NoSubadminRequired
55
+     */
56
+    public function index($section) {
57
+        return $this->getIndexResponse('personal', $section);
58 58
 
59
-	}
59
+    }
60 60
 
61
-	/**
62
-	 * @param string $section
63
-	 * @return array
64
-	 */
65
-	protected function getSettings($section) {
66
-		$settings = $this->settingsManager->getPersonalSettings($section);
67
-		$formatted = $this->formatSettings($settings);
68
-		if($section === 'additional') {
69
-			$formatted['content'] .= $this->getLegacyForms();
70
-		}
71
-		return $formatted;
72
-	}
61
+    /**
62
+     * @param string $section
63
+     * @return array
64
+     */
65
+    protected function getSettings($section) {
66
+        $settings = $this->settingsManager->getPersonalSettings($section);
67
+        $formatted = $this->formatSettings($settings);
68
+        if($section === 'additional') {
69
+            $formatted['content'] .= $this->getLegacyForms();
70
+        }
71
+        return $formatted;
72
+    }
73 73
 
74
-	/**
75
-	 * @return bool|string
76
-	 */
77
-	private function getLegacyForms() {
78
-		$forms = \OC_App::getForms('personal');
74
+    /**
75
+     * @return bool|string
76
+     */
77
+    private function getLegacyForms() {
78
+        $forms = \OC_App::getForms('personal');
79 79
 
80
-		$forms = array_map(function ($form) {
81
-			if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
82
-				$sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
83
-				$sectionName = str_replace('</h2>', '', $sectionName);
84
-				$anchor = strtolower($sectionName);
85
-				$anchor = str_replace(' ', '-', $anchor);
80
+        $forms = array_map(function ($form) {
81
+            if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
82
+                $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
83
+                $sectionName = str_replace('</h2>', '', $sectionName);
84
+                $anchor = strtolower($sectionName);
85
+                $anchor = str_replace(' ', '-', $anchor);
86 86
 
87
-				return array(
88
-					'anchor' => $anchor,
89
-					'section-name' => $sectionName,
90
-					'form' => $form
91
-				);
92
-			}
93
-			return array(
94
-				'form' => $form
95
-			);
96
-		}, $forms);
87
+                return array(
88
+                    'anchor' => $anchor,
89
+                    'section-name' => $sectionName,
90
+                    'form' => $form
91
+                );
92
+            }
93
+            return array(
94
+                'form' => $form
95
+            );
96
+        }, $forms);
97 97
 
98
-		$out = new Template('settings', 'settings/additional');
99
-		$out->assign('forms', $forms);
98
+        $out = new Template('settings', 'settings/additional');
99
+        $out->assign('forms', $forms);
100 100
 
101
-		return $out->fetchPage();
102
-	}
101
+        return $out->fetchPage();
102
+    }
103 103
 }
Please login to merge, or discard this patch.
settings/Controller/AdminSettingsController.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	protected function getSettings($section) {
78 78
 		$settings = $this->settingsManager->getAdminSettings($section);
79 79
 		$formatted = $this->formatSettings($settings);
80
-		if($section === 'additional') {
80
+		if ($section === 'additional') {
81 81
 			$formatted['content'] .= $this->getLegacyForms();
82 82
 		}
83 83
 		return $formatted;
@@ -89,9 +89,9 @@  discard block
 block discarded – undo
89 89
 	private function getLegacyForms() {
90 90
 		$forms = \OC_App::getForms('admin');
91 91
 
92
-		$forms = array_map(function ($form) {
92
+		$forms = array_map(function($form) {
93 93
 			if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
94
-				$sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
94
+				$sectionName = str_replace('<h2'.$regs['class'].'>', '', $regs[0]);
95 95
 				$sectionName = str_replace('</h2>', '', $sectionName);
96 96
 				$anchor = strtolower($sectionName);
97 97
 				$anchor = str_replace(' ', '-', $anchor);
Please login to merge, or discard this patch.
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -36,77 +36,77 @@
 block discarded – undo
36 36
  * @package OC\Settings\Controller
37 37
  */
38 38
 class AdminSettingsController extends Controller {
39
-	use CommonSettingsTrait;
39
+    use CommonSettingsTrait;
40 40
 
41
-	/**
42
-	 * @param string $appName
43
-	 * @param IRequest $request
44
-	 * @param INavigationManager $navigationManager
45
-	 * @param ISettingsManager $settingsManager
46
-	 */
47
-	public function __construct(
48
-		$appName,
49
-		IRequest $request,
50
-		INavigationManager $navigationManager,
51
-		ISettingsManager $settingsManager
52
-	) {
53
-		parent::__construct($appName, $request);
54
-		$this->navigationManager = $navigationManager;
55
-		$this->settingsManager = $settingsManager;
56
-	}
41
+    /**
42
+     * @param string $appName
43
+     * @param IRequest $request
44
+     * @param INavigationManager $navigationManager
45
+     * @param ISettingsManager $settingsManager
46
+     */
47
+    public function __construct(
48
+        $appName,
49
+        IRequest $request,
50
+        INavigationManager $navigationManager,
51
+        ISettingsManager $settingsManager
52
+    ) {
53
+        parent::__construct($appName, $request);
54
+        $this->navigationManager = $navigationManager;
55
+        $this->settingsManager = $settingsManager;
56
+    }
57 57
 
58
-	/**
59
-	 * @param string $section
60
-	 * @return TemplateResponse
61
-	 *
62
-	 * @NoCSRFRequired
63
-	 */
64
-	public function index($section) {
65
-		return $this->getIndexResponse('admin', $section);
66
-	}
58
+    /**
59
+     * @param string $section
60
+     * @return TemplateResponse
61
+     *
62
+     * @NoCSRFRequired
63
+     */
64
+    public function index($section) {
65
+        return $this->getIndexResponse('admin', $section);
66
+    }
67 67
 
68
-	/**
69
-	 * @param string $section
70
-	 * @return array
71
-	 */
72
-	protected function getSettings($section) {
73
-		$settings = $this->settingsManager->getAdminSettings($section);
74
-		$formatted = $this->formatSettings($settings);
75
-		if($section === 'additional') {
76
-			$formatted['content'] .= $this->getLegacyForms();
77
-		}
78
-		return $formatted;
79
-	}
68
+    /**
69
+     * @param string $section
70
+     * @return array
71
+     */
72
+    protected function getSettings($section) {
73
+        $settings = $this->settingsManager->getAdminSettings($section);
74
+        $formatted = $this->formatSettings($settings);
75
+        if($section === 'additional') {
76
+            $formatted['content'] .= $this->getLegacyForms();
77
+        }
78
+        return $formatted;
79
+    }
80 80
 
81
-	/**
82
-	 * @return bool|string
83
-	 */
84
-	private function getLegacyForms() {
85
-		$forms = \OC_App::getForms('admin');
81
+    /**
82
+     * @return bool|string
83
+     */
84
+    private function getLegacyForms() {
85
+        $forms = \OC_App::getForms('admin');
86 86
 
87
-		$forms = array_map(function ($form) {
88
-			if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
89
-				$sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
90
-				$sectionName = str_replace('</h2>', '', $sectionName);
91
-				$anchor = strtolower($sectionName);
92
-				$anchor = str_replace(' ', '-', $anchor);
87
+        $forms = array_map(function ($form) {
88
+            if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
89
+                $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
90
+                $sectionName = str_replace('</h2>', '', $sectionName);
91
+                $anchor = strtolower($sectionName);
92
+                $anchor = str_replace(' ', '-', $anchor);
93 93
 
94
-				return array(
95
-					'anchor' => $anchor,
96
-					'section-name' => $sectionName,
97
-					'form' => $form
98
-				);
99
-			}
100
-			return array(
101
-				'form' => $form
102
-			);
103
-		}, $forms);
94
+                return array(
95
+                    'anchor' => $anchor,
96
+                    'section-name' => $sectionName,
97
+                    'form' => $form
98
+                );
99
+            }
100
+            return array(
101
+                'form' => $form
102
+            );
103
+        }, $forms);
104 104
 
105
-		$out = new Template('settings', 'settings/additional');
106
-		$out->assign('forms', $forms);
105
+        $out = new Template('settings', 'settings/additional');
106
+        $out->assign('forms', $forms);
107 107
 
108
-		return $out->fetchPage();
109
-	}
108
+        return $out->fetchPage();
109
+    }
110 110
 
111 111
 
112 112
 }
Please login to merge, or discard this patch.
lib/private/User/User.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 		$this->uid = $uid;
85 85
 		$this->backend = $backend;
86 86
 		$this->emitter = $emitter;
87
-		if(is_null($config)) {
87
+		if (is_null($config)) {
88 88
 			$config = \OC::$server->getConfig();
89 89
 		}
90 90
 		$this->config = $config;
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
 	 */
161 161
 	public function setEMailAddress($mailAddress) {
162 162
 		$oldMailAddress = $this->getEMailAddress();
163
-		if($mailAddress === '') {
163
+		if ($mailAddress === '') {
164 164
 			$this->config->deleteUserValue($this->uid, 'settings', 'email');
165 165
 		} else {
166 166
 			$this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress);
167 167
 		}
168
-		if($oldMailAddress !== $mailAddress) {
168
+		if ($oldMailAddress !== $mailAddress) {
169 169
 			$this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress);
170 170
 		}
171 171
 	}
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 			}
230 230
 
231 231
 			// Delete the users entry in the storage table
232
-			Storage::remove('home::' . $this->uid);
232
+			Storage::remove('home::'.$this->uid);
233 233
 
234 234
 			\OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid);
235 235
 			\OC::$server->getCommentsManager()->deleteReadMarksFromUser($this);
@@ -281,9 +281,9 @@  discard block
 block discarded – undo
281 281
 			if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) {
282 282
 				$this->home = $home;
283 283
 			} elseif ($this->config) {
284
-				$this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid;
284
+				$this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/'.$this->uid;
285 285
 			} else {
286
-				$this->home = \OC::$SERVERROOT . '/data/' . $this->uid;
286
+				$this->home = \OC::$SERVERROOT.'/data/'.$this->uid;
287 287
 			}
288 288
 		}
289 289
 		return $this->home;
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 	 * @return string
296 296
 	 */
297 297
 	public function getBackendClassName() {
298
-		if($this->backend instanceof IUserBackend) {
298
+		if ($this->backend instanceof IUserBackend) {
299 299
 			return $this->backend->getBackendName();
300 300
 		}
301 301
 		return get_class($this->backend);
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
 	 */
377 377
 	public function getQuota() {
378 378
 		$quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default');
379
-		if($quota === 'default') {
379
+		if ($quota === 'default') {
380 380
 			$quota = $this->config->getAppValue('files', 'default_quota', 'none');
381 381
 		}
382 382
 		return $quota;
@@ -391,12 +391,12 @@  discard block
 block discarded – undo
391 391
 	 */
392 392
 	public function setQuota($quota) {
393 393
 		$oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', '');
394
-		if($quota !== 'none' and $quota !== 'default') {
394
+		if ($quota !== 'none' and $quota !== 'default') {
395 395
 			$quota = OC_Helper::computerFileSize($quota);
396 396
 			$quota = OC_Helper::humanFileSize($quota);
397 397
 		}
398 398
 		$this->config->setUserValue($this->uid, 'files', 'quota', $quota);
399
-		if($quota !== $oldQuota) {
399
+		if ($quota !== $oldQuota) {
400 400
 			$this->triggerChange('quota', $quota);
401 401
 		}
402 402
 	}
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 	public function getCloudId() {
433 433
 		$uid = $this->getUID();
434 434
 		$server = $this->urlGenerator->getAbsoluteURL('/');
435
-		$server =  rtrim( $this->removeProtocolFromUrl($server), '/');
435
+		$server = rtrim($this->removeProtocolFromUrl($server), '/');
436 436
 		return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId();
437 437
 	}
438 438
 
Please login to merge, or discard this patch.
Indentation   +415 added lines, -415 removed lines patch added patch discarded remove patch
@@ -44,419 +44,419 @@
 block discarded – undo
44 44
 use \OCP\IUserBackend;
45 45
 
46 46
 class User implements IUser {
47
-	/** @var string $uid */
48
-	private $uid;
49
-
50
-	/** @var string $displayName */
51
-	private $displayName;
52
-
53
-	/** @var UserInterface $backend */
54
-	private $backend;
55
-
56
-	/** @var bool $enabled */
57
-	private $enabled;
58
-
59
-	/** @var Emitter|Manager $emitter */
60
-	private $emitter;
61
-
62
-	/** @var string $home */
63
-	private $home;
64
-
65
-	/** @var int $lastLogin */
66
-	private $lastLogin;
67
-
68
-	/** @var \OCP\IConfig $config */
69
-	private $config;
70
-
71
-	/** @var IAvatarManager */
72
-	private $avatarManager;
73
-
74
-	/** @var IURLGenerator */
75
-	private $urlGenerator;
76
-
77
-	/**
78
-	 * @param string $uid
79
-	 * @param UserInterface $backend
80
-	 * @param \OC\Hooks\Emitter $emitter
81
-	 * @param IConfig|null $config
82
-	 * @param IURLGenerator $urlGenerator
83
-	 */
84
-	public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $urlGenerator = null) {
85
-		$this->uid = $uid;
86
-		$this->backend = $backend;
87
-		$this->emitter = $emitter;
88
-		if(is_null($config)) {
89
-			$config = \OC::$server->getConfig();
90
-		}
91
-		$this->config = $config;
92
-		$this->urlGenerator = $urlGenerator;
93
-		$enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true');
94
-		$this->enabled = ($enabled === 'true');
95
-		$this->lastLogin = $this->config->getUserValue($uid, 'login', 'lastLogin', 0);
96
-		if (is_null($this->urlGenerator)) {
97
-			$this->urlGenerator = \OC::$server->getURLGenerator();
98
-		}
99
-	}
100
-
101
-	/**
102
-	 * get the user id
103
-	 *
104
-	 * @return string
105
-	 */
106
-	public function getUID() {
107
-		return $this->uid;
108
-	}
109
-
110
-	/**
111
-	 * get the display name for the user, if no specific display name is set it will fallback to the user id
112
-	 *
113
-	 * @return string
114
-	 */
115
-	public function getDisplayName() {
116
-		if (!isset($this->displayName)) {
117
-			$displayName = '';
118
-			if ($this->backend and $this->backend->implementsActions(Backend::GET_DISPLAYNAME)) {
119
-				// get display name and strip whitespace from the beginning and end of it
120
-				$backendDisplayName = $this->backend->getDisplayName($this->uid);
121
-				if (is_string($backendDisplayName)) {
122
-					$displayName = trim($backendDisplayName);
123
-				}
124
-			}
125
-
126
-			if (!empty($displayName)) {
127
-				$this->displayName = $displayName;
128
-			} else {
129
-				$this->displayName = $this->uid;
130
-			}
131
-		}
132
-		return $this->displayName;
133
-	}
134
-
135
-	/**
136
-	 * set the displayname for the user
137
-	 *
138
-	 * @param string $displayName
139
-	 * @return bool
140
-	 */
141
-	public function setDisplayName($displayName) {
142
-		$displayName = trim($displayName);
143
-		if ($this->backend->implementsActions(Backend::SET_DISPLAYNAME) && !empty($displayName)) {
144
-			$result = $this->backend->setDisplayName($this->uid, $displayName);
145
-			if ($result) {
146
-				$this->displayName = $displayName;
147
-				$this->triggerChange('displayName', $displayName);
148
-			}
149
-			return $result !== false;
150
-		} else {
151
-			return false;
152
-		}
153
-	}
154
-
155
-	/**
156
-	 * set the email address of the user
157
-	 *
158
-	 * @param string|null $mailAddress
159
-	 * @return void
160
-	 * @since 9.0.0
161
-	 */
162
-	public function setEMailAddress($mailAddress) {
163
-		$oldMailAddress = $this->getEMailAddress();
164
-		if($mailAddress === '') {
165
-			$this->config->deleteUserValue($this->uid, 'settings', 'email');
166
-		} else {
167
-			$this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress);
168
-		}
169
-		if($oldMailAddress !== $mailAddress) {
170
-			$this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress);
171
-		}
172
-	}
173
-
174
-	/**
175
-	 * returns the timestamp of the user's last login or 0 if the user did never
176
-	 * login
177
-	 *
178
-	 * @return int
179
-	 */
180
-	public function getLastLogin() {
181
-		return $this->lastLogin;
182
-	}
183
-
184
-	/**
185
-	 * updates the timestamp of the most recent login of this user
186
-	 */
187
-	public function updateLastLoginTimestamp() {
188
-		$firstTimeLogin = ($this->lastLogin === 0);
189
-		$this->lastLogin = time();
190
-		$this->config->setUserValue(
191
-			$this->uid, 'login', 'lastLogin', $this->lastLogin);
192
-
193
-		return $firstTimeLogin;
194
-	}
195
-
196
-	/**
197
-	 * Delete the user
198
-	 *
199
-	 * @return bool
200
-	 */
201
-	public function delete() {
202
-		if ($this->emitter) {
203
-			$this->emitter->emit('\OC\User', 'preDelete', array($this));
204
-		}
205
-		// get the home now because it won't return it after user deletion
206
-		$homePath = $this->getHome();
207
-		$result = $this->backend->deleteUser($this->uid);
208
-		if ($result) {
209
-
210
-			// FIXME: Feels like an hack - suggestions?
211
-
212
-			$groupManager = \OC::$server->getGroupManager();
213
-			// We have to delete the user from all groups
214
-			foreach ($groupManager->getUserGroupIds($this) as $groupId) {
215
-				$group = $groupManager->get($groupId);
216
-				if ($group) {
217
-					\OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]);
218
-					$group->removeUser($this);
219
-					\OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]);
220
-				}
221
-			}
222
-			// Delete the user's keys in preferences
223
-			\OC::$server->getConfig()->deleteAllUserValues($this->uid);
224
-
225
-			// Delete user files in /data/
226
-			if ($homePath !== false) {
227
-				// FIXME: this operates directly on FS, should use View instead...
228
-				// also this is not testable/mockable...
229
-				\OC_Helper::rmdirr($homePath);
230
-			}
231
-
232
-			// Delete the users entry in the storage table
233
-			Storage::remove('home::' . $this->uid);
234
-
235
-			\OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid);
236
-			\OC::$server->getCommentsManager()->deleteReadMarksFromUser($this);
237
-
238
-			$notification = \OC::$server->getNotificationManager()->createNotification();
239
-			$notification->setUser($this->uid);
240
-			\OC::$server->getNotificationManager()->markProcessed($notification);
241
-
242
-			/** @var AccountManager $accountManager */
243
-			$accountManager = \OC::$server->query(AccountManager::class);
244
-			$accountManager->deleteUser($this);
245
-
246
-			if ($this->emitter) {
247
-				$this->emitter->emit('\OC\User', 'postDelete', array($this));
248
-			}
249
-		}
250
-		return !($result === false);
251
-	}
252
-
253
-	/**
254
-	 * Set the password of the user
255
-	 *
256
-	 * @param string $password
257
-	 * @param string $recoveryPassword for the encryption app to reset encryption keys
258
-	 * @return bool
259
-	 */
260
-	public function setPassword($password, $recoveryPassword = null) {
261
-		if ($this->emitter) {
262
-			$this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword));
263
-		}
264
-		if ($this->backend->implementsActions(Backend::SET_PASSWORD)) {
265
-			$result = $this->backend->setPassword($this->uid, $password);
266
-			if ($this->emitter) {
267
-				$this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword));
268
-			}
269
-			return !($result === false);
270
-		} else {
271
-			return false;
272
-		}
273
-	}
274
-
275
-	/**
276
-	 * get the users home folder to mount
277
-	 *
278
-	 * @return string
279
-	 */
280
-	public function getHome() {
281
-		if (!$this->home) {
282
-			if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) {
283
-				$this->home = $home;
284
-			} elseif ($this->config) {
285
-				$this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid;
286
-			} else {
287
-				$this->home = \OC::$SERVERROOT . '/data/' . $this->uid;
288
-			}
289
-		}
290
-		return $this->home;
291
-	}
292
-
293
-	/**
294
-	 * Get the name of the backend class the user is connected with
295
-	 *
296
-	 * @return string
297
-	 */
298
-	public function getBackendClassName() {
299
-		if($this->backend instanceof IUserBackend) {
300
-			return $this->backend->getBackendName();
301
-		}
302
-		return get_class($this->backend);
303
-	}
304
-
305
-	public function getBackend() {
306
-		return $this->backend;
307
-	}
308
-
309
-	/**
310
-	 * check if the backend allows the user to change his avatar on Personal page
311
-	 *
312
-	 * @return bool
313
-	 */
314
-	public function canChangeAvatar() {
315
-		if ($this->backend->implementsActions(Backend::PROVIDE_AVATAR)) {
316
-			return $this->backend->canChangeAvatar($this->uid);
317
-		}
318
-		return true;
319
-	}
320
-
321
-	/**
322
-	 * check if the backend supports changing passwords
323
-	 *
324
-	 * @return bool
325
-	 */
326
-	public function canChangePassword() {
327
-		return $this->backend->implementsActions(Backend::SET_PASSWORD);
328
-	}
329
-
330
-	/**
331
-	 * check if the backend supports changing display names
332
-	 *
333
-	 * @return bool
334
-	 */
335
-	public function canChangeDisplayName() {
336
-		if ($this->config->getSystemValue('allow_user_to_change_display_name') === false) {
337
-			return false;
338
-		}
339
-		return $this->backend->implementsActions(Backend::SET_DISPLAYNAME);
340
-	}
341
-
342
-	/**
343
-	 * check if the user is enabled
344
-	 *
345
-	 * @return bool
346
-	 */
347
-	public function isEnabled() {
348
-		return $this->enabled;
349
-	}
350
-
351
-	/**
352
-	 * set the enabled status for the user
353
-	 *
354
-	 * @param bool $enabled
355
-	 */
356
-	public function setEnabled(bool $enabled = true) {
357
-		$oldStatus = $this->isEnabled();
358
-		$this->enabled = $enabled;
359
-		if ($oldStatus !== $this->enabled) {
360
-			$this->triggerChange('enabled', $enabled);
361
-			$this->config->setUserValue($this->uid, 'core', 'enabled', $enabled ? 'true' : 'false');
362
-		}
363
-	}
364
-
365
-	/**
366
-	 * get the users email address
367
-	 *
368
-	 * @return string|null
369
-	 * @since 9.0.0
370
-	 */
371
-	public function getEMailAddress() {
372
-		return $this->config->getUserValue($this->uid, 'settings', 'email', null);
373
-	}
374
-
375
-	/**
376
-	 * get the users' quota
377
-	 *
378
-	 * @return string
379
-	 * @since 9.0.0
380
-	 */
381
-	public function getQuota() {
382
-		$quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default');
383
-		if($quota === 'default') {
384
-			$quota = $this->config->getAppValue('files', 'default_quota', 'none');
385
-		}
386
-		return $quota;
387
-	}
388
-
389
-	/**
390
-	 * set the users' quota
391
-	 *
392
-	 * @param string $quota
393
-	 * @return void
394
-	 * @since 9.0.0
395
-	 */
396
-	public function setQuota($quota) {
397
-		$oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', '');
398
-		if($quota !== 'none' and $quota !== 'default') {
399
-			$quota = OC_Helper::computerFileSize($quota);
400
-			$quota = OC_Helper::humanFileSize($quota);
401
-		}
402
-		$this->config->setUserValue($this->uid, 'files', 'quota', $quota);
403
-		if($quota !== $oldQuota) {
404
-			$this->triggerChange('quota', $quota);
405
-		}
406
-	}
407
-
408
-	/**
409
-	 * get the avatar image if it exists
410
-	 *
411
-	 * @param int $size
412
-	 * @return IImage|null
413
-	 * @since 9.0.0
414
-	 */
415
-	public function getAvatarImage($size) {
416
-		// delay the initialization
417
-		if (is_null($this->avatarManager)) {
418
-			$this->avatarManager = \OC::$server->getAvatarManager();
419
-		}
420
-
421
-		$avatar = $this->avatarManager->getAvatar($this->uid);
422
-		$image = $avatar->get(-1);
423
-		if ($image) {
424
-			return $image;
425
-		}
426
-
427
-		return null;
428
-	}
429
-
430
-	/**
431
-	 * get the federation cloud id
432
-	 *
433
-	 * @return string
434
-	 * @since 9.0.0
435
-	 */
436
-	public function getCloudId() {
437
-		$uid = $this->getUID();
438
-		$server = $this->urlGenerator->getAbsoluteURL('/');
439
-		$server =  rtrim( $this->removeProtocolFromUrl($server), '/');
440
-		return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId();
441
-	}
442
-
443
-	/**
444
-	 * @param string $url
445
-	 * @return string
446
-	 */
447
-	private function removeProtocolFromUrl($url) {
448
-		if (strpos($url, 'https://') === 0) {
449
-			return substr($url, strlen('https://'));
450
-		} else if (strpos($url, 'http://') === 0) {
451
-			return substr($url, strlen('http://'));
452
-		}
453
-
454
-		return $url;
455
-	}
456
-
457
-	public function triggerChange($feature, $value = null, $oldValue = null) {
458
-		if ($this->emitter) {
459
-			$this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value, $oldValue));
460
-		}
461
-	}
47
+    /** @var string $uid */
48
+    private $uid;
49
+
50
+    /** @var string $displayName */
51
+    private $displayName;
52
+
53
+    /** @var UserInterface $backend */
54
+    private $backend;
55
+
56
+    /** @var bool $enabled */
57
+    private $enabled;
58
+
59
+    /** @var Emitter|Manager $emitter */
60
+    private $emitter;
61
+
62
+    /** @var string $home */
63
+    private $home;
64
+
65
+    /** @var int $lastLogin */
66
+    private $lastLogin;
67
+
68
+    /** @var \OCP\IConfig $config */
69
+    private $config;
70
+
71
+    /** @var IAvatarManager */
72
+    private $avatarManager;
73
+
74
+    /** @var IURLGenerator */
75
+    private $urlGenerator;
76
+
77
+    /**
78
+     * @param string $uid
79
+     * @param UserInterface $backend
80
+     * @param \OC\Hooks\Emitter $emitter
81
+     * @param IConfig|null $config
82
+     * @param IURLGenerator $urlGenerator
83
+     */
84
+    public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $urlGenerator = null) {
85
+        $this->uid = $uid;
86
+        $this->backend = $backend;
87
+        $this->emitter = $emitter;
88
+        if(is_null($config)) {
89
+            $config = \OC::$server->getConfig();
90
+        }
91
+        $this->config = $config;
92
+        $this->urlGenerator = $urlGenerator;
93
+        $enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true');
94
+        $this->enabled = ($enabled === 'true');
95
+        $this->lastLogin = $this->config->getUserValue($uid, 'login', 'lastLogin', 0);
96
+        if (is_null($this->urlGenerator)) {
97
+            $this->urlGenerator = \OC::$server->getURLGenerator();
98
+        }
99
+    }
100
+
101
+    /**
102
+     * get the user id
103
+     *
104
+     * @return string
105
+     */
106
+    public function getUID() {
107
+        return $this->uid;
108
+    }
109
+
110
+    /**
111
+     * get the display name for the user, if no specific display name is set it will fallback to the user id
112
+     *
113
+     * @return string
114
+     */
115
+    public function getDisplayName() {
116
+        if (!isset($this->displayName)) {
117
+            $displayName = '';
118
+            if ($this->backend and $this->backend->implementsActions(Backend::GET_DISPLAYNAME)) {
119
+                // get display name and strip whitespace from the beginning and end of it
120
+                $backendDisplayName = $this->backend->getDisplayName($this->uid);
121
+                if (is_string($backendDisplayName)) {
122
+                    $displayName = trim($backendDisplayName);
123
+                }
124
+            }
125
+
126
+            if (!empty($displayName)) {
127
+                $this->displayName = $displayName;
128
+            } else {
129
+                $this->displayName = $this->uid;
130
+            }
131
+        }
132
+        return $this->displayName;
133
+    }
134
+
135
+    /**
136
+     * set the displayname for the user
137
+     *
138
+     * @param string $displayName
139
+     * @return bool
140
+     */
141
+    public function setDisplayName($displayName) {
142
+        $displayName = trim($displayName);
143
+        if ($this->backend->implementsActions(Backend::SET_DISPLAYNAME) && !empty($displayName)) {
144
+            $result = $this->backend->setDisplayName($this->uid, $displayName);
145
+            if ($result) {
146
+                $this->displayName = $displayName;
147
+                $this->triggerChange('displayName', $displayName);
148
+            }
149
+            return $result !== false;
150
+        } else {
151
+            return false;
152
+        }
153
+    }
154
+
155
+    /**
156
+     * set the email address of the user
157
+     *
158
+     * @param string|null $mailAddress
159
+     * @return void
160
+     * @since 9.0.0
161
+     */
162
+    public function setEMailAddress($mailAddress) {
163
+        $oldMailAddress = $this->getEMailAddress();
164
+        if($mailAddress === '') {
165
+            $this->config->deleteUserValue($this->uid, 'settings', 'email');
166
+        } else {
167
+            $this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress);
168
+        }
169
+        if($oldMailAddress !== $mailAddress) {
170
+            $this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress);
171
+        }
172
+    }
173
+
174
+    /**
175
+     * returns the timestamp of the user's last login or 0 if the user did never
176
+     * login
177
+     *
178
+     * @return int
179
+     */
180
+    public function getLastLogin() {
181
+        return $this->lastLogin;
182
+    }
183
+
184
+    /**
185
+     * updates the timestamp of the most recent login of this user
186
+     */
187
+    public function updateLastLoginTimestamp() {
188
+        $firstTimeLogin = ($this->lastLogin === 0);
189
+        $this->lastLogin = time();
190
+        $this->config->setUserValue(
191
+            $this->uid, 'login', 'lastLogin', $this->lastLogin);
192
+
193
+        return $firstTimeLogin;
194
+    }
195
+
196
+    /**
197
+     * Delete the user
198
+     *
199
+     * @return bool
200
+     */
201
+    public function delete() {
202
+        if ($this->emitter) {
203
+            $this->emitter->emit('\OC\User', 'preDelete', array($this));
204
+        }
205
+        // get the home now because it won't return it after user deletion
206
+        $homePath = $this->getHome();
207
+        $result = $this->backend->deleteUser($this->uid);
208
+        if ($result) {
209
+
210
+            // FIXME: Feels like an hack - suggestions?
211
+
212
+            $groupManager = \OC::$server->getGroupManager();
213
+            // We have to delete the user from all groups
214
+            foreach ($groupManager->getUserGroupIds($this) as $groupId) {
215
+                $group = $groupManager->get($groupId);
216
+                if ($group) {
217
+                    \OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]);
218
+                    $group->removeUser($this);
219
+                    \OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]);
220
+                }
221
+            }
222
+            // Delete the user's keys in preferences
223
+            \OC::$server->getConfig()->deleteAllUserValues($this->uid);
224
+
225
+            // Delete user files in /data/
226
+            if ($homePath !== false) {
227
+                // FIXME: this operates directly on FS, should use View instead...
228
+                // also this is not testable/mockable...
229
+                \OC_Helper::rmdirr($homePath);
230
+            }
231
+
232
+            // Delete the users entry in the storage table
233
+            Storage::remove('home::' . $this->uid);
234
+
235
+            \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid);
236
+            \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this);
237
+
238
+            $notification = \OC::$server->getNotificationManager()->createNotification();
239
+            $notification->setUser($this->uid);
240
+            \OC::$server->getNotificationManager()->markProcessed($notification);
241
+
242
+            /** @var AccountManager $accountManager */
243
+            $accountManager = \OC::$server->query(AccountManager::class);
244
+            $accountManager->deleteUser($this);
245
+
246
+            if ($this->emitter) {
247
+                $this->emitter->emit('\OC\User', 'postDelete', array($this));
248
+            }
249
+        }
250
+        return !($result === false);
251
+    }
252
+
253
+    /**
254
+     * Set the password of the user
255
+     *
256
+     * @param string $password
257
+     * @param string $recoveryPassword for the encryption app to reset encryption keys
258
+     * @return bool
259
+     */
260
+    public function setPassword($password, $recoveryPassword = null) {
261
+        if ($this->emitter) {
262
+            $this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword));
263
+        }
264
+        if ($this->backend->implementsActions(Backend::SET_PASSWORD)) {
265
+            $result = $this->backend->setPassword($this->uid, $password);
266
+            if ($this->emitter) {
267
+                $this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword));
268
+            }
269
+            return !($result === false);
270
+        } else {
271
+            return false;
272
+        }
273
+    }
274
+
275
+    /**
276
+     * get the users home folder to mount
277
+     *
278
+     * @return string
279
+     */
280
+    public function getHome() {
281
+        if (!$this->home) {
282
+            if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) {
283
+                $this->home = $home;
284
+            } elseif ($this->config) {
285
+                $this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid;
286
+            } else {
287
+                $this->home = \OC::$SERVERROOT . '/data/' . $this->uid;
288
+            }
289
+        }
290
+        return $this->home;
291
+    }
292
+
293
+    /**
294
+     * Get the name of the backend class the user is connected with
295
+     *
296
+     * @return string
297
+     */
298
+    public function getBackendClassName() {
299
+        if($this->backend instanceof IUserBackend) {
300
+            return $this->backend->getBackendName();
301
+        }
302
+        return get_class($this->backend);
303
+    }
304
+
305
+    public function getBackend() {
306
+        return $this->backend;
307
+    }
308
+
309
+    /**
310
+     * check if the backend allows the user to change his avatar on Personal page
311
+     *
312
+     * @return bool
313
+     */
314
+    public function canChangeAvatar() {
315
+        if ($this->backend->implementsActions(Backend::PROVIDE_AVATAR)) {
316
+            return $this->backend->canChangeAvatar($this->uid);
317
+        }
318
+        return true;
319
+    }
320
+
321
+    /**
322
+     * check if the backend supports changing passwords
323
+     *
324
+     * @return bool
325
+     */
326
+    public function canChangePassword() {
327
+        return $this->backend->implementsActions(Backend::SET_PASSWORD);
328
+    }
329
+
330
+    /**
331
+     * check if the backend supports changing display names
332
+     *
333
+     * @return bool
334
+     */
335
+    public function canChangeDisplayName() {
336
+        if ($this->config->getSystemValue('allow_user_to_change_display_name') === false) {
337
+            return false;
338
+        }
339
+        return $this->backend->implementsActions(Backend::SET_DISPLAYNAME);
340
+    }
341
+
342
+    /**
343
+     * check if the user is enabled
344
+     *
345
+     * @return bool
346
+     */
347
+    public function isEnabled() {
348
+        return $this->enabled;
349
+    }
350
+
351
+    /**
352
+     * set the enabled status for the user
353
+     *
354
+     * @param bool $enabled
355
+     */
356
+    public function setEnabled(bool $enabled = true) {
357
+        $oldStatus = $this->isEnabled();
358
+        $this->enabled = $enabled;
359
+        if ($oldStatus !== $this->enabled) {
360
+            $this->triggerChange('enabled', $enabled);
361
+            $this->config->setUserValue($this->uid, 'core', 'enabled', $enabled ? 'true' : 'false');
362
+        }
363
+    }
364
+
365
+    /**
366
+     * get the users email address
367
+     *
368
+     * @return string|null
369
+     * @since 9.0.0
370
+     */
371
+    public function getEMailAddress() {
372
+        return $this->config->getUserValue($this->uid, 'settings', 'email', null);
373
+    }
374
+
375
+    /**
376
+     * get the users' quota
377
+     *
378
+     * @return string
379
+     * @since 9.0.0
380
+     */
381
+    public function getQuota() {
382
+        $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default');
383
+        if($quota === 'default') {
384
+            $quota = $this->config->getAppValue('files', 'default_quota', 'none');
385
+        }
386
+        return $quota;
387
+    }
388
+
389
+    /**
390
+     * set the users' quota
391
+     *
392
+     * @param string $quota
393
+     * @return void
394
+     * @since 9.0.0
395
+     */
396
+    public function setQuota($quota) {
397
+        $oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', '');
398
+        if($quota !== 'none' and $quota !== 'default') {
399
+            $quota = OC_Helper::computerFileSize($quota);
400
+            $quota = OC_Helper::humanFileSize($quota);
401
+        }
402
+        $this->config->setUserValue($this->uid, 'files', 'quota', $quota);
403
+        if($quota !== $oldQuota) {
404
+            $this->triggerChange('quota', $quota);
405
+        }
406
+    }
407
+
408
+    /**
409
+     * get the avatar image if it exists
410
+     *
411
+     * @param int $size
412
+     * @return IImage|null
413
+     * @since 9.0.0
414
+     */
415
+    public function getAvatarImage($size) {
416
+        // delay the initialization
417
+        if (is_null($this->avatarManager)) {
418
+            $this->avatarManager = \OC::$server->getAvatarManager();
419
+        }
420
+
421
+        $avatar = $this->avatarManager->getAvatar($this->uid);
422
+        $image = $avatar->get(-1);
423
+        if ($image) {
424
+            return $image;
425
+        }
426
+
427
+        return null;
428
+    }
429
+
430
+    /**
431
+     * get the federation cloud id
432
+     *
433
+     * @return string
434
+     * @since 9.0.0
435
+     */
436
+    public function getCloudId() {
437
+        $uid = $this->getUID();
438
+        $server = $this->urlGenerator->getAbsoluteURL('/');
439
+        $server =  rtrim( $this->removeProtocolFromUrl($server), '/');
440
+        return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId();
441
+    }
442
+
443
+    /**
444
+     * @param string $url
445
+     * @return string
446
+     */
447
+    private function removeProtocolFromUrl($url) {
448
+        if (strpos($url, 'https://') === 0) {
449
+            return substr($url, strlen('https://'));
450
+        } else if (strpos($url, 'http://') === 0) {
451
+            return substr($url, strlen('http://'));
452
+        }
453
+
454
+        return $url;
455
+    }
456
+
457
+    public function triggerChange($feature, $value = null, $oldValue = null) {
458
+        if ($this->emitter) {
459
+            $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value, $oldValue));
460
+        }
461
+    }
462 462
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Settings/Personal.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -32,72 +32,72 @@
 block discarded – undo
32 32
 
33 33
 class Personal implements ISettings {
34 34
 
35
-	/** @var IManager */
36
-	private $encryptionManager;
35
+    /** @var IManager */
36
+    private $encryptionManager;
37 37
 
38
-	/** @var UserGlobalStoragesService */
39
-	private $userGlobalStoragesService;
38
+    /** @var UserGlobalStoragesService */
39
+    private $userGlobalStoragesService;
40 40
 
41
-	/** @var BackendService */
42
-	private $backendService;
41
+    /** @var BackendService */
42
+    private $backendService;
43 43
 
44
-	/** @var GlobalAuth	 */
45
-	private $globalAuth;
44
+    /** @var GlobalAuth	 */
45
+    private $globalAuth;
46 46
 
47
-	/** @var IUserSession */
48
-	private $userSession;
47
+    /** @var IUserSession */
48
+    private $userSession;
49 49
 
50
-	public function __construct(
51
-		IManager $encryptionManager,
52
-		UserGlobalStoragesService $userGlobalStoragesService,
53
-		BackendService $backendService,
54
-		GlobalAuth $globalAuth,
55
-		IUserSession $userSession
56
-	) {
57
-		$this->encryptionManager = $encryptionManager;
58
-		$this->userGlobalStoragesService = $userGlobalStoragesService;
59
-		$this->backendService = $backendService;
60
-		$this->globalAuth = $globalAuth;
61
-		$this->userSession = $userSession;
62
-	}
50
+    public function __construct(
51
+        IManager $encryptionManager,
52
+        UserGlobalStoragesService $userGlobalStoragesService,
53
+        BackendService $backendService,
54
+        GlobalAuth $globalAuth,
55
+        IUserSession $userSession
56
+    ) {
57
+        $this->encryptionManager = $encryptionManager;
58
+        $this->userGlobalStoragesService = $userGlobalStoragesService;
59
+        $this->backendService = $backendService;
60
+        $this->globalAuth = $globalAuth;
61
+        $this->userSession = $userSession;
62
+    }
63 63
 
64
-	/**
65
-	 * @return TemplateResponse
66
-	 */
67
-	public function getForm() {
68
-		$uid = $this->userSession->getUser()->getUID();
64
+    /**
65
+     * @return TemplateResponse
66
+     */
67
+    public function getForm() {
68
+        $uid = $this->userSession->getUser()->getUID();
69 69
 
70
-		$parameters = [
71
-			'encryptionEnabled'    => $this->encryptionManager->isEnabled(),
72
-			'visibilityType'       => BackendService::VISIBILITY_PERSONAL,
73
-			'storages'             => $this->userGlobalStoragesService->getStorages(),
74
-			'backends'             => $this->backendService->getAvailableBackends(),
75
-			'authMechanisms'       => $this->backendService->getAuthMechanisms(),
76
-			'dependencies'         => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()),
77
-			'allowUserMounting'    => $this->backendService->isUserMountingAllowed(),
78
-			'globalCredentials'    => $this->globalAuth->getAuth($uid),
79
-			'globalCredentialsUid' => $uid,
80
-		];
70
+        $parameters = [
71
+            'encryptionEnabled'    => $this->encryptionManager->isEnabled(),
72
+            'visibilityType'       => BackendService::VISIBILITY_PERSONAL,
73
+            'storages'             => $this->userGlobalStoragesService->getStorages(),
74
+            'backends'             => $this->backendService->getAvailableBackends(),
75
+            'authMechanisms'       => $this->backendService->getAuthMechanisms(),
76
+            'dependencies'         => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()),
77
+            'allowUserMounting'    => $this->backendService->isUserMountingAllowed(),
78
+            'globalCredentials'    => $this->globalAuth->getAuth($uid),
79
+            'globalCredentialsUid' => $uid,
80
+        ];
81 81
 
82
-		return new TemplateResponse('files_external', 'settings', $parameters, '');
83
-	}
82
+        return new TemplateResponse('files_external', 'settings', $parameters, '');
83
+    }
84 84
 
85
-	/**
86
-	 * @return string the section ID, e.g. 'sharing'
87
-	 */
88
-	public function getSection() {
89
-		return 'externalstorages';
90
-	}
85
+    /**
86
+     * @return string the section ID, e.g. 'sharing'
87
+     */
88
+    public function getSection() {
89
+        return 'externalstorages';
90
+    }
91 91
 
92
-	/**
93
-	 * @return int whether the form should be rather on the top or bottom of
94
-	 * the admin section. The forms are arranged in ascending order of the
95
-	 * priority values. It is required to return a value between 0 and 100.
96
-	 *
97
-	 * E.g.: 70
98
-	 */
99
-	public function getPriority() {
100
-		return 40;
101
-	}
92
+    /**
93
+     * @return int whether the form should be rather on the top or bottom of
94
+     * the admin section. The forms are arranged in ascending order of the
95
+     * priority values. It is required to return a value between 0 and 100.
96
+     *
97
+     * E.g.: 70
98
+     */
99
+    public function getPriority() {
100
+        return 40;
101
+    }
102 102
 
103 103
 }
Please login to merge, or discard this patch.
apps/files_external/appinfo/app.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,13 +29,13 @@
 block discarded – undo
29 29
 
30 30
 OC::$CLASSPATH['OC_Mount_Config'] = 'files_external/lib/config.php';
31 31
 
32
-require_once __DIR__ . '/../3rdparty/autoload.php';
32
+require_once __DIR__.'/../3rdparty/autoload.php';
33 33
 
34 34
 // register Application object singleton
35 35
 \OC_Mount_Config::$app = new \OCA\Files_External\AppInfo\Application();
36 36
 $appContainer = \OC_Mount_Config::$app->getContainer();
37 37
 
38
-\OCA\Files\App::getNavigationManager()->add(function () {
38
+\OCA\Files\App::getNavigationManager()->add(function() {
39 39
 	$l = \OC::$server->getL10N('files_external');
40 40
 	return [
41 41
 		'id' => 'extstoragemounts',
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -37,14 +37,14 @@
 block discarded – undo
37 37
 $appContainer = \OC_Mount_Config::$app->getContainer();
38 38
 
39 39
 \OCA\Files\App::getNavigationManager()->add(function () {
40
-	$l = \OC::$server->getL10N('files_external');
41
-	return [
42
-		'id' => 'extstoragemounts',
43
-		'appname' => 'files_external',
44
-		'script' => 'list.php',
45
-		'order' => 30,
46
-		'name' => $l->t('External storages'),
47
-	];
40
+    $l = \OC::$server->getL10N('files_external');
41
+    return [
42
+        'id' => 'extstoragemounts',
43
+        'appname' => 'files_external',
44
+        'script' => 'list.php',
45
+        'order' => 30,
46
+        'name' => $l->t('External storages'),
47
+    ];
48 48
 });
49 49
 
50 50
 $mountProvider = $appContainer->query(ConfigAdapter::class);
Please login to merge, or discard this patch.
core/Command/Db/Migrations/ExecuteCommand.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
 			$olderVersions = $ms->getMigratedVersions();
79 79
 			$olderVersions[] = '0';
80 80
 			$olderVersions[] = 'prev';
81
-			if (in_array($version,  $olderVersions, true)) {
81
+			if (in_array($version, $olderVersions, true)) {
82 82
 				$output->writeln('<error>Can not go back to previous migration without debug enabled</error>');
83 83
 				return 1;
84 84
 			}
Please login to merge, or discard this patch.
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -38,95 +38,95 @@
 block discarded – undo
38 38
 
39 39
 class ExecuteCommand extends Command implements CompletionAwareInterface {
40 40
 
41
-	/** @var IDBConnection */
42
-	private $connection;
43
-
44
-	/** @var IConfig */
45
-	private $config;
46
-
47
-	/** @var IAppManager */
48
-	protected $appManager;
49
-
50
-	/**
51
-	 * ExecuteCommand constructor.
52
-	 *
53
-	 * @param IDBConnection $connection
54
-	 * @param IConfig $config
55
-	 * @param IAppManager $appManager
56
-	 */
57
-	public function __construct(IDBConnection $connection, IAppManager $appManager, IConfig $config) {
58
-		$this->connection = $connection;
59
-		$this->config = $config;
60
-
61
-		parent::__construct();
62
-	}
63
-
64
-	protected function configure() {
65
-		$this
66
-			->setName('migrations:execute')
67
-			->setDescription('Execute a single migration version manually.')
68
-			->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
69
-			->addArgument('version', InputArgument::REQUIRED, 'The version to execute.', null);
70
-
71
-		parent::configure();
72
-	}
73
-
74
-	/**
75
-	 * @param InputInterface $input
76
-	 * @param OutputInterface $output
77
-	 * @return int
78
-	 */
79
-	public function execute(InputInterface $input, OutputInterface $output) {
80
-		$appName = $input->getArgument('app');
81
-		$ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
82
-		$version = $input->getArgument('version');
83
-
84
-		if ($this->config->getSystemValue('debug', false) === false) {
85
-			$olderVersions = $ms->getMigratedVersions();
86
-			$olderVersions[] = '0';
87
-			$olderVersions[] = 'prev';
88
-			if (in_array($version,  $olderVersions, true)) {
89
-				$output->writeln('<error>Can not go back to previous migration without debug enabled</error>');
90
-				return 1;
91
-			}
92
-		}
93
-
94
-
95
-		$ms->executeStep($version);
96
-		return 0;
97
-	}
98
-
99
-	/**
100
-	 * @param string $optionName
101
-	 * @param CompletionContext $context
102
-	 * @return string[]
103
-	 */
104
-	public function completeOptionValues($optionName, CompletionContext $context) {
105
-		return [];
106
-	}
107
-
108
-	/**
109
-	 * @param string $argumentName
110
-	 * @param CompletionContext $context
111
-	 * @return string[]
112
-	 */
113
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
114
-		if ($argumentName === 'app') {
115
-			$allApps = \OC_App::getAllApps();
116
-			return array_diff($allApps, \OC_App::getEnabledApps(true, true));
117
-		}
118
-
119
-		if ($argumentName === 'version') {
120
-			$appName = $context->getWordAtIndex($context->getWordIndex() - 1);
121
-
122
-			$ms = new MigrationService($appName, $this->connection);
123
-			$migrations = $ms->getAvailableVersions();
124
-
125
-			array_unshift($migrations, 'next', 'latest');
126
-			return $migrations;
127
-		}
128
-
129
-		return [];
130
-	}
41
+    /** @var IDBConnection */
42
+    private $connection;
43
+
44
+    /** @var IConfig */
45
+    private $config;
46
+
47
+    /** @var IAppManager */
48
+    protected $appManager;
49
+
50
+    /**
51
+     * ExecuteCommand constructor.
52
+     *
53
+     * @param IDBConnection $connection
54
+     * @param IConfig $config
55
+     * @param IAppManager $appManager
56
+     */
57
+    public function __construct(IDBConnection $connection, IAppManager $appManager, IConfig $config) {
58
+        $this->connection = $connection;
59
+        $this->config = $config;
60
+
61
+        parent::__construct();
62
+    }
63
+
64
+    protected function configure() {
65
+        $this
66
+            ->setName('migrations:execute')
67
+            ->setDescription('Execute a single migration version manually.')
68
+            ->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
69
+            ->addArgument('version', InputArgument::REQUIRED, 'The version to execute.', null);
70
+
71
+        parent::configure();
72
+    }
73
+
74
+    /**
75
+     * @param InputInterface $input
76
+     * @param OutputInterface $output
77
+     * @return int
78
+     */
79
+    public function execute(InputInterface $input, OutputInterface $output) {
80
+        $appName = $input->getArgument('app');
81
+        $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
82
+        $version = $input->getArgument('version');
83
+
84
+        if ($this->config->getSystemValue('debug', false) === false) {
85
+            $olderVersions = $ms->getMigratedVersions();
86
+            $olderVersions[] = '0';
87
+            $olderVersions[] = 'prev';
88
+            if (in_array($version,  $olderVersions, true)) {
89
+                $output->writeln('<error>Can not go back to previous migration without debug enabled</error>');
90
+                return 1;
91
+            }
92
+        }
93
+
94
+
95
+        $ms->executeStep($version);
96
+        return 0;
97
+    }
98
+
99
+    /**
100
+     * @param string $optionName
101
+     * @param CompletionContext $context
102
+     * @return string[]
103
+     */
104
+    public function completeOptionValues($optionName, CompletionContext $context) {
105
+        return [];
106
+    }
107
+
108
+    /**
109
+     * @param string $argumentName
110
+     * @param CompletionContext $context
111
+     * @return string[]
112
+     */
113
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
114
+        if ($argumentName === 'app') {
115
+            $allApps = \OC_App::getAllApps();
116
+            return array_diff($allApps, \OC_App::getEnabledApps(true, true));
117
+        }
118
+
119
+        if ($argumentName === 'version') {
120
+            $appName = $context->getWordAtIndex($context->getWordIndex() - 1);
121
+
122
+            $ms = new MigrationService($appName, $this->connection);
123
+            $migrations = $ms->getAvailableVersions();
124
+
125
+            array_unshift($migrations, 'next', 'latest');
126
+            return $migrations;
127
+        }
128
+
129
+        return [];
130
+    }
131 131
 
132 132
 }
Please login to merge, or discard this patch.