Completed
Pull Request — master (#4336)
by Lukas
17:56 queued 06:34
created
lib/private/legacy/template/functions.php 3 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
  * make preview_icon available as a simple function
184 184
  * Returns the path to the preview of the image.
185 185
  * @param string $path path of file
186
- * @return link to the preview
186
+ * @return string to the preview
187 187
  */
188 188
 function preview_icon( $path ) {
189 189
 	return \OC::$server->getURLGenerator()->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]);
@@ -191,6 +191,7 @@  discard block
 block discarded – undo
191 191
 
192 192
 /**
193 193
  * @param string $path
194
+ * @param string $token
194 195
  */
195 196
 function publicPreview_icon ( $path, $token ) {
196 197
 	return \OC::$server->getURLGenerator()->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 't' => $token]);
Please login to merge, or discard this patch.
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
  * @param string $string the string which will be escaped and printed
35 35
  */
36 36
 function p($string) {
37
-	print(\OCP\Util::sanitizeHTML($string));
37
+    print(\OCP\Util::sanitizeHTML($string));
38 38
 }
39 39
 
40 40
 /**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
  * @param string|array $string the string which will be printed as it is
44 44
  */
45 45
 function print_unescaped($string) {
46
-	print($string);
46
+    print($string);
47 47
 }
48 48
 
49 49
 /**
@@ -53,13 +53,13 @@  discard block
 block discarded – undo
53 53
  * if an array is given it will add all scripts
54 54
  */
55 55
 function script($app, $file = null) {
56
-	if(is_array($file)) {
57
-		foreach($file as $f) {
58
-			OC_Util::addScript($app, $f);
59
-		}
60
-	} else {
61
-		OC_Util::addScript($app, $file);
62
-	}
56
+    if(is_array($file)) {
57
+        foreach($file as $f) {
58
+            OC_Util::addScript($app, $f);
59
+        }
60
+    } else {
61
+        OC_Util::addScript($app, $file);
62
+    }
63 63
 }
64 64
 
65 65
 /**
@@ -69,13 +69,13 @@  discard block
 block discarded – undo
69 69
  * if an array is given it will add all scripts
70 70
  */
71 71
 function vendor_script($app, $file = null) {
72
-	if(is_array($file)) {
73
-		foreach($file as $f) {
74
-			OC_Util::addVendorScript($app, $f);
75
-		}
76
-	} else {
77
-		OC_Util::addVendorScript($app, $file);
78
-	}
72
+    if(is_array($file)) {
73
+        foreach($file as $f) {
74
+            OC_Util::addVendorScript($app, $f);
75
+        }
76
+    } else {
77
+        OC_Util::addVendorScript($app, $file);
78
+    }
79 79
 }
80 80
 
81 81
 /**
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
  * if an array is given it will add all styles
86 86
  */
87 87
 function style($app, $file = null) {
88
-	if(is_array($file)) {
89
-		foreach($file as $f) {
90
-			OC_Util::addStyle($app, $f);
91
-		}
92
-	} else {
93
-		OC_Util::addStyle($app, $file);
94
-	}
88
+    if(is_array($file)) {
89
+        foreach($file as $f) {
90
+            OC_Util::addStyle($app, $f);
91
+        }
92
+    } else {
93
+        OC_Util::addStyle($app, $file);
94
+    }
95 95
 }
96 96
 
97 97
 /**
@@ -101,13 +101,13 @@  discard block
 block discarded – undo
101 101
  * if an array is given it will add all styles
102 102
  */
103 103
 function vendor_style($app, $file = null) {
104
-	if(is_array($file)) {
105
-		foreach($file as $f) {
106
-			OC_Util::addVendorStyle($app, $f);
107
-		}
108
-	} else {
109
-		OC_Util::addVendorStyle($app, $file);
110
-	}
104
+    if(is_array($file)) {
105
+        foreach($file as $f) {
106
+            OC_Util::addVendorStyle($app, $f);
107
+        }
108
+    } else {
109
+        OC_Util::addVendorStyle($app, $file);
110
+    }
111 111
 }
112 112
 
113 113
 /**
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
  * if an array is given it will add all styles
117 117
  */
118 118
 function translation($app) {
119
-	OC_Util::addTranslations($app);
119
+    OC_Util::addTranslations($app);
120 120
 }
121 121
 
122 122
 /**
@@ -126,15 +126,15 @@  discard block
 block discarded – undo
126 126
  * if an array is given it will add all components
127 127
  */
128 128
 function component($app, $file) {
129
-	if(is_array($file)) {
130
-		foreach($file as $f) {
131
-			$url = link_to($app, 'component/' . $f . '.html');
132
-			OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
133
-		}
134
-	} else {
135
-		$url = link_to($app, 'component/' . $file . '.html');
136
-		OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
137
-	}
129
+    if(is_array($file)) {
130
+        foreach($file as $f) {
131
+            $url = link_to($app, 'component/' . $f . '.html');
132
+            OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
133
+        }
134
+    } else {
135
+        $url = link_to($app, 'component/' . $file . '.html');
136
+        OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
137
+    }
138 138
 }
139 139
 
140 140
 /**
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
  * For further information have a look at \OCP\IURLGenerator::linkTo
148 148
  */
149 149
 function link_to( $app, $file, $args = array() ) {
150
-	return \OC::$server->getURLGenerator()->linkTo($app, $file, $args);
150
+    return \OC::$server->getURLGenerator()->linkTo($app, $file, $args);
151 151
 }
152 152
 
153 153
 /**
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
  * @return string url to the online documentation
156 156
  */
157 157
 function link_to_docs($key) {
158
-	return \OC::$server->getURLGenerator()->linkToDocs($key);
158
+    return \OC::$server->getURLGenerator()->linkToDocs($key);
159 159
 }
160 160
 
161 161
 /**
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
  * For further information have a look at \OCP\IURLGenerator::imagePath
168 168
  */
169 169
 function image_path( $app, $image ) {
170
-	return \OC::$server->getURLGenerator()->imagePath( $app, $image );
170
+    return \OC::$server->getURLGenerator()->imagePath( $app, $image );
171 171
 }
172 172
 
173 173
 /**
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
  * @return string link to the image
177 177
  */
178 178
 function mimetype_icon( $mimetype ) {
179
-	return \OC::$server->getMimeTypeDetector()->mimeTypeIcon( $mimetype );
179
+    return \OC::$server->getMimeTypeDetector()->mimeTypeIcon( $mimetype );
180 180
 }
181 181
 
182 182
 /**
@@ -186,14 +186,14 @@  discard block
 block discarded – undo
186 186
  * @return link to the preview
187 187
  */
188 188
 function preview_icon( $path ) {
189
-	return \OC::$server->getURLGenerator()->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]);
189
+    return \OC::$server->getURLGenerator()->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]);
190 190
 }
191 191
 
192 192
 /**
193 193
  * @param string $path
194 194
  */
195 195
 function publicPreview_icon ( $path, $token ) {
196
-	return \OC::$server->getURLGenerator()->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 't' => $token]);
196
+    return \OC::$server->getURLGenerator()->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 't' => $token]);
197 197
 }
198 198
 
199 199
 /**
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
  * For further information have a look at OC_Helper::humanFileSize
205 205
  */
206 206
 function human_file_size( $bytes ) {
207
-	return OC_Helper::humanFileSize( $bytes );
207
+    return OC_Helper::humanFileSize( $bytes );
208 208
 }
209 209
 
210 210
 /**
@@ -213,9 +213,9 @@  discard block
 block discarded – undo
213 213
  * @return $timestamp without time value
214 214
  */
215 215
 function strip_time($timestamp){
216
-	$date = new \DateTime("@{$timestamp}");
217
-	$date->setTime(0, 0, 0);
218
-	return intval($date->format('U'));
216
+    $date = new \DateTime("@{$timestamp}");
217
+    $date->setTime(0, 0, 0);
218
+    return intval($date->format('U'));
219 219
 }
220 220
 
221 221
 /**
@@ -227,39 +227,39 @@  discard block
 block discarded – undo
227 227
  * @return string timestamp
228 228
  */
229 229
 function relative_modified_date($timestamp, $fromTime = null, $dateOnly = false) {
230
-	/** @var \OC\DateTimeFormatter $formatter */
231
-	$formatter = \OC::$server->query('DateTimeFormatter');
230
+    /** @var \OC\DateTimeFormatter $formatter */
231
+    $formatter = \OC::$server->query('DateTimeFormatter');
232 232
 
233
-	if ($dateOnly){
234
-		return $formatter->formatDateSpan($timestamp, $fromTime);
235
-	}
236
-	return $formatter->formatTimeSpan($timestamp, $fromTime);
233
+    if ($dateOnly){
234
+        return $formatter->formatDateSpan($timestamp, $fromTime);
235
+    }
236
+    return $formatter->formatTimeSpan($timestamp, $fromTime);
237 237
 }
238 238
 
239 239
 function html_select_options($options, $selected, $params=array()) {
240
-	if (!is_array($selected)) {
241
-		$selected=array($selected);
242
-	}
243
-	if (isset($params['combine']) && $params['combine']) {
244
-		$options = array_combine($options, $options);
245
-	}
246
-	$value_name = $label_name = false;
247
-	if (isset($params['value'])) {
248
-		$value_name = $params['value'];
249
-	}
250
-	if (isset($params['label'])) {
251
-		$label_name = $params['label'];
252
-	}
253
-	$html = '';
254
-	foreach($options as $value => $label) {
255
-		if ($value_name && is_array($label)) {
256
-			$value = $label[$value_name];
257
-		}
258
-		if ($label_name && is_array($label)) {
259
-			$label = $label[$label_name];
260
-		}
261
-		$select = in_array($value, $selected) ? ' selected="selected"' : '';
262
-		$html .= '<option value="' . \OCP\Util::sanitizeHTML($value) . '"' . $select . '>' . \OCP\Util::sanitizeHTML($label) . '</option>'."\n";
263
-	}
264
-	return $html;
240
+    if (!is_array($selected)) {
241
+        $selected=array($selected);
242
+    }
243
+    if (isset($params['combine']) && $params['combine']) {
244
+        $options = array_combine($options, $options);
245
+    }
246
+    $value_name = $label_name = false;
247
+    if (isset($params['value'])) {
248
+        $value_name = $params['value'];
249
+    }
250
+    if (isset($params['label'])) {
251
+        $label_name = $params['label'];
252
+    }
253
+    $html = '';
254
+    foreach($options as $value => $label) {
255
+        if ($value_name && is_array($label)) {
256
+            $value = $label[$value_name];
257
+        }
258
+        if ($label_name && is_array($label)) {
259
+            $label = $label[$label_name];
260
+        }
261
+        $select = in_array($value, $selected) ? ' selected="selected"' : '';
262
+        $html .= '<option value="' . \OCP\Util::sanitizeHTML($value) . '"' . $select . '>' . \OCP\Util::sanitizeHTML($label) . '</option>'."\n";
263
+    }
264
+    return $html;
265 265
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
  * if an array is given it will add all scripts
54 54
  */
55 55
 function script($app, $file = null) {
56
-	if(is_array($file)) {
57
-		foreach($file as $f) {
56
+	if (is_array($file)) {
57
+		foreach ($file as $f) {
58 58
 			OC_Util::addScript($app, $f);
59 59
 		}
60 60
 	} else {
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
  * if an array is given it will add all scripts
70 70
  */
71 71
 function vendor_script($app, $file = null) {
72
-	if(is_array($file)) {
73
-		foreach($file as $f) {
72
+	if (is_array($file)) {
73
+		foreach ($file as $f) {
74 74
 			OC_Util::addVendorScript($app, $f);
75 75
 		}
76 76
 	} else {
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
  * if an array is given it will add all styles
86 86
  */
87 87
 function style($app, $file = null) {
88
-	if(is_array($file)) {
89
-		foreach($file as $f) {
88
+	if (is_array($file)) {
89
+		foreach ($file as $f) {
90 90
 			OC_Util::addStyle($app, $f);
91 91
 		}
92 92
 	} else {
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
  * if an array is given it will add all styles
102 102
  */
103 103
 function vendor_style($app, $file = null) {
104
-	if(is_array($file)) {
105
-		foreach($file as $f) {
104
+	if (is_array($file)) {
105
+		foreach ($file as $f) {
106 106
 			OC_Util::addVendorStyle($app, $f);
107 107
 		}
108 108
 	} else {
@@ -126,13 +126,13 @@  discard block
 block discarded – undo
126 126
  * if an array is given it will add all components
127 127
  */
128 128
 function component($app, $file) {
129
-	if(is_array($file)) {
130
-		foreach($file as $f) {
131
-			$url = link_to($app, 'component/' . $f . '.html');
129
+	if (is_array($file)) {
130
+		foreach ($file as $f) {
131
+			$url = link_to($app, 'component/'.$f.'.html');
132 132
 			OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
133 133
 		}
134 134
 	} else {
135
-		$url = link_to($app, 'component/' . $file . '.html');
135
+		$url = link_to($app, 'component/'.$file.'.html');
136 136
 		OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url));
137 137
 	}
138 138
 }
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
  *
147 147
  * For further information have a look at \OCP\IURLGenerator::linkTo
148 148
  */
149
-function link_to( $app, $file, $args = array() ) {
149
+function link_to($app, $file, $args = array()) {
150 150
 	return \OC::$server->getURLGenerator()->linkTo($app, $file, $args);
151 151
 }
152 152
 
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
  *
167 167
  * For further information have a look at \OCP\IURLGenerator::imagePath
168 168
  */
169
-function image_path( $app, $image ) {
170
-	return \OC::$server->getURLGenerator()->imagePath( $app, $image );
169
+function image_path($app, $image) {
170
+	return \OC::$server->getURLGenerator()->imagePath($app, $image);
171 171
 }
172 172
 
173 173
 /**
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
  * @param string $mimetype mimetype
176 176
  * @return string link to the image
177 177
  */
178
-function mimetype_icon( $mimetype ) {
179
-	return \OC::$server->getMimeTypeDetector()->mimeTypeIcon( $mimetype );
178
+function mimetype_icon($mimetype) {
179
+	return \OC::$server->getMimeTypeDetector()->mimeTypeIcon($mimetype);
180 180
 }
181 181
 
182 182
 /**
@@ -185,14 +185,14 @@  discard block
 block discarded – undo
185 185
  * @param string $path path of file
186 186
  * @return link to the preview
187 187
  */
188
-function preview_icon( $path ) {
188
+function preview_icon($path) {
189 189
 	return \OC::$server->getURLGenerator()->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]);
190 190
 }
191 191
 
192 192
 /**
193 193
  * @param string $path
194 194
  */
195
-function publicPreview_icon ( $path, $token ) {
195
+function publicPreview_icon($path, $token) {
196 196
 	return \OC::$server->getURLGenerator()->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 't' => $token]);
197 197
 }
198 198
 
@@ -203,8 +203,8 @@  discard block
 block discarded – undo
203 203
  *
204 204
  * For further information have a look at OC_Helper::humanFileSize
205 205
  */
206
-function human_file_size( $bytes ) {
207
-	return OC_Helper::humanFileSize( $bytes );
206
+function human_file_size($bytes) {
207
+	return OC_Helper::humanFileSize($bytes);
208 208
 }
209 209
 
210 210
 /**
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
  * @param int $timestamp UNIX timestamp to strip
213 213
  * @return $timestamp without time value
214 214
  */
215
-function strip_time($timestamp){
215
+function strip_time($timestamp) {
216 216
 	$date = new \DateTime("@{$timestamp}");
217 217
 	$date->setTime(0, 0, 0);
218 218
 	return intval($date->format('U'));
@@ -230,15 +230,15 @@  discard block
 block discarded – undo
230 230
 	/** @var \OC\DateTimeFormatter $formatter */
231 231
 	$formatter = \OC::$server->query('DateTimeFormatter');
232 232
 
233
-	if ($dateOnly){
233
+	if ($dateOnly) {
234 234
 		return $formatter->formatDateSpan($timestamp, $fromTime);
235 235
 	}
236 236
 	return $formatter->formatTimeSpan($timestamp, $fromTime);
237 237
 }
238 238
 
239
-function html_select_options($options, $selected, $params=array()) {
239
+function html_select_options($options, $selected, $params = array()) {
240 240
 	if (!is_array($selected)) {
241
-		$selected=array($selected);
241
+		$selected = array($selected);
242 242
 	}
243 243
 	if (isset($params['combine']) && $params['combine']) {
244 244
 		$options = array_combine($options, $options);
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 		$label_name = $params['label'];
252 252
 	}
253 253
 	$html = '';
254
-	foreach($options as $value => $label) {
254
+	foreach ($options as $value => $label) {
255 255
 		if ($value_name && is_array($label)) {
256 256
 			$value = $label[$value_name];
257 257
 		}
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 			$label = $label[$label_name];
260 260
 		}
261 261
 		$select = in_array($value, $selected) ? ' selected="selected"' : '';
262
-		$html .= '<option value="' . \OCP\Util::sanitizeHTML($value) . '"' . $select . '>' . \OCP\Util::sanitizeHTML($label) . '</option>'."\n";
262
+		$html .= '<option value="'.\OCP\Util::sanitizeHTML($value).'"'.$select.'>'.\OCP\Util::sanitizeHTML($label).'</option>'."\n";
263 263
 	}
264 264
 	return $html;
265 265
 }
Please login to merge, or discard this patch.
lib/private/Memcache/APCu.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
 	 * Set a value in the cache if it's not already stored
66 66
 	 *
67 67
 	 * @param string $key
68
-	 * @param mixed $value
68
+	 * @param integer $value
69 69
 	 * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
70 70
 	 * @return bool
71 71
 	 */
Please login to merge, or discard this patch.
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -30,140 +30,140 @@
 block discarded – undo
30 30
 use OCP\IMemcache;
31 31
 
32 32
 class APCu extends Cache implements IMemcache {
33
-	use CASTrait {
34
-		cas as casEmulated;
35
-	}
33
+    use CASTrait {
34
+        cas as casEmulated;
35
+    }
36 36
 
37
-	use CADTrait;
37
+    use CADTrait;
38 38
 
39
-	public function get($key) {
40
-		$result = apcu_fetch($this->getPrefix() . $key, $success);
41
-		if (!$success) {
42
-			return null;
43
-		}
44
-		return $result;
45
-	}
39
+    public function get($key) {
40
+        $result = apcu_fetch($this->getPrefix() . $key, $success);
41
+        if (!$success) {
42
+            return null;
43
+        }
44
+        return $result;
45
+    }
46 46
 
47
-	public function set($key, $value, $ttl = 0) {
48
-		return apcu_store($this->getPrefix() . $key, $value, $ttl);
49
-	}
47
+    public function set($key, $value, $ttl = 0) {
48
+        return apcu_store($this->getPrefix() . $key, $value, $ttl);
49
+    }
50 50
 
51
-	public function hasKey($key) {
52
-		return apcu_exists($this->getPrefix() . $key);
53
-	}
51
+    public function hasKey($key) {
52
+        return apcu_exists($this->getPrefix() . $key);
53
+    }
54 54
 
55
-	public function remove($key) {
56
-		return apcu_delete($this->getPrefix() . $key);
57
-	}
55
+    public function remove($key) {
56
+        return apcu_delete($this->getPrefix() . $key);
57
+    }
58 58
 
59
-	public function clear($prefix = '') {
60
-		$ns = $this->getPrefix() . $prefix;
61
-		$ns = preg_quote($ns, '/');
62
-		if(class_exists('\APCIterator')) {
63
-			$iter = new \APCIterator('user', '/^' . $ns . '/', APC_ITER_KEY);
64
-		} else {
65
-			$iter = new \APCUIterator('/^' . $ns . '/', APC_ITER_KEY);
66
-		}
67
-		return apcu_delete($iter);
68
-	}
59
+    public function clear($prefix = '') {
60
+        $ns = $this->getPrefix() . $prefix;
61
+        $ns = preg_quote($ns, '/');
62
+        if(class_exists('\APCIterator')) {
63
+            $iter = new \APCIterator('user', '/^' . $ns . '/', APC_ITER_KEY);
64
+        } else {
65
+            $iter = new \APCUIterator('/^' . $ns . '/', APC_ITER_KEY);
66
+        }
67
+        return apcu_delete($iter);
68
+    }
69 69
 
70
-	/**
71
-	 * Set a value in the cache if it's not already stored
72
-	 *
73
-	 * @param string $key
74
-	 * @param mixed $value
75
-	 * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
76
-	 * @return bool
77
-	 */
78
-	public function add($key, $value, $ttl = 0) {
79
-		return apcu_add($this->getPrefix() . $key, $value, $ttl);
80
-	}
70
+    /**
71
+     * Set a value in the cache if it's not already stored
72
+     *
73
+     * @param string $key
74
+     * @param mixed $value
75
+     * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
76
+     * @return bool
77
+     */
78
+    public function add($key, $value, $ttl = 0) {
79
+        return apcu_add($this->getPrefix() . $key, $value, $ttl);
80
+    }
81 81
 
82
-	/**
83
-	 * Increase a stored number
84
-	 *
85
-	 * @param string $key
86
-	 * @param int $step
87
-	 * @return int | bool
88
-	 */
89
-	public function inc($key, $step = 1) {
90
-		$this->add($key, 0);
91
-		/**
92
-		 * TODO - hack around a PHP 7 specific issue in APCu
93
-		 *
94
-		 * on PHP 7 the apcu_inc method on a non-existing object will increment
95
-		 * "0" and result in "1" as value - therefore we check for existence
96
-		 * first
97
-		 *
98
-		 * on PHP 5.6 this is not the case
99
-		 *
100
-		 * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221
101
-		 * for details
102
-		 */
103
-		return apcu_exists($this->getPrefix() . $key)
104
-			? apcu_inc($this->getPrefix() . $key, $step)
105
-			: false;
106
-	}
82
+    /**
83
+     * Increase a stored number
84
+     *
85
+     * @param string $key
86
+     * @param int $step
87
+     * @return int | bool
88
+     */
89
+    public function inc($key, $step = 1) {
90
+        $this->add($key, 0);
91
+        /**
92
+         * TODO - hack around a PHP 7 specific issue in APCu
93
+         *
94
+         * on PHP 7 the apcu_inc method on a non-existing object will increment
95
+         * "0" and result in "1" as value - therefore we check for existence
96
+         * first
97
+         *
98
+         * on PHP 5.6 this is not the case
99
+         *
100
+         * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221
101
+         * for details
102
+         */
103
+        return apcu_exists($this->getPrefix() . $key)
104
+            ? apcu_inc($this->getPrefix() . $key, $step)
105
+            : false;
106
+    }
107 107
 
108
-	/**
109
-	 * Decrease a stored number
110
-	 *
111
-	 * @param string $key
112
-	 * @param int $step
113
-	 * @return int | bool
114
-	 */
115
-	public function dec($key, $step = 1) {
116
-		/**
117
-		 * TODO - hack around a PHP 7 specific issue in APCu
118
-		 *
119
-		 * on PHP 7 the apcu_dec method on a non-existing object will decrement
120
-		 * "0" and result in "-1" as value - therefore we check for existence
121
-		 * first
122
-		 *
123
-		 * on PHP 5.6 this is not the case
124
-		 *
125
-		 * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221
126
-		 * for details
127
-		 */
128
-		return apcu_exists($this->getPrefix() . $key)
129
-			? apcu_dec($this->getPrefix() . $key, $step)
130
-			: false;
131
-	}
108
+    /**
109
+     * Decrease a stored number
110
+     *
111
+     * @param string $key
112
+     * @param int $step
113
+     * @return int | bool
114
+     */
115
+    public function dec($key, $step = 1) {
116
+        /**
117
+         * TODO - hack around a PHP 7 specific issue in APCu
118
+         *
119
+         * on PHP 7 the apcu_dec method on a non-existing object will decrement
120
+         * "0" and result in "-1" as value - therefore we check for existence
121
+         * first
122
+         *
123
+         * on PHP 5.6 this is not the case
124
+         *
125
+         * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221
126
+         * for details
127
+         */
128
+        return apcu_exists($this->getPrefix() . $key)
129
+            ? apcu_dec($this->getPrefix() . $key, $step)
130
+            : false;
131
+    }
132 132
 
133
-	/**
134
-	 * Compare and set
135
-	 *
136
-	 * @param string $key
137
-	 * @param mixed $old
138
-	 * @param mixed $new
139
-	 * @return bool
140
-	 */
141
-	public function cas($key, $old, $new) {
142
-		// apc only does cas for ints
143
-		if (is_int($old) and is_int($new)) {
144
-			return apcu_cas($this->getPrefix() . $key, $old, $new);
145
-		} else {
146
-			return $this->casEmulated($key, $old, $new);
147
-		}
148
-	}
133
+    /**
134
+     * Compare and set
135
+     *
136
+     * @param string $key
137
+     * @param mixed $old
138
+     * @param mixed $new
139
+     * @return bool
140
+     */
141
+    public function cas($key, $old, $new) {
142
+        // apc only does cas for ints
143
+        if (is_int($old) and is_int($new)) {
144
+            return apcu_cas($this->getPrefix() . $key, $old, $new);
145
+        } else {
146
+            return $this->casEmulated($key, $old, $new);
147
+        }
148
+    }
149 149
 
150
-	/**
151
-	 * @return bool
152
-	 */
153
-	static public function isAvailable() {
154
-		if (!extension_loaded('apcu')) {
155
-			return false;
156
-		} elseif (!\OC::$server->getIniWrapper()->getBool('apc.enabled')) {
157
-			return false;
158
-		} elseif (!\OC::$server->getIniWrapper()->getBool('apc.enable_cli') && \OC::$CLI) {
159
-			return false;
160
-		} elseif (
161
-				version_compare(phpversion('apc'), '4.0.6') === -1 &&
162
-				version_compare(phpversion('apcu'), '5.1.0') === -1
163
-		) {
164
-			return false;
165
-		} else {
166
-			return true;
167
-		}
168
-	}
150
+    /**
151
+     * @return bool
152
+     */
153
+    static public function isAvailable() {
154
+        if (!extension_loaded('apcu')) {
155
+            return false;
156
+        } elseif (!\OC::$server->getIniWrapper()->getBool('apc.enabled')) {
157
+            return false;
158
+        } elseif (!\OC::$server->getIniWrapper()->getBool('apc.enable_cli') && \OC::$CLI) {
159
+            return false;
160
+        } elseif (
161
+                version_compare(phpversion('apc'), '4.0.6') === -1 &&
162
+                version_compare(phpversion('apcu'), '5.1.0') === -1
163
+        ) {
164
+            return false;
165
+        } else {
166
+            return true;
167
+        }
168
+    }
169 169
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	use CADTrait;
38 38
 
39 39
 	public function get($key) {
40
-		$result = apcu_fetch($this->getPrefix() . $key, $success);
40
+		$result = apcu_fetch($this->getPrefix().$key, $success);
41 41
 		if (!$success) {
42 42
 			return null;
43 43
 		}
@@ -45,24 +45,24 @@  discard block
 block discarded – undo
45 45
 	}
46 46
 
47 47
 	public function set($key, $value, $ttl = 0) {
48
-		return apcu_store($this->getPrefix() . $key, $value, $ttl);
48
+		return apcu_store($this->getPrefix().$key, $value, $ttl);
49 49
 	}
50 50
 
51 51
 	public function hasKey($key) {
52
-		return apcu_exists($this->getPrefix() . $key);
52
+		return apcu_exists($this->getPrefix().$key);
53 53
 	}
54 54
 
55 55
 	public function remove($key) {
56
-		return apcu_delete($this->getPrefix() . $key);
56
+		return apcu_delete($this->getPrefix().$key);
57 57
 	}
58 58
 
59 59
 	public function clear($prefix = '') {
60
-		$ns = $this->getPrefix() . $prefix;
60
+		$ns = $this->getPrefix().$prefix;
61 61
 		$ns = preg_quote($ns, '/');
62
-		if(class_exists('\APCIterator')) {
63
-			$iter = new \APCIterator('user', '/^' . $ns . '/', APC_ITER_KEY);
62
+		if (class_exists('\APCIterator')) {
63
+			$iter = new \APCIterator('user', '/^'.$ns.'/', APC_ITER_KEY);
64 64
 		} else {
65
-			$iter = new \APCUIterator('/^' . $ns . '/', APC_ITER_KEY);
65
+			$iter = new \APCUIterator('/^'.$ns.'/', APC_ITER_KEY);
66 66
 		}
67 67
 		return apcu_delete($iter);
68 68
 	}
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	 * @return bool
77 77
 	 */
78 78
 	public function add($key, $value, $ttl = 0) {
79
-		return apcu_add($this->getPrefix() . $key, $value, $ttl);
79
+		return apcu_add($this->getPrefix().$key, $value, $ttl);
80 80
 	}
81 81
 
82 82
 	/**
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
 		 * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221
101 101
 		 * for details
102 102
 		 */
103
-		return apcu_exists($this->getPrefix() . $key)
104
-			? apcu_inc($this->getPrefix() . $key, $step)
103
+		return apcu_exists($this->getPrefix().$key)
104
+			? apcu_inc($this->getPrefix().$key, $step)
105 105
 			: false;
106 106
 	}
107 107
 
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
 		 * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221
126 126
 		 * for details
127 127
 		 */
128
-		return apcu_exists($this->getPrefix() . $key)
129
-			? apcu_dec($this->getPrefix() . $key, $step)
128
+		return apcu_exists($this->getPrefix().$key)
129
+			? apcu_dec($this->getPrefix().$key, $step)
130 130
 			: false;
131 131
 	}
132 132
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	public function cas($key, $old, $new) {
142 142
 		// apc only does cas for ints
143 143
 		if (is_int($old) and is_int($new)) {
144
-			return apcu_cas($this->getPrefix() . $key, $old, $new);
144
+			return apcu_cas($this->getPrefix().$key, $old, $new);
145 145
 		} else {
146 146
 			return $this->casEmulated($key, $old, $new);
147 147
 		}
Please login to merge, or discard this patch.
lib/private/Memcache/ArrayCache.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
 	 * Set a value in the cache if it's not already stored
66 66
 	 *
67 67
 	 * @param string $key
68
-	 * @param mixed $value
68
+	 * @param integer $value
69 69
 	 * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
70 70
 	 * @return bool
71 71
 	 */
Please login to merge, or discard this patch.
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -27,133 +27,133 @@
 block discarded – undo
27 27
 use OCP\IMemcache;
28 28
 
29 29
 class ArrayCache extends Cache implements IMemcache {
30
-	/** @var array Array with the cached data */
31
-	protected $cachedData = array();
30
+    /** @var array Array with the cached data */
31
+    protected $cachedData = array();
32 32
 
33
-	use CADTrait;
33
+    use CADTrait;
34 34
 
35
-	/**
36
-	 * {@inheritDoc}
37
-	 */
38
-	public function get($key) {
39
-		if ($this->hasKey($key)) {
40
-			return $this->cachedData[$key];
41
-		}
42
-		return null;
43
-	}
35
+    /**
36
+     * {@inheritDoc}
37
+     */
38
+    public function get($key) {
39
+        if ($this->hasKey($key)) {
40
+            return $this->cachedData[$key];
41
+        }
42
+        return null;
43
+    }
44 44
 
45
-	/**
46
-	 * {@inheritDoc}
47
-	 */
48
-	public function set($key, $value, $ttl = 0) {
49
-		$this->cachedData[$key] = $value;
50
-		return true;
51
-	}
45
+    /**
46
+     * {@inheritDoc}
47
+     */
48
+    public function set($key, $value, $ttl = 0) {
49
+        $this->cachedData[$key] = $value;
50
+        return true;
51
+    }
52 52
 
53
-	/**
54
-	 * {@inheritDoc}
55
-	 */
56
-	public function hasKey($key) {
57
-		return isset($this->cachedData[$key]);
58
-	}
53
+    /**
54
+     * {@inheritDoc}
55
+     */
56
+    public function hasKey($key) {
57
+        return isset($this->cachedData[$key]);
58
+    }
59 59
 
60
-	/**
61
-	 * {@inheritDoc}
62
-	 */
63
-	public function remove($key) {
64
-		unset($this->cachedData[$key]);
65
-		return true;
66
-	}
60
+    /**
61
+     * {@inheritDoc}
62
+     */
63
+    public function remove($key) {
64
+        unset($this->cachedData[$key]);
65
+        return true;
66
+    }
67 67
 
68
-	/**
69
-	 * {@inheritDoc}
70
-	 */
71
-	public function clear($prefix = '') {
72
-		if ($prefix === '') {
73
-			$this->cachedData = [];
74
-			return true;
75
-		}
68
+    /**
69
+     * {@inheritDoc}
70
+     */
71
+    public function clear($prefix = '') {
72
+        if ($prefix === '') {
73
+            $this->cachedData = [];
74
+            return true;
75
+        }
76 76
 
77
-		foreach ($this->cachedData as $key => $value) {
78
-			if (strpos($key, $prefix) === 0) {
79
-				$this->remove($key);
80
-			}
81
-		}
82
-		return true;
83
-	}
77
+        foreach ($this->cachedData as $key => $value) {
78
+            if (strpos($key, $prefix) === 0) {
79
+                $this->remove($key);
80
+            }
81
+        }
82
+        return true;
83
+    }
84 84
 
85
-	/**
86
-	 * Set a value in the cache if it's not already stored
87
-	 *
88
-	 * @param string $key
89
-	 * @param mixed $value
90
-	 * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
91
-	 * @return bool
92
-	 */
93
-	public function add($key, $value, $ttl = 0) {
94
-		// since this cache is not shared race conditions aren't an issue
95
-		if ($this->hasKey($key)) {
96
-			return false;
97
-		} else {
98
-			return $this->set($key, $value, $ttl);
99
-		}
100
-	}
85
+    /**
86
+     * Set a value in the cache if it's not already stored
87
+     *
88
+     * @param string $key
89
+     * @param mixed $value
90
+     * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
91
+     * @return bool
92
+     */
93
+    public function add($key, $value, $ttl = 0) {
94
+        // since this cache is not shared race conditions aren't an issue
95
+        if ($this->hasKey($key)) {
96
+            return false;
97
+        } else {
98
+            return $this->set($key, $value, $ttl);
99
+        }
100
+    }
101 101
 
102
-	/**
103
-	 * Increase a stored number
104
-	 *
105
-	 * @param string $key
106
-	 * @param int $step
107
-	 * @return int | bool
108
-	 */
109
-	public function inc($key, $step = 1) {
110
-		$oldValue = $this->get($key);
111
-		if (is_int($oldValue)) {
112
-			$this->set($key, $oldValue + $step);
113
-			return $oldValue + $step;
114
-		} else {
115
-			$success = $this->add($key, $step);
116
-			return ($success) ? $step : false;
117
-		}
118
-	}
102
+    /**
103
+     * Increase a stored number
104
+     *
105
+     * @param string $key
106
+     * @param int $step
107
+     * @return int | bool
108
+     */
109
+    public function inc($key, $step = 1) {
110
+        $oldValue = $this->get($key);
111
+        if (is_int($oldValue)) {
112
+            $this->set($key, $oldValue + $step);
113
+            return $oldValue + $step;
114
+        } else {
115
+            $success = $this->add($key, $step);
116
+            return ($success) ? $step : false;
117
+        }
118
+    }
119 119
 
120
-	/**
121
-	 * Decrease a stored number
122
-	 *
123
-	 * @param string $key
124
-	 * @param int $step
125
-	 * @return int | bool
126
-	 */
127
-	public function dec($key, $step = 1) {
128
-		$oldValue = $this->get($key);
129
-		if (is_int($oldValue)) {
130
-			$this->set($key, $oldValue - $step);
131
-			return $oldValue - $step;
132
-		} else {
133
-			return false;
134
-		}
135
-	}
120
+    /**
121
+     * Decrease a stored number
122
+     *
123
+     * @param string $key
124
+     * @param int $step
125
+     * @return int | bool
126
+     */
127
+    public function dec($key, $step = 1) {
128
+        $oldValue = $this->get($key);
129
+        if (is_int($oldValue)) {
130
+            $this->set($key, $oldValue - $step);
131
+            return $oldValue - $step;
132
+        } else {
133
+            return false;
134
+        }
135
+    }
136 136
 
137
-	/**
138
-	 * Compare and set
139
-	 *
140
-	 * @param string $key
141
-	 * @param mixed $old
142
-	 * @param mixed $new
143
-	 * @return bool
144
-	 */
145
-	public function cas($key, $old, $new) {
146
-		if ($this->get($key) === $old) {
147
-			return $this->set($key, $new);
148
-		} else {
149
-			return false;
150
-		}
151
-	}
137
+    /**
138
+     * Compare and set
139
+     *
140
+     * @param string $key
141
+     * @param mixed $old
142
+     * @param mixed $new
143
+     * @return bool
144
+     */
145
+    public function cas($key, $old, $new) {
146
+        if ($this->get($key) === $old) {
147
+            return $this->set($key, $new);
148
+        } else {
149
+            return false;
150
+        }
151
+    }
152 152
 
153
-	/**
154
-	 * {@inheritDoc}
155
-	 */
156
-	static public function isAvailable() {
157
-		return true;
158
-	}
153
+    /**
154
+     * {@inheritDoc}
155
+     */
156
+    static public function isAvailable() {
157
+        return true;
158
+    }
159 159
 }
Please login to merge, or discard this patch.
lib/private/User/Session.php 3 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 	 * @param OC\Security\Bruteforce\Throttler $throttler
312 312
 	 * @throws LoginException
313 313
 	 * @throws PasswordLoginForbiddenException
314
-	 * @return boolean
314
+	 * @return boolean|null
315 315
 	 */
316 316
 	public function logClientIn($user,
317 317
 								$password,
@@ -361,6 +361,9 @@  discard block
 block discarded – undo
361 361
 		return $this->config->getSystemValue('token_auth_enforced', false);
362 362
 	}
363 363
 
364
+	/**
365
+	 * @param string $username
366
+	 */
364 367
 	protected function isTwoFactorEnforced($username) {
365 368
 		Util::emitHook(
366 369
 			'\OCA\Files_Sharing\API\Server2Server',
Please login to merge, or discard this patch.
Indentation   +791 added lines, -791 removed lines patch added patch discarded remove patch
@@ -78,797 +78,797 @@
 block discarded – undo
78 78
  */
79 79
 class Session implements IUserSession, Emitter {
80 80
 
81
-	/** @var IUserManager $manager */
82
-	private $manager;
83
-
84
-	/** @var ISession $session */
85
-	private $session;
86
-
87
-	/** @var ITimeFactory */
88
-	private $timeFactory;
89
-
90
-	/** @var IProvider */
91
-	private $tokenProvider;
92
-
93
-	/** @var IConfig */
94
-	private $config;
95
-
96
-	/** @var User $activeUser */
97
-	protected $activeUser;
98
-
99
-	/** @var ISecureRandom */
100
-	private $random;
101
-
102
-	/** @var ILockdownManager  */
103
-	private $lockdownManager;
104
-
105
-	/**
106
-	 * @param IUserManager $manager
107
-	 * @param ISession $session
108
-	 * @param ITimeFactory $timeFactory
109
-	 * @param IProvider $tokenProvider
110
-	 * @param IConfig $config
111
-	 * @param ISecureRandom $random
112
-	 * @param ILockdownManager $lockdownManager
113
-	 */
114
-	public function __construct(IUserManager $manager,
115
-								ISession $session,
116
-								ITimeFactory $timeFactory,
117
-								$tokenProvider,
118
-								IConfig $config,
119
-								ISecureRandom $random,
120
-								ILockdownManager $lockdownManager
121
-	) {
122
-		$this->manager = $manager;
123
-		$this->session = $session;
124
-		$this->timeFactory = $timeFactory;
125
-		$this->tokenProvider = $tokenProvider;
126
-		$this->config = $config;
127
-		$this->random = $random;
128
-		$this->lockdownManager = $lockdownManager;
129
-	}
130
-
131
-	/**
132
-	 * @param IProvider $provider
133
-	 */
134
-	public function setTokenProvider(IProvider $provider) {
135
-		$this->tokenProvider = $provider;
136
-	}
137
-
138
-	/**
139
-	 * @param string $scope
140
-	 * @param string $method
141
-	 * @param callable $callback
142
-	 */
143
-	public function listen($scope, $method, callable $callback) {
144
-		$this->manager->listen($scope, $method, $callback);
145
-	}
146
-
147
-	/**
148
-	 * @param string $scope optional
149
-	 * @param string $method optional
150
-	 * @param callable $callback optional
151
-	 */
152
-	public function removeListener($scope = null, $method = null, callable $callback = null) {
153
-		$this->manager->removeListener($scope, $method, $callback);
154
-	}
155
-
156
-	/**
157
-	 * get the manager object
158
-	 *
159
-	 * @return Manager
160
-	 */
161
-	public function getManager() {
162
-		return $this->manager;
163
-	}
164
-
165
-	/**
166
-	 * get the session object
167
-	 *
168
-	 * @return ISession
169
-	 */
170
-	public function getSession() {
171
-		return $this->session;
172
-	}
173
-
174
-	/**
175
-	 * set the session object
176
-	 *
177
-	 * @param ISession $session
178
-	 */
179
-	public function setSession(ISession $session) {
180
-		if ($this->session instanceof ISession) {
181
-			$this->session->close();
182
-		}
183
-		$this->session = $session;
184
-		$this->activeUser = null;
185
-	}
186
-
187
-	/**
188
-	 * set the currently active user
189
-	 *
190
-	 * @param IUser|null $user
191
-	 */
192
-	public function setUser($user) {
193
-		if (is_null($user)) {
194
-			$this->session->remove('user_id');
195
-		} else {
196
-			$this->session->set('user_id', $user->getUID());
197
-		}
198
-		$this->activeUser = $user;
199
-	}
200
-
201
-	/**
202
-	 * get the current active user
203
-	 *
204
-	 * @return IUser|null Current user, otherwise null
205
-	 */
206
-	public function getUser() {
207
-		// FIXME: This is a quick'n dirty work-around for the incognito mode as
208
-		// described at https://github.com/owncloud/core/pull/12912#issuecomment-67391155
209
-		if (OC_User::isIncognitoMode()) {
210
-			return null;
211
-		}
212
-		if (is_null($this->activeUser)) {
213
-			$uid = $this->session->get('user_id');
214
-			if (is_null($uid)) {
215
-				return null;
216
-			}
217
-			$this->activeUser = $this->manager->get($uid);
218
-			if (is_null($this->activeUser)) {
219
-				return null;
220
-			}
221
-			$this->validateSession();
222
-		}
223
-		return $this->activeUser;
224
-	}
225
-
226
-	/**
227
-	 * Validate whether the current session is valid
228
-	 *
229
-	 * - For token-authenticated clients, the token validity is checked
230
-	 * - For browsers, the session token validity is checked
231
-	 */
232
-	protected function validateSession() {
233
-		$token = null;
234
-		$appPassword = $this->session->get('app_password');
235
-
236
-		if (is_null($appPassword)) {
237
-			try {
238
-				$token = $this->session->getId();
239
-			} catch (SessionNotAvailableException $ex) {
240
-				return;
241
-			}
242
-		} else {
243
-			$token = $appPassword;
244
-		}
245
-
246
-		if (!$this->validateToken($token)) {
247
-			// Session was invalidated
248
-			$this->logout();
249
-		}
250
-	}
251
-
252
-	/**
253
-	 * Checks whether the user is logged in
254
-	 *
255
-	 * @return bool if logged in
256
-	 */
257
-	public function isLoggedIn() {
258
-		$user = $this->getUser();
259
-		if (is_null($user)) {
260
-			return false;
261
-		}
262
-
263
-		return $user->isEnabled();
264
-	}
265
-
266
-	/**
267
-	 * set the login name
268
-	 *
269
-	 * @param string|null $loginName for the logged in user
270
-	 */
271
-	public function setLoginName($loginName) {
272
-		if (is_null($loginName)) {
273
-			$this->session->remove('loginname');
274
-		} else {
275
-			$this->session->set('loginname', $loginName);
276
-		}
277
-	}
278
-
279
-	/**
280
-	 * get the login name of the current user
281
-	 *
282
-	 * @return string
283
-	 */
284
-	public function getLoginName() {
285
-		if ($this->activeUser) {
286
-			return $this->session->get('loginname');
287
-		} else {
288
-			$uid = $this->session->get('user_id');
289
-			if ($uid) {
290
-				$this->activeUser = $this->manager->get($uid);
291
-				return $this->session->get('loginname');
292
-			} else {
293
-				return null;
294
-			}
295
-		}
296
-	}
297
-
298
-	/**
299
-	 * set the token id
300
-	 *
301
-	 * @param int|null $token that was used to log in
302
-	 */
303
-	protected function setToken($token) {
304
-		if ($token === null) {
305
-			$this->session->remove('token-id');
306
-		} else {
307
-			$this->session->set('token-id', $token);
308
-		}
309
-	}
310
-
311
-	/**
312
-	 * try to log in with the provided credentials
313
-	 *
314
-	 * @param string $uid
315
-	 * @param string $password
316
-	 * @return boolean|null
317
-	 * @throws LoginException
318
-	 */
319
-	public function login($uid, $password) {
320
-		$this->session->regenerateId();
321
-		if ($this->validateToken($password, $uid)) {
322
-			return $this->loginWithToken($password);
323
-		}
324
-		return $this->loginWithPassword($uid, $password);
325
-	}
326
-
327
-	/**
328
-	 * Tries to log in a client
329
-	 *
330
-	 * Checks token auth enforced
331
-	 * Checks 2FA enabled
332
-	 *
333
-	 * @param string $user
334
-	 * @param string $password
335
-	 * @param IRequest $request
336
-	 * @param OC\Security\Bruteforce\Throttler $throttler
337
-	 * @throws LoginException
338
-	 * @throws PasswordLoginForbiddenException
339
-	 * @return boolean
340
-	 */
341
-	public function logClientIn($user,
342
-								$password,
343
-								IRequest $request,
344
-								OC\Security\Bruteforce\Throttler $throttler) {
345
-		$currentDelay = $throttler->sleepDelay($request->getRemoteAddress(), 'login');
346
-
347
-		if ($this->manager instanceof PublicEmitter) {
348
-			$this->manager->emit('\OC\User', 'preLogin', array($user, $password));
349
-		}
350
-
351
-		$isTokenPassword = $this->isTokenPassword($password);
352
-		if (!$isTokenPassword && $this->isTokenAuthEnforced()) {
353
-			throw new PasswordLoginForbiddenException();
354
-		}
355
-		if (!$isTokenPassword && $this->isTwoFactorEnforced($user)) {
356
-			throw new PasswordLoginForbiddenException();
357
-		}
358
-		if (!$this->login($user, $password) ) {
359
-			$users = $this->manager->getByEmail($user);
360
-			if (count($users) === 1) {
361
-				return $this->login($users[0]->getUID(), $password);
362
-			}
363
-
364
-			$throttler->registerAttempt('login', $request->getRemoteAddress(), ['uid' => $user]);
365
-			if($currentDelay === 0) {
366
-				$throttler->sleepDelay($request->getRemoteAddress(), 'login');
367
-			}
368
-			return false;
369
-		}
370
-
371
-		if ($isTokenPassword) {
372
-			$this->session->set('app_password', $password);
373
-		} else if($this->supportsCookies($request)) {
374
-			// Password login, but cookies supported -> create (browser) session token
375
-			$this->createSessionToken($request, $this->getUser()->getUID(), $user, $password);
376
-		}
377
-
378
-		return true;
379
-	}
380
-
381
-	protected function supportsCookies(IRequest $request) {
382
-		if (!is_null($request->getCookie('cookie_test'))) {
383
-			return true;
384
-		}
385
-		setcookie('cookie_test', 'test', $this->timeFactory->getTime() + 3600);
386
-		return false;
387
-	}
388
-
389
-	private function isTokenAuthEnforced() {
390
-		return $this->config->getSystemValue('token_auth_enforced', false);
391
-	}
392
-
393
-	protected function isTwoFactorEnforced($username) {
394
-		Util::emitHook(
395
-			'\OCA\Files_Sharing\API\Server2Server',
396
-			'preLoginNameUsedAsUserName',
397
-			array('uid' => &$username)
398
-		);
399
-		$user = $this->manager->get($username);
400
-		if (is_null($user)) {
401
-			$users = $this->manager->getByEmail($username);
402
-			if (empty($users)) {
403
-				return false;
404
-			}
405
-			if (count($users) !== 1) {
406
-				return true;
407
-			}
408
-			$user = $users[0];
409
-		}
410
-		// DI not possible due to cyclic dependencies :'-/
411
-		return OC::$server->getTwoFactorAuthManager()->isTwoFactorAuthenticated($user);
412
-	}
413
-
414
-	/**
415
-	 * Check if the given 'password' is actually a device token
416
-	 *
417
-	 * @param string $password
418
-	 * @return boolean
419
-	 */
420
-	public function isTokenPassword($password) {
421
-		try {
422
-			$this->tokenProvider->getToken($password);
423
-			return true;
424
-		} catch (InvalidTokenException $ex) {
425
-			return false;
426
-		}
427
-	}
428
-
429
-	protected function prepareUserLogin($firstTimeLogin) {
430
-		// TODO: mock/inject/use non-static
431
-		// Refresh the token
432
-		\OC::$server->getCsrfTokenManager()->refreshToken();
433
-		//we need to pass the user name, which may differ from login name
434
-		$user = $this->getUser()->getUID();
435
-		OC_Util::setupFS($user);
436
-
437
-		if ($firstTimeLogin) {
438
-			// TODO: lock necessary?
439
-			//trigger creation of user home and /files folder
440
-			$userFolder = \OC::$server->getUserFolder($user);
441
-
442
-			// copy skeleton
443
-			\OC_Util::copySkeleton($user, $userFolder);
444
-
445
-			// trigger any other initialization
446
-			\OC::$server->getEventDispatcher()->dispatch(IUser::class . '::firstLogin', new GenericEvent($this->getUser()));
447
-		}
448
-	}
449
-
450
-	/**
451
-	 * Tries to login the user with HTTP Basic Authentication
452
-	 *
453
-	 * @todo do not allow basic auth if the user is 2FA enforced
454
-	 * @param IRequest $request
455
-	 * @param OC\Security\Bruteforce\Throttler $throttler
456
-	 * @return boolean if the login was successful
457
-	 */
458
-	public function tryBasicAuthLogin(IRequest $request,
459
-									  OC\Security\Bruteforce\Throttler $throttler) {
460
-		if (!empty($request->server['PHP_AUTH_USER']) && !empty($request->server['PHP_AUTH_PW'])) {
461
-			try {
462
-				if ($this->logClientIn($request->server['PHP_AUTH_USER'], $request->server['PHP_AUTH_PW'], $request, $throttler)) {
463
-					/**
464
-					 * Add DAV authenticated. This should in an ideal world not be
465
-					 * necessary but the iOS App reads cookies from anywhere instead
466
-					 * only the DAV endpoint.
467
-					 * This makes sure that the cookies will be valid for the whole scope
468
-					 * @see https://github.com/owncloud/core/issues/22893
469
-					 */
470
-					$this->session->set(
471
-						Auth::DAV_AUTHENTICATED, $this->getUser()->getUID()
472
-					);
473
-
474
-					// Set the last-password-confirm session to make the sudo mode work
475
-					 $this->session->set('last-password-confirm', $this->timeFactory->getTime());
476
-
477
-					return true;
478
-				}
479
-			} catch (PasswordLoginForbiddenException $ex) {
480
-				// Nothing to do
481
-			}
482
-		}
483
-		return false;
484
-	}
485
-
486
-	/**
487
-	 * Log an user in via login name and password
488
-	 *
489
-	 * @param string $uid
490
-	 * @param string $password
491
-	 * @return boolean
492
-	 * @throws LoginException if an app canceld the login process or the user is not enabled
493
-	 */
494
-	private function loginWithPassword($uid, $password) {
495
-		$user = $this->manager->checkPassword($uid, $password);
496
-		if ($user === false) {
497
-			// Password check failed
498
-			return false;
499
-		}
500
-
501
-		if ($user->isEnabled()) {
502
-			$this->setUser($user);
503
-			$this->setLoginName($uid);
504
-			$this->setToken(null);
505
-			$firstTimeLogin = $user->updateLastLoginTimestamp();
506
-			$this->manager->emit('\OC\User', 'postLogin', [$user, $password]);
507
-			if ($this->isLoggedIn()) {
508
-				$this->prepareUserLogin($firstTimeLogin);
509
-				return true;
510
-			} else {
511
-				// injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory
512
-				$message = \OC::$server->getL10N('lib')->t('Login canceled by app');
513
-				throw new LoginException($message);
514
-			}
515
-		} else {
516
-			// injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory
517
-			$message = \OC::$server->getL10N('lib')->t('User disabled');
518
-			throw new LoginException($message);
519
-		}
520
-	}
521
-
522
-	/**
523
-	 * Log an user in with a given token (id)
524
-	 *
525
-	 * @param string $token
526
-	 * @return boolean
527
-	 * @throws LoginException if an app canceled the login process or the user is not enabled
528
-	 */
529
-	private function loginWithToken($token) {
530
-		try {
531
-			$dbToken = $this->tokenProvider->getToken($token);
532
-		} catch (InvalidTokenException $ex) {
533
-			return false;
534
-		}
535
-		$uid = $dbToken->getUID();
536
-
537
-		// When logging in with token, the password must be decrypted first before passing to login hook
538
-		$password = '';
539
-		try {
540
-			$password = $this->tokenProvider->getPassword($dbToken, $token);
541
-		} catch (PasswordlessTokenException $ex) {
542
-			// Ignore and use empty string instead
543
-		}
544
-
545
-		$user = $this->manager->get($uid);
546
-		if (is_null($user)) {
547
-			// user does not exist
548
-			return false;
549
-		}
550
-		if (!$user->isEnabled()) {
551
-			// disabled users can not log in
552
-			// injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory
553
-			$message = \OC::$server->getL10N('lib')->t('User disabled');
554
-			throw new LoginException($message);
555
-		}
556
-
557
-		//login
558
-		$this->setUser($user);
559
-		$this->setLoginName($dbToken->getLoginName());
560
-		$this->setToken($dbToken->getId());
561
-		$this->lockdownManager->setToken($dbToken);
562
-		$this->manager->emit('\OC\User', 'postLogin', array($user, $password));
563
-
564
-		if ($this->isLoggedIn()) {
565
-			$this->prepareUserLogin(false); // token login cant be the first
566
-		} else {
567
-			// injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory
568
-			$message = \OC::$server->getL10N('lib')->t('Login canceled by app');
569
-			throw new LoginException($message);
570
-		}
571
-
572
-		return true;
573
-	}
574
-
575
-	/**
576
-	 * Create a new session token for the given user credentials
577
-	 *
578
-	 * @param IRequest $request
579
-	 * @param string $uid user UID
580
-	 * @param string $loginName login name
581
-	 * @param string $password
582
-	 * @param int $remember
583
-	 * @return boolean
584
-	 */
585
-	public function createSessionToken(IRequest $request, $uid, $loginName, $password = null, $remember = IToken::DO_NOT_REMEMBER) {
586
-		if (is_null($this->manager->get($uid))) {
587
-			// User does not exist
588
-			return false;
589
-		}
590
-		$name = isset($request->server['HTTP_USER_AGENT']) ? $request->server['HTTP_USER_AGENT'] : 'unknown browser';
591
-		try {
592
-			$sessionId = $this->session->getId();
593
-			$pwd = $this->getPassword($password);
594
-			$this->tokenProvider->generateToken($sessionId, $uid, $loginName, $pwd, $name, IToken::TEMPORARY_TOKEN, $remember);
595
-			return true;
596
-		} catch (SessionNotAvailableException $ex) {
597
-			// This can happen with OCC, where a memory session is used
598
-			// if a memory session is used, we shouldn't create a session token anyway
599
-			return false;
600
-		}
601
-	}
602
-
603
-	/**
604
-	 * Checks if the given password is a token.
605
-	 * If yes, the password is extracted from the token.
606
-	 * If no, the same password is returned.
607
-	 *
608
-	 * @param string $password either the login password or a device token
609
-	 * @return string|null the password or null if none was set in the token
610
-	 */
611
-	private function getPassword($password) {
612
-		if (is_null($password)) {
613
-			// This is surely no token ;-)
614
-			return null;
615
-		}
616
-		try {
617
-			$token = $this->tokenProvider->getToken($password);
618
-			try {
619
-				return $this->tokenProvider->getPassword($token, $password);
620
-			} catch (PasswordlessTokenException $ex) {
621
-				return null;
622
-			}
623
-		} catch (InvalidTokenException $ex) {
624
-			return $password;
625
-		}
626
-	}
627
-
628
-	/**
629
-	 * @param IToken $dbToken
630
-	 * @param string $token
631
-	 * @return boolean
632
-	 */
633
-	private function checkTokenCredentials(IToken $dbToken, $token) {
634
-		// Check whether login credentials are still valid and the user was not disabled
635
-		// This check is performed each 5 minutes
636
-		$lastCheck = $dbToken->getLastCheck() ? : 0;
637
-		$now = $this->timeFactory->getTime();
638
-		if ($lastCheck > ($now - 60 * 5)) {
639
-			// Checked performed recently, nothing to do now
640
-			return true;
641
-		}
642
-
643
-		try {
644
-			$pwd = $this->tokenProvider->getPassword($dbToken, $token);
645
-		} catch (InvalidTokenException $ex) {
646
-			// An invalid token password was used -> log user out
647
-			return false;
648
-		} catch (PasswordlessTokenException $ex) {
649
-			// Token has no password
650
-
651
-			if (!is_null($this->activeUser) && !$this->activeUser->isEnabled()) {
652
-				$this->tokenProvider->invalidateToken($token);
653
-				return false;
654
-			}
655
-
656
-			$dbToken->setLastCheck($now);
657
-			return true;
658
-		}
659
-
660
-		if ($this->manager->checkPassword($dbToken->getLoginName(), $pwd) === false
661
-			|| (!is_null($this->activeUser) && !$this->activeUser->isEnabled())) {
662
-			$this->tokenProvider->invalidateToken($token);
663
-			// Password has changed or user was disabled -> log user out
664
-			return false;
665
-		}
666
-		$dbToken->setLastCheck($now);
667
-		return true;
668
-	}
669
-
670
-	/**
671
-	 * Check if the given token exists and performs password/user-enabled checks
672
-	 *
673
-	 * Invalidates the token if checks fail
674
-	 *
675
-	 * @param string $token
676
-	 * @param string $user login name
677
-	 * @return boolean
678
-	 */
679
-	private function validateToken($token, $user = null) {
680
-		try {
681
-			$dbToken = $this->tokenProvider->getToken($token);
682
-		} catch (InvalidTokenException $ex) {
683
-			return false;
684
-		}
685
-
686
-		// Check if login names match
687
-		if (!is_null($user) && $dbToken->getLoginName() !== $user) {
688
-			// TODO: this makes it imposssible to use different login names on browser and client
689
-			// e.g. login by e-mail '[email protected]' on browser for generating the token will not
690
-			//      allow to use the client token with the login name 'user'.
691
-			return false;
692
-		}
693
-
694
-		if (!$this->checkTokenCredentials($dbToken, $token)) {
695
-			return false;
696
-		}
697
-
698
-		$this->tokenProvider->updateTokenActivity($dbToken);
699
-
700
-		return true;
701
-	}
702
-
703
-	/**
704
-	 * Tries to login the user with auth token header
705
-	 *
706
-	 * @param IRequest $request
707
-	 * @todo check remember me cookie
708
-	 * @return boolean
709
-	 */
710
-	public function tryTokenLogin(IRequest $request) {
711
-		$authHeader = $request->getHeader('Authorization');
712
-		if (strpos($authHeader, 'token ') === false) {
713
-			// No auth header, let's try session id
714
-			try {
715
-				$token = $this->session->getId();
716
-			} catch (SessionNotAvailableException $ex) {
717
-				return false;
718
-			}
719
-		} else {
720
-			$token = substr($authHeader, 6);
721
-		}
722
-
723
-		if (!$this->loginWithToken($token)) {
724
-			return false;
725
-		}
726
-		if(!$this->validateToken($token)) {
727
-			return false;
728
-		}
729
-		return true;
730
-	}
731
-
732
-	/**
733
-	 * perform login using the magic cookie (remember login)
734
-	 *
735
-	 * @param string $uid the username
736
-	 * @param string $currentToken
737
-	 * @param string $oldSessionId
738
-	 * @return bool
739
-	 */
740
-	public function loginWithCookie($uid, $currentToken, $oldSessionId) {
741
-		$this->session->regenerateId();
742
-		$this->manager->emit('\OC\User', 'preRememberedLogin', array($uid));
743
-		$user = $this->manager->get($uid);
744
-		if (is_null($user)) {
745
-			// user does not exist
746
-			return false;
747
-		}
748
-
749
-		// get stored tokens
750
-		$tokens = $this->config->getUserKeys($uid, 'login_token');
751
-		// test cookies token against stored tokens
752
-		if (!in_array($currentToken, $tokens, true)) {
753
-			return false;
754
-		}
755
-		// replace successfully used token with a new one
756
-		$this->config->deleteUserValue($uid, 'login_token', $currentToken);
757
-		$newToken = $this->random->generate(32);
758
-		$this->config->setUserValue($uid, 'login_token', $newToken, $this->timeFactory->getTime());
759
-
760
-		try {
761
-			$sessionId = $this->session->getId();
762
-			$this->tokenProvider->renewSessionToken($oldSessionId, $sessionId);
763
-		} catch (SessionNotAvailableException $ex) {
764
-			return false;
765
-		} catch (InvalidTokenException $ex) {
766
-			\OC::$server->getLogger()->warning('Renewing session token failed', ['app' => 'core']);
767
-			return false;
768
-		}
769
-
770
-		$this->setMagicInCookie($user->getUID(), $newToken);
771
-		$token = $this->tokenProvider->getToken($sessionId);
772
-
773
-		//login
774
-		$this->setUser($user);
775
-		$this->setLoginName($token->getLoginName());
776
-		$this->setToken($token->getId());
777
-		$this->lockdownManager->setToken($token);
778
-		$user->updateLastLoginTimestamp();
779
-		$this->manager->emit('\OC\User', 'postRememberedLogin', [$user]);
780
-		return true;
781
-	}
782
-
783
-	/**
784
-	 * @param IUser $user
785
-	 */
786
-	public function createRememberMeToken(IUser $user) {
787
-		$token = $this->random->generate(32);
788
-		$this->config->setUserValue($user->getUID(), 'login_token', $token, $this->timeFactory->getTime());
789
-		$this->setMagicInCookie($user->getUID(), $token);
790
-	}
791
-
792
-	/**
793
-	 * logout the user from the session
794
-	 */
795
-	public function logout() {
796
-		$this->manager->emit('\OC\User', 'logout');
797
-		$user = $this->getUser();
798
-		if (!is_null($user)) {
799
-			try {
800
-				$this->tokenProvider->invalidateToken($this->session->getId());
801
-			} catch (SessionNotAvailableException $ex) {
802
-
803
-			}
804
-		}
805
-		$this->setUser(null);
806
-		$this->setLoginName(null);
807
-		$this->setToken(null);
808
-		$this->unsetMagicInCookie();
809
-		$this->session->clear();
810
-		$this->manager->emit('\OC\User', 'postLogout');
811
-	}
812
-
813
-	/**
814
-	 * Set cookie value to use in next page load
815
-	 *
816
-	 * @param string $username username to be set
817
-	 * @param string $token
818
-	 */
819
-	public function setMagicInCookie($username, $token) {
820
-		$secureCookie = OC::$server->getRequest()->getServerProtocol() === 'https';
821
-		$webRoot = \OC::$WEBROOT;
822
-		if ($webRoot === '') {
823
-			$webRoot = '/';
824
-		}
825
-
826
-		$expires = $this->timeFactory->getTime() + $this->config->getSystemValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15);
827
-		setcookie('nc_username', $username, $expires, $webRoot, '', $secureCookie, true);
828
-		setcookie('nc_token', $token, $expires, $webRoot, '', $secureCookie, true);
829
-		try {
830
-			setcookie('nc_session_id', $this->session->getId(), $expires, $webRoot, '', $secureCookie, true);
831
-		} catch (SessionNotAvailableException $ex) {
832
-			// ignore
833
-		}
834
-	}
835
-
836
-	/**
837
-	 * Remove cookie for "remember username"
838
-	 */
839
-	public function unsetMagicInCookie() {
840
-		//TODO: DI for cookies and IRequest
841
-		$secureCookie = OC::$server->getRequest()->getServerProtocol() === 'https';
842
-
843
-		unset($_COOKIE['nc_username']); //TODO: DI
844
-		unset($_COOKIE['nc_token']);
845
-		unset($_COOKIE['nc_session_id']);
846
-		setcookie('nc_username', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT, '', $secureCookie, true);
847
-		setcookie('nc_token', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT, '', $secureCookie, true);
848
-		setcookie('nc_session_id', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT, '', $secureCookie, true);
849
-		// old cookies might be stored under /webroot/ instead of /webroot
850
-		// and Firefox doesn't like it!
851
-		setcookie('nc_username', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT . '/', '', $secureCookie, true);
852
-		setcookie('nc_token', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT . '/', '', $secureCookie, true);
853
-		setcookie('nc_session_id', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT . '/', '', $secureCookie, true);
854
-	}
855
-
856
-	/**
857
-	 * Update password of the browser session token if there is one
858
-	 *
859
-	 * @param string $password
860
-	 */
861
-	public function updateSessionTokenPassword($password) {
862
-		try {
863
-			$sessionId = $this->session->getId();
864
-			$token = $this->tokenProvider->getToken($sessionId);
865
-			$this->tokenProvider->setPassword($token, $sessionId, $password);
866
-		} catch (SessionNotAvailableException $ex) {
867
-			// Nothing to do
868
-		} catch (InvalidTokenException $ex) {
869
-			// Nothing to do
870
-		}
871
-	}
81
+    /** @var IUserManager $manager */
82
+    private $manager;
83
+
84
+    /** @var ISession $session */
85
+    private $session;
86
+
87
+    /** @var ITimeFactory */
88
+    private $timeFactory;
89
+
90
+    /** @var IProvider */
91
+    private $tokenProvider;
92
+
93
+    /** @var IConfig */
94
+    private $config;
95
+
96
+    /** @var User $activeUser */
97
+    protected $activeUser;
98
+
99
+    /** @var ISecureRandom */
100
+    private $random;
101
+
102
+    /** @var ILockdownManager  */
103
+    private $lockdownManager;
104
+
105
+    /**
106
+     * @param IUserManager $manager
107
+     * @param ISession $session
108
+     * @param ITimeFactory $timeFactory
109
+     * @param IProvider $tokenProvider
110
+     * @param IConfig $config
111
+     * @param ISecureRandom $random
112
+     * @param ILockdownManager $lockdownManager
113
+     */
114
+    public function __construct(IUserManager $manager,
115
+                                ISession $session,
116
+                                ITimeFactory $timeFactory,
117
+                                $tokenProvider,
118
+                                IConfig $config,
119
+                                ISecureRandom $random,
120
+                                ILockdownManager $lockdownManager
121
+    ) {
122
+        $this->manager = $manager;
123
+        $this->session = $session;
124
+        $this->timeFactory = $timeFactory;
125
+        $this->tokenProvider = $tokenProvider;
126
+        $this->config = $config;
127
+        $this->random = $random;
128
+        $this->lockdownManager = $lockdownManager;
129
+    }
130
+
131
+    /**
132
+     * @param IProvider $provider
133
+     */
134
+    public function setTokenProvider(IProvider $provider) {
135
+        $this->tokenProvider = $provider;
136
+    }
137
+
138
+    /**
139
+     * @param string $scope
140
+     * @param string $method
141
+     * @param callable $callback
142
+     */
143
+    public function listen($scope, $method, callable $callback) {
144
+        $this->manager->listen($scope, $method, $callback);
145
+    }
146
+
147
+    /**
148
+     * @param string $scope optional
149
+     * @param string $method optional
150
+     * @param callable $callback optional
151
+     */
152
+    public function removeListener($scope = null, $method = null, callable $callback = null) {
153
+        $this->manager->removeListener($scope, $method, $callback);
154
+    }
155
+
156
+    /**
157
+     * get the manager object
158
+     *
159
+     * @return Manager
160
+     */
161
+    public function getManager() {
162
+        return $this->manager;
163
+    }
164
+
165
+    /**
166
+     * get the session object
167
+     *
168
+     * @return ISession
169
+     */
170
+    public function getSession() {
171
+        return $this->session;
172
+    }
173
+
174
+    /**
175
+     * set the session object
176
+     *
177
+     * @param ISession $session
178
+     */
179
+    public function setSession(ISession $session) {
180
+        if ($this->session instanceof ISession) {
181
+            $this->session->close();
182
+        }
183
+        $this->session = $session;
184
+        $this->activeUser = null;
185
+    }
186
+
187
+    /**
188
+     * set the currently active user
189
+     *
190
+     * @param IUser|null $user
191
+     */
192
+    public function setUser($user) {
193
+        if (is_null($user)) {
194
+            $this->session->remove('user_id');
195
+        } else {
196
+            $this->session->set('user_id', $user->getUID());
197
+        }
198
+        $this->activeUser = $user;
199
+    }
200
+
201
+    /**
202
+     * get the current active user
203
+     *
204
+     * @return IUser|null Current user, otherwise null
205
+     */
206
+    public function getUser() {
207
+        // FIXME: This is a quick'n dirty work-around for the incognito mode as
208
+        // described at https://github.com/owncloud/core/pull/12912#issuecomment-67391155
209
+        if (OC_User::isIncognitoMode()) {
210
+            return null;
211
+        }
212
+        if (is_null($this->activeUser)) {
213
+            $uid = $this->session->get('user_id');
214
+            if (is_null($uid)) {
215
+                return null;
216
+            }
217
+            $this->activeUser = $this->manager->get($uid);
218
+            if (is_null($this->activeUser)) {
219
+                return null;
220
+            }
221
+            $this->validateSession();
222
+        }
223
+        return $this->activeUser;
224
+    }
225
+
226
+    /**
227
+     * Validate whether the current session is valid
228
+     *
229
+     * - For token-authenticated clients, the token validity is checked
230
+     * - For browsers, the session token validity is checked
231
+     */
232
+    protected function validateSession() {
233
+        $token = null;
234
+        $appPassword = $this->session->get('app_password');
235
+
236
+        if (is_null($appPassword)) {
237
+            try {
238
+                $token = $this->session->getId();
239
+            } catch (SessionNotAvailableException $ex) {
240
+                return;
241
+            }
242
+        } else {
243
+            $token = $appPassword;
244
+        }
245
+
246
+        if (!$this->validateToken($token)) {
247
+            // Session was invalidated
248
+            $this->logout();
249
+        }
250
+    }
251
+
252
+    /**
253
+     * Checks whether the user is logged in
254
+     *
255
+     * @return bool if logged in
256
+     */
257
+    public function isLoggedIn() {
258
+        $user = $this->getUser();
259
+        if (is_null($user)) {
260
+            return false;
261
+        }
262
+
263
+        return $user->isEnabled();
264
+    }
265
+
266
+    /**
267
+     * set the login name
268
+     *
269
+     * @param string|null $loginName for the logged in user
270
+     */
271
+    public function setLoginName($loginName) {
272
+        if (is_null($loginName)) {
273
+            $this->session->remove('loginname');
274
+        } else {
275
+            $this->session->set('loginname', $loginName);
276
+        }
277
+    }
278
+
279
+    /**
280
+     * get the login name of the current user
281
+     *
282
+     * @return string
283
+     */
284
+    public function getLoginName() {
285
+        if ($this->activeUser) {
286
+            return $this->session->get('loginname');
287
+        } else {
288
+            $uid = $this->session->get('user_id');
289
+            if ($uid) {
290
+                $this->activeUser = $this->manager->get($uid);
291
+                return $this->session->get('loginname');
292
+            } else {
293
+                return null;
294
+            }
295
+        }
296
+    }
297
+
298
+    /**
299
+     * set the token id
300
+     *
301
+     * @param int|null $token that was used to log in
302
+     */
303
+    protected function setToken($token) {
304
+        if ($token === null) {
305
+            $this->session->remove('token-id');
306
+        } else {
307
+            $this->session->set('token-id', $token);
308
+        }
309
+    }
310
+
311
+    /**
312
+     * try to log in with the provided credentials
313
+     *
314
+     * @param string $uid
315
+     * @param string $password
316
+     * @return boolean|null
317
+     * @throws LoginException
318
+     */
319
+    public function login($uid, $password) {
320
+        $this->session->regenerateId();
321
+        if ($this->validateToken($password, $uid)) {
322
+            return $this->loginWithToken($password);
323
+        }
324
+        return $this->loginWithPassword($uid, $password);
325
+    }
326
+
327
+    /**
328
+     * Tries to log in a client
329
+     *
330
+     * Checks token auth enforced
331
+     * Checks 2FA enabled
332
+     *
333
+     * @param string $user
334
+     * @param string $password
335
+     * @param IRequest $request
336
+     * @param OC\Security\Bruteforce\Throttler $throttler
337
+     * @throws LoginException
338
+     * @throws PasswordLoginForbiddenException
339
+     * @return boolean
340
+     */
341
+    public function logClientIn($user,
342
+                                $password,
343
+                                IRequest $request,
344
+                                OC\Security\Bruteforce\Throttler $throttler) {
345
+        $currentDelay = $throttler->sleepDelay($request->getRemoteAddress(), 'login');
346
+
347
+        if ($this->manager instanceof PublicEmitter) {
348
+            $this->manager->emit('\OC\User', 'preLogin', array($user, $password));
349
+        }
350
+
351
+        $isTokenPassword = $this->isTokenPassword($password);
352
+        if (!$isTokenPassword && $this->isTokenAuthEnforced()) {
353
+            throw new PasswordLoginForbiddenException();
354
+        }
355
+        if (!$isTokenPassword && $this->isTwoFactorEnforced($user)) {
356
+            throw new PasswordLoginForbiddenException();
357
+        }
358
+        if (!$this->login($user, $password) ) {
359
+            $users = $this->manager->getByEmail($user);
360
+            if (count($users) === 1) {
361
+                return $this->login($users[0]->getUID(), $password);
362
+            }
363
+
364
+            $throttler->registerAttempt('login', $request->getRemoteAddress(), ['uid' => $user]);
365
+            if($currentDelay === 0) {
366
+                $throttler->sleepDelay($request->getRemoteAddress(), 'login');
367
+            }
368
+            return false;
369
+        }
370
+
371
+        if ($isTokenPassword) {
372
+            $this->session->set('app_password', $password);
373
+        } else if($this->supportsCookies($request)) {
374
+            // Password login, but cookies supported -> create (browser) session token
375
+            $this->createSessionToken($request, $this->getUser()->getUID(), $user, $password);
376
+        }
377
+
378
+        return true;
379
+    }
380
+
381
+    protected function supportsCookies(IRequest $request) {
382
+        if (!is_null($request->getCookie('cookie_test'))) {
383
+            return true;
384
+        }
385
+        setcookie('cookie_test', 'test', $this->timeFactory->getTime() + 3600);
386
+        return false;
387
+    }
388
+
389
+    private function isTokenAuthEnforced() {
390
+        return $this->config->getSystemValue('token_auth_enforced', false);
391
+    }
392
+
393
+    protected function isTwoFactorEnforced($username) {
394
+        Util::emitHook(
395
+            '\OCA\Files_Sharing\API\Server2Server',
396
+            'preLoginNameUsedAsUserName',
397
+            array('uid' => &$username)
398
+        );
399
+        $user = $this->manager->get($username);
400
+        if (is_null($user)) {
401
+            $users = $this->manager->getByEmail($username);
402
+            if (empty($users)) {
403
+                return false;
404
+            }
405
+            if (count($users) !== 1) {
406
+                return true;
407
+            }
408
+            $user = $users[0];
409
+        }
410
+        // DI not possible due to cyclic dependencies :'-/
411
+        return OC::$server->getTwoFactorAuthManager()->isTwoFactorAuthenticated($user);
412
+    }
413
+
414
+    /**
415
+     * Check if the given 'password' is actually a device token
416
+     *
417
+     * @param string $password
418
+     * @return boolean
419
+     */
420
+    public function isTokenPassword($password) {
421
+        try {
422
+            $this->tokenProvider->getToken($password);
423
+            return true;
424
+        } catch (InvalidTokenException $ex) {
425
+            return false;
426
+        }
427
+    }
428
+
429
+    protected function prepareUserLogin($firstTimeLogin) {
430
+        // TODO: mock/inject/use non-static
431
+        // Refresh the token
432
+        \OC::$server->getCsrfTokenManager()->refreshToken();
433
+        //we need to pass the user name, which may differ from login name
434
+        $user = $this->getUser()->getUID();
435
+        OC_Util::setupFS($user);
436
+
437
+        if ($firstTimeLogin) {
438
+            // TODO: lock necessary?
439
+            //trigger creation of user home and /files folder
440
+            $userFolder = \OC::$server->getUserFolder($user);
441
+
442
+            // copy skeleton
443
+            \OC_Util::copySkeleton($user, $userFolder);
444
+
445
+            // trigger any other initialization
446
+            \OC::$server->getEventDispatcher()->dispatch(IUser::class . '::firstLogin', new GenericEvent($this->getUser()));
447
+        }
448
+    }
449
+
450
+    /**
451
+     * Tries to login the user with HTTP Basic Authentication
452
+     *
453
+     * @todo do not allow basic auth if the user is 2FA enforced
454
+     * @param IRequest $request
455
+     * @param OC\Security\Bruteforce\Throttler $throttler
456
+     * @return boolean if the login was successful
457
+     */
458
+    public function tryBasicAuthLogin(IRequest $request,
459
+                                        OC\Security\Bruteforce\Throttler $throttler) {
460
+        if (!empty($request->server['PHP_AUTH_USER']) && !empty($request->server['PHP_AUTH_PW'])) {
461
+            try {
462
+                if ($this->logClientIn($request->server['PHP_AUTH_USER'], $request->server['PHP_AUTH_PW'], $request, $throttler)) {
463
+                    /**
464
+                     * Add DAV authenticated. This should in an ideal world not be
465
+                     * necessary but the iOS App reads cookies from anywhere instead
466
+                     * only the DAV endpoint.
467
+                     * This makes sure that the cookies will be valid for the whole scope
468
+                     * @see https://github.com/owncloud/core/issues/22893
469
+                     */
470
+                    $this->session->set(
471
+                        Auth::DAV_AUTHENTICATED, $this->getUser()->getUID()
472
+                    );
473
+
474
+                    // Set the last-password-confirm session to make the sudo mode work
475
+                        $this->session->set('last-password-confirm', $this->timeFactory->getTime());
476
+
477
+                    return true;
478
+                }
479
+            } catch (PasswordLoginForbiddenException $ex) {
480
+                // Nothing to do
481
+            }
482
+        }
483
+        return false;
484
+    }
485
+
486
+    /**
487
+     * Log an user in via login name and password
488
+     *
489
+     * @param string $uid
490
+     * @param string $password
491
+     * @return boolean
492
+     * @throws LoginException if an app canceld the login process or the user is not enabled
493
+     */
494
+    private function loginWithPassword($uid, $password) {
495
+        $user = $this->manager->checkPassword($uid, $password);
496
+        if ($user === false) {
497
+            // Password check failed
498
+            return false;
499
+        }
500
+
501
+        if ($user->isEnabled()) {
502
+            $this->setUser($user);
503
+            $this->setLoginName($uid);
504
+            $this->setToken(null);
505
+            $firstTimeLogin = $user->updateLastLoginTimestamp();
506
+            $this->manager->emit('\OC\User', 'postLogin', [$user, $password]);
507
+            if ($this->isLoggedIn()) {
508
+                $this->prepareUserLogin($firstTimeLogin);
509
+                return true;
510
+            } else {
511
+                // injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory
512
+                $message = \OC::$server->getL10N('lib')->t('Login canceled by app');
513
+                throw new LoginException($message);
514
+            }
515
+        } else {
516
+            // injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory
517
+            $message = \OC::$server->getL10N('lib')->t('User disabled');
518
+            throw new LoginException($message);
519
+        }
520
+    }
521
+
522
+    /**
523
+     * Log an user in with a given token (id)
524
+     *
525
+     * @param string $token
526
+     * @return boolean
527
+     * @throws LoginException if an app canceled the login process or the user is not enabled
528
+     */
529
+    private function loginWithToken($token) {
530
+        try {
531
+            $dbToken = $this->tokenProvider->getToken($token);
532
+        } catch (InvalidTokenException $ex) {
533
+            return false;
534
+        }
535
+        $uid = $dbToken->getUID();
536
+
537
+        // When logging in with token, the password must be decrypted first before passing to login hook
538
+        $password = '';
539
+        try {
540
+            $password = $this->tokenProvider->getPassword($dbToken, $token);
541
+        } catch (PasswordlessTokenException $ex) {
542
+            // Ignore and use empty string instead
543
+        }
544
+
545
+        $user = $this->manager->get($uid);
546
+        if (is_null($user)) {
547
+            // user does not exist
548
+            return false;
549
+        }
550
+        if (!$user->isEnabled()) {
551
+            // disabled users can not log in
552
+            // injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory
553
+            $message = \OC::$server->getL10N('lib')->t('User disabled');
554
+            throw new LoginException($message);
555
+        }
556
+
557
+        //login
558
+        $this->setUser($user);
559
+        $this->setLoginName($dbToken->getLoginName());
560
+        $this->setToken($dbToken->getId());
561
+        $this->lockdownManager->setToken($dbToken);
562
+        $this->manager->emit('\OC\User', 'postLogin', array($user, $password));
563
+
564
+        if ($this->isLoggedIn()) {
565
+            $this->prepareUserLogin(false); // token login cant be the first
566
+        } else {
567
+            // injecting l10n does not work - there is a circular dependency between session and \OCP\L10N\IFactory
568
+            $message = \OC::$server->getL10N('lib')->t('Login canceled by app');
569
+            throw new LoginException($message);
570
+        }
571
+
572
+        return true;
573
+    }
574
+
575
+    /**
576
+     * Create a new session token for the given user credentials
577
+     *
578
+     * @param IRequest $request
579
+     * @param string $uid user UID
580
+     * @param string $loginName login name
581
+     * @param string $password
582
+     * @param int $remember
583
+     * @return boolean
584
+     */
585
+    public function createSessionToken(IRequest $request, $uid, $loginName, $password = null, $remember = IToken::DO_NOT_REMEMBER) {
586
+        if (is_null($this->manager->get($uid))) {
587
+            // User does not exist
588
+            return false;
589
+        }
590
+        $name = isset($request->server['HTTP_USER_AGENT']) ? $request->server['HTTP_USER_AGENT'] : 'unknown browser';
591
+        try {
592
+            $sessionId = $this->session->getId();
593
+            $pwd = $this->getPassword($password);
594
+            $this->tokenProvider->generateToken($sessionId, $uid, $loginName, $pwd, $name, IToken::TEMPORARY_TOKEN, $remember);
595
+            return true;
596
+        } catch (SessionNotAvailableException $ex) {
597
+            // This can happen with OCC, where a memory session is used
598
+            // if a memory session is used, we shouldn't create a session token anyway
599
+            return false;
600
+        }
601
+    }
602
+
603
+    /**
604
+     * Checks if the given password is a token.
605
+     * If yes, the password is extracted from the token.
606
+     * If no, the same password is returned.
607
+     *
608
+     * @param string $password either the login password or a device token
609
+     * @return string|null the password or null if none was set in the token
610
+     */
611
+    private function getPassword($password) {
612
+        if (is_null($password)) {
613
+            // This is surely no token ;-)
614
+            return null;
615
+        }
616
+        try {
617
+            $token = $this->tokenProvider->getToken($password);
618
+            try {
619
+                return $this->tokenProvider->getPassword($token, $password);
620
+            } catch (PasswordlessTokenException $ex) {
621
+                return null;
622
+            }
623
+        } catch (InvalidTokenException $ex) {
624
+            return $password;
625
+        }
626
+    }
627
+
628
+    /**
629
+     * @param IToken $dbToken
630
+     * @param string $token
631
+     * @return boolean
632
+     */
633
+    private function checkTokenCredentials(IToken $dbToken, $token) {
634
+        // Check whether login credentials are still valid and the user was not disabled
635
+        // This check is performed each 5 minutes
636
+        $lastCheck = $dbToken->getLastCheck() ? : 0;
637
+        $now = $this->timeFactory->getTime();
638
+        if ($lastCheck > ($now - 60 * 5)) {
639
+            // Checked performed recently, nothing to do now
640
+            return true;
641
+        }
642
+
643
+        try {
644
+            $pwd = $this->tokenProvider->getPassword($dbToken, $token);
645
+        } catch (InvalidTokenException $ex) {
646
+            // An invalid token password was used -> log user out
647
+            return false;
648
+        } catch (PasswordlessTokenException $ex) {
649
+            // Token has no password
650
+
651
+            if (!is_null($this->activeUser) && !$this->activeUser->isEnabled()) {
652
+                $this->tokenProvider->invalidateToken($token);
653
+                return false;
654
+            }
655
+
656
+            $dbToken->setLastCheck($now);
657
+            return true;
658
+        }
659
+
660
+        if ($this->manager->checkPassword($dbToken->getLoginName(), $pwd) === false
661
+            || (!is_null($this->activeUser) && !$this->activeUser->isEnabled())) {
662
+            $this->tokenProvider->invalidateToken($token);
663
+            // Password has changed or user was disabled -> log user out
664
+            return false;
665
+        }
666
+        $dbToken->setLastCheck($now);
667
+        return true;
668
+    }
669
+
670
+    /**
671
+     * Check if the given token exists and performs password/user-enabled checks
672
+     *
673
+     * Invalidates the token if checks fail
674
+     *
675
+     * @param string $token
676
+     * @param string $user login name
677
+     * @return boolean
678
+     */
679
+    private function validateToken($token, $user = null) {
680
+        try {
681
+            $dbToken = $this->tokenProvider->getToken($token);
682
+        } catch (InvalidTokenException $ex) {
683
+            return false;
684
+        }
685
+
686
+        // Check if login names match
687
+        if (!is_null($user) && $dbToken->getLoginName() !== $user) {
688
+            // TODO: this makes it imposssible to use different login names on browser and client
689
+            // e.g. login by e-mail '[email protected]' on browser for generating the token will not
690
+            //      allow to use the client token with the login name 'user'.
691
+            return false;
692
+        }
693
+
694
+        if (!$this->checkTokenCredentials($dbToken, $token)) {
695
+            return false;
696
+        }
697
+
698
+        $this->tokenProvider->updateTokenActivity($dbToken);
699
+
700
+        return true;
701
+    }
702
+
703
+    /**
704
+     * Tries to login the user with auth token header
705
+     *
706
+     * @param IRequest $request
707
+     * @todo check remember me cookie
708
+     * @return boolean
709
+     */
710
+    public function tryTokenLogin(IRequest $request) {
711
+        $authHeader = $request->getHeader('Authorization');
712
+        if (strpos($authHeader, 'token ') === false) {
713
+            // No auth header, let's try session id
714
+            try {
715
+                $token = $this->session->getId();
716
+            } catch (SessionNotAvailableException $ex) {
717
+                return false;
718
+            }
719
+        } else {
720
+            $token = substr($authHeader, 6);
721
+        }
722
+
723
+        if (!$this->loginWithToken($token)) {
724
+            return false;
725
+        }
726
+        if(!$this->validateToken($token)) {
727
+            return false;
728
+        }
729
+        return true;
730
+    }
731
+
732
+    /**
733
+     * perform login using the magic cookie (remember login)
734
+     *
735
+     * @param string $uid the username
736
+     * @param string $currentToken
737
+     * @param string $oldSessionId
738
+     * @return bool
739
+     */
740
+    public function loginWithCookie($uid, $currentToken, $oldSessionId) {
741
+        $this->session->regenerateId();
742
+        $this->manager->emit('\OC\User', 'preRememberedLogin', array($uid));
743
+        $user = $this->manager->get($uid);
744
+        if (is_null($user)) {
745
+            // user does not exist
746
+            return false;
747
+        }
748
+
749
+        // get stored tokens
750
+        $tokens = $this->config->getUserKeys($uid, 'login_token');
751
+        // test cookies token against stored tokens
752
+        if (!in_array($currentToken, $tokens, true)) {
753
+            return false;
754
+        }
755
+        // replace successfully used token with a new one
756
+        $this->config->deleteUserValue($uid, 'login_token', $currentToken);
757
+        $newToken = $this->random->generate(32);
758
+        $this->config->setUserValue($uid, 'login_token', $newToken, $this->timeFactory->getTime());
759
+
760
+        try {
761
+            $sessionId = $this->session->getId();
762
+            $this->tokenProvider->renewSessionToken($oldSessionId, $sessionId);
763
+        } catch (SessionNotAvailableException $ex) {
764
+            return false;
765
+        } catch (InvalidTokenException $ex) {
766
+            \OC::$server->getLogger()->warning('Renewing session token failed', ['app' => 'core']);
767
+            return false;
768
+        }
769
+
770
+        $this->setMagicInCookie($user->getUID(), $newToken);
771
+        $token = $this->tokenProvider->getToken($sessionId);
772
+
773
+        //login
774
+        $this->setUser($user);
775
+        $this->setLoginName($token->getLoginName());
776
+        $this->setToken($token->getId());
777
+        $this->lockdownManager->setToken($token);
778
+        $user->updateLastLoginTimestamp();
779
+        $this->manager->emit('\OC\User', 'postRememberedLogin', [$user]);
780
+        return true;
781
+    }
782
+
783
+    /**
784
+     * @param IUser $user
785
+     */
786
+    public function createRememberMeToken(IUser $user) {
787
+        $token = $this->random->generate(32);
788
+        $this->config->setUserValue($user->getUID(), 'login_token', $token, $this->timeFactory->getTime());
789
+        $this->setMagicInCookie($user->getUID(), $token);
790
+    }
791
+
792
+    /**
793
+     * logout the user from the session
794
+     */
795
+    public function logout() {
796
+        $this->manager->emit('\OC\User', 'logout');
797
+        $user = $this->getUser();
798
+        if (!is_null($user)) {
799
+            try {
800
+                $this->tokenProvider->invalidateToken($this->session->getId());
801
+            } catch (SessionNotAvailableException $ex) {
802
+
803
+            }
804
+        }
805
+        $this->setUser(null);
806
+        $this->setLoginName(null);
807
+        $this->setToken(null);
808
+        $this->unsetMagicInCookie();
809
+        $this->session->clear();
810
+        $this->manager->emit('\OC\User', 'postLogout');
811
+    }
812
+
813
+    /**
814
+     * Set cookie value to use in next page load
815
+     *
816
+     * @param string $username username to be set
817
+     * @param string $token
818
+     */
819
+    public function setMagicInCookie($username, $token) {
820
+        $secureCookie = OC::$server->getRequest()->getServerProtocol() === 'https';
821
+        $webRoot = \OC::$WEBROOT;
822
+        if ($webRoot === '') {
823
+            $webRoot = '/';
824
+        }
825
+
826
+        $expires = $this->timeFactory->getTime() + $this->config->getSystemValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15);
827
+        setcookie('nc_username', $username, $expires, $webRoot, '', $secureCookie, true);
828
+        setcookie('nc_token', $token, $expires, $webRoot, '', $secureCookie, true);
829
+        try {
830
+            setcookie('nc_session_id', $this->session->getId(), $expires, $webRoot, '', $secureCookie, true);
831
+        } catch (SessionNotAvailableException $ex) {
832
+            // ignore
833
+        }
834
+    }
835
+
836
+    /**
837
+     * Remove cookie for "remember username"
838
+     */
839
+    public function unsetMagicInCookie() {
840
+        //TODO: DI for cookies and IRequest
841
+        $secureCookie = OC::$server->getRequest()->getServerProtocol() === 'https';
842
+
843
+        unset($_COOKIE['nc_username']); //TODO: DI
844
+        unset($_COOKIE['nc_token']);
845
+        unset($_COOKIE['nc_session_id']);
846
+        setcookie('nc_username', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT, '', $secureCookie, true);
847
+        setcookie('nc_token', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT, '', $secureCookie, true);
848
+        setcookie('nc_session_id', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT, '', $secureCookie, true);
849
+        // old cookies might be stored under /webroot/ instead of /webroot
850
+        // and Firefox doesn't like it!
851
+        setcookie('nc_username', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT . '/', '', $secureCookie, true);
852
+        setcookie('nc_token', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT . '/', '', $secureCookie, true);
853
+        setcookie('nc_session_id', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT . '/', '', $secureCookie, true);
854
+    }
855
+
856
+    /**
857
+     * Update password of the browser session token if there is one
858
+     *
859
+     * @param string $password
860
+     */
861
+    public function updateSessionTokenPassword($password) {
862
+        try {
863
+            $sessionId = $this->session->getId();
864
+            $token = $this->tokenProvider->getToken($sessionId);
865
+            $this->tokenProvider->setPassword($token, $sessionId, $password);
866
+        } catch (SessionNotAvailableException $ex) {
867
+            // Nothing to do
868
+        } catch (InvalidTokenException $ex) {
869
+            // Nothing to do
870
+        }
871
+    }
872 872
 
873 873
 
874 874
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -355,14 +355,14 @@  discard block
 block discarded – undo
355 355
 		if (!$isTokenPassword && $this->isTwoFactorEnforced($user)) {
356 356
 			throw new PasswordLoginForbiddenException();
357 357
 		}
358
-		if (!$this->login($user, $password) ) {
358
+		if (!$this->login($user, $password)) {
359 359
 			$users = $this->manager->getByEmail($user);
360 360
 			if (count($users) === 1) {
361 361
 				return $this->login($users[0]->getUID(), $password);
362 362
 			}
363 363
 
364 364
 			$throttler->registerAttempt('login', $request->getRemoteAddress(), ['uid' => $user]);
365
-			if($currentDelay === 0) {
365
+			if ($currentDelay === 0) {
366 366
 				$throttler->sleepDelay($request->getRemoteAddress(), 'login');
367 367
 			}
368 368
 			return false;
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 
371 371
 		if ($isTokenPassword) {
372 372
 			$this->session->set('app_password', $password);
373
-		} else if($this->supportsCookies($request)) {
373
+		} else if ($this->supportsCookies($request)) {
374 374
 			// Password login, but cookies supported -> create (browser) session token
375 375
 			$this->createSessionToken($request, $this->getUser()->getUID(), $user, $password);
376 376
 		}
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
 			\OC_Util::copySkeleton($user, $userFolder);
444 444
 
445 445
 			// trigger any other initialization
446
-			\OC::$server->getEventDispatcher()->dispatch(IUser::class . '::firstLogin', new GenericEvent($this->getUser()));
446
+			\OC::$server->getEventDispatcher()->dispatch(IUser::class.'::firstLogin', new GenericEvent($this->getUser()));
447 447
 		}
448 448
 	}
449 449
 
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
 	private function checkTokenCredentials(IToken $dbToken, $token) {
634 634
 		// Check whether login credentials are still valid and the user was not disabled
635 635
 		// This check is performed each 5 minutes
636
-		$lastCheck = $dbToken->getLastCheck() ? : 0;
636
+		$lastCheck = $dbToken->getLastCheck() ?: 0;
637 637
 		$now = $this->timeFactory->getTime();
638 638
 		if ($lastCheck > ($now - 60 * 5)) {
639 639
 			// Checked performed recently, nothing to do now
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
 		if (!$this->loginWithToken($token)) {
724 724
 			return false;
725 725
 		}
726
-		if(!$this->validateToken($token)) {
726
+		if (!$this->validateToken($token)) {
727 727
 			return false;
728 728
 		}
729 729
 		return true;
@@ -848,9 +848,9 @@  discard block
 block discarded – undo
848 848
 		setcookie('nc_session_id', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT, '', $secureCookie, true);
849 849
 		// old cookies might be stored under /webroot/ instead of /webroot
850 850
 		// and Firefox doesn't like it!
851
-		setcookie('nc_username', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT . '/', '', $secureCookie, true);
852
-		setcookie('nc_token', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT . '/', '', $secureCookie, true);
853
-		setcookie('nc_session_id', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT . '/', '', $secureCookie, true);
851
+		setcookie('nc_username', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT.'/', '', $secureCookie, true);
852
+		setcookie('nc_token', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT.'/', '', $secureCookie, true);
853
+		setcookie('nc_session_id', '', $this->timeFactory->getTime() - 3600, OC::$WEBROOT.'/', '', $secureCookie, true);
854 854
 	}
855 855
 
856 856
 	/**
Please login to merge, or discard this patch.
apps/dav/lib/Files/FileSearchBackend.php 3 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -104,6 +104,10 @@
 block discarded – undo
104 104
 		}
105 105
 	}
106 106
 
107
+	/**
108
+	 * @param string $href
109
+	 * @param string $path
110
+	 */
107 111
 	public function getPropertyDefinitionsForScope($href, $path) {
108 112
 		// all valid scopes support the same schema
109 113
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 		/** @var Folder $folder $results */
156 156
 		$results = $folder->search($query);
157 157
 
158
-		return array_map(function (Node $node) {
158
+		return array_map(function(Node $node) {
159 159
 			if ($node instanceof Folder) {
160 160
 				return new SearchResult(new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager), $this->getHrefForNode($node));
161 161
 			} else {
@@ -169,8 +169,8 @@  discard block
 block discarded – undo
169 169
 	 * @return string
170 170
 	 */
171 171
 	private function getHrefForNode(Node $node) {
172
-		$base = '/files/' . $this->user->getUID();
173
-		return $base . $this->view->getRelativePath($node->getPath());
172
+		$base = '/files/'.$this->user->getUID();
173
+		return $base.$this->view->getRelativePath($node->getPath());
174 174
 	}
175 175
 
176 176
 	/**
@@ -210,19 +210,19 @@  discard block
 block discarded – undo
210 210
 			case Operator::OPERATION_LESS_THAN:
211 211
 			case Operator::OPERATION_IS_LIKE:
212 212
 				if (count($operator->arguments) !== 2) {
213
-					throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation');
213
+					throw new \InvalidArgumentException('Invalid number of arguments for '.$trimmedType.' operation');
214 214
 				}
215 215
 				if (!is_string($operator->arguments[0])) {
216
-					throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property');
216
+					throw new \InvalidArgumentException('Invalid argument 1 for '.$trimmedType.' operation, expected property');
217 217
 				}
218 218
 				if (!($operator->arguments[1] instanceof Literal)) {
219
-					throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal');
219
+					throw new \InvalidArgumentException('Invalid argument 2 for '.$trimmedType.' operation, expected literal');
220 220
 				}
221 221
 				return new SearchComparison($trimmedType, $this->mapPropertyNameToColumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value));
222 222
 			case Operator::OPERATION_IS_COLLECTION:
223 223
 				return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE);
224 224
 			default:
225
-				throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType . ' (' . $operator->type . ')');
225
+				throw new \InvalidArgumentException('Unsupported operation '.$trimmedType.' ('.$operator->type.')');
226 226
 		}
227 227
 	}
228 228
 
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 			case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME:
248 248
 				return 'fileid';
249 249
 			default:
250
-				throw new \InvalidArgumentException('Unsupported property for search or order: ' . $propertyName);
250
+				throw new \InvalidArgumentException('Unsupported property for search or order: '.$propertyName);
251 251
 		}
252 252
 	}
253 253
 
Please login to merge, or discard this patch.
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -49,231 +49,231 @@
 block discarded – undo
49 49
 use SearchDAV\XML\Order;
50 50
 
51 51
 class FileSearchBackend implements ISearchBackend {
52
-	/** @var Tree */
53
-	private $tree;
52
+    /** @var Tree */
53
+    private $tree;
54 54
 
55
-	/** @var IUser */
56
-	private $user;
55
+    /** @var IUser */
56
+    private $user;
57 57
 
58
-	/** @var IRootFolder */
59
-	private $rootFolder;
58
+    /** @var IRootFolder */
59
+    private $rootFolder;
60 60
 
61
-	/** @var IManager */
62
-	private $shareManager;
61
+    /** @var IManager */
62
+    private $shareManager;
63 63
 
64
-	/** @var View */
65
-	private $view;
64
+    /** @var View */
65
+    private $view;
66 66
 
67
-	/**
68
-	 * FileSearchBackend constructor.
69
-	 *
70
-	 * @param Tree $tree
71
-	 * @param IUser $user
72
-	 * @param IRootFolder $rootFolder
73
-	 * @param IManager $shareManager
74
-	 * @param View $view
75
-	 * @internal param IRootFolder $rootFolder
76
-	 */
77
-	public function __construct(Tree $tree, IUser $user, IRootFolder $rootFolder, IManager $shareManager, View $view) {
78
-		$this->tree = $tree;
79
-		$this->user = $user;
80
-		$this->rootFolder = $rootFolder;
81
-		$this->shareManager = $shareManager;
82
-		$this->view = $view;
83
-	}
67
+    /**
68
+     * FileSearchBackend constructor.
69
+     *
70
+     * @param Tree $tree
71
+     * @param IUser $user
72
+     * @param IRootFolder $rootFolder
73
+     * @param IManager $shareManager
74
+     * @param View $view
75
+     * @internal param IRootFolder $rootFolder
76
+     */
77
+    public function __construct(Tree $tree, IUser $user, IRootFolder $rootFolder, IManager $shareManager, View $view) {
78
+        $this->tree = $tree;
79
+        $this->user = $user;
80
+        $this->rootFolder = $rootFolder;
81
+        $this->shareManager = $shareManager;
82
+        $this->view = $view;
83
+    }
84 84
 
85
-	/**
86
-	 * Search endpoint will be remote.php/dav
87
-	 *
88
-	 * @return string
89
-	 */
90
-	public function getArbiterPath() {
91
-		return '';
92
-	}
85
+    /**
86
+     * Search endpoint will be remote.php/dav
87
+     *
88
+     * @return string
89
+     */
90
+    public function getArbiterPath() {
91
+        return '';
92
+    }
93 93
 
94
-	public function isValidScope($href, $depth, $path) {
95
-		// only allow scopes inside the dav server
96
-		if (is_null($path)) {
97
-			return false;
98
-		}
94
+    public function isValidScope($href, $depth, $path) {
95
+        // only allow scopes inside the dav server
96
+        if (is_null($path)) {
97
+            return false;
98
+        }
99 99
 
100
-		try {
101
-			$node = $this->tree->getNodeForPath($path);
102
-			return $node instanceof Directory;
103
-		} catch (NotFound $e) {
104
-			return false;
105
-		}
106
-	}
100
+        try {
101
+            $node = $this->tree->getNodeForPath($path);
102
+            return $node instanceof Directory;
103
+        } catch (NotFound $e) {
104
+            return false;
105
+        }
106
+    }
107 107
 
108
-	public function getPropertyDefinitionsForScope($href, $path) {
109
-		// all valid scopes support the same schema
108
+    public function getPropertyDefinitionsForScope($href, $path) {
109
+        // all valid scopes support the same schema
110 110
 
111
-		//todo dynamically load all propfind properties that are supported
112
-		return [
113
-			// queryable properties
114
-			new SearchPropertyDefinition('{DAV:}displayname', true, false, true),
115
-			new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true),
116
-			new SearchPropertyDefinition('{DAV:}getlastmodified', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
117
-			new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
118
-			new SearchPropertyDefinition(TagsPlugin::FAVORITE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_BOOLEAN),
119
-			new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, true, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
111
+        //todo dynamically load all propfind properties that are supported
112
+        return [
113
+            // queryable properties
114
+            new SearchPropertyDefinition('{DAV:}displayname', true, false, true),
115
+            new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true),
116
+            new SearchPropertyDefinition('{DAV:}getlastmodified', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
117
+            new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
118
+            new SearchPropertyDefinition(TagsPlugin::FAVORITE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_BOOLEAN),
119
+            new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, true, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
120 120
 
121
-			// select only properties
122
-			new SearchPropertyDefinition('{DAV:}resourcetype', false, true, false),
123
-			new SearchPropertyDefinition('{DAV:}getcontentlength', false, true, false),
124
-			new SearchPropertyDefinition(FilesPlugin::CHECKSUMS_PROPERTYNAME, false, true, false),
125
-			new SearchPropertyDefinition(FilesPlugin::PERMISSIONS_PROPERTYNAME, false, true, false),
126
-			new SearchPropertyDefinition(FilesPlugin::GETETAG_PROPERTYNAME, false, true, false),
127
-			new SearchPropertyDefinition(FilesPlugin::OWNER_ID_PROPERTYNAME, false, true, false),
128
-			new SearchPropertyDefinition(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME, false, true, false),
129
-			new SearchPropertyDefinition(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME, false, true, false),
130
-			new SearchPropertyDefinition(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_BOOLEAN),
131
-			new SearchPropertyDefinition(FilesPlugin::FILEID_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
132
-		];
133
-	}
121
+            // select only properties
122
+            new SearchPropertyDefinition('{DAV:}resourcetype', false, true, false),
123
+            new SearchPropertyDefinition('{DAV:}getcontentlength', false, true, false),
124
+            new SearchPropertyDefinition(FilesPlugin::CHECKSUMS_PROPERTYNAME, false, true, false),
125
+            new SearchPropertyDefinition(FilesPlugin::PERMISSIONS_PROPERTYNAME, false, true, false),
126
+            new SearchPropertyDefinition(FilesPlugin::GETETAG_PROPERTYNAME, false, true, false),
127
+            new SearchPropertyDefinition(FilesPlugin::OWNER_ID_PROPERTYNAME, false, true, false),
128
+            new SearchPropertyDefinition(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME, false, true, false),
129
+            new SearchPropertyDefinition(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME, false, true, false),
130
+            new SearchPropertyDefinition(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_BOOLEAN),
131
+            new SearchPropertyDefinition(FilesPlugin::FILEID_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
132
+        ];
133
+    }
134 134
 
135
-	/**
136
-	 * @param BasicSearch $search
137
-	 * @return SearchResult[]
138
-	 */
139
-	public function search(BasicSearch $search) {
140
-		if (count($search->from) !== 1) {
141
-			throw new \InvalidArgumentException('Searching more than one folder is not supported');
142
-		}
143
-		$query = $this->transformQuery($search);
144
-		$scope = $search->from[0];
145
-		if ($scope->path === null) {
146
-			throw new \InvalidArgumentException('Using uri\'s as scope is not supported, please use a path relative to the search arbiter instead');
147
-		}
148
-		$node = $this->tree->getNodeForPath($scope->path);
149
-		if (!$node instanceof Directory) {
150
-			throw new \InvalidArgumentException('Search is only supported on directories');
151
-		}
135
+    /**
136
+     * @param BasicSearch $search
137
+     * @return SearchResult[]
138
+     */
139
+    public function search(BasicSearch $search) {
140
+        if (count($search->from) !== 1) {
141
+            throw new \InvalidArgumentException('Searching more than one folder is not supported');
142
+        }
143
+        $query = $this->transformQuery($search);
144
+        $scope = $search->from[0];
145
+        if ($scope->path === null) {
146
+            throw new \InvalidArgumentException('Using uri\'s as scope is not supported, please use a path relative to the search arbiter instead');
147
+        }
148
+        $node = $this->tree->getNodeForPath($scope->path);
149
+        if (!$node instanceof Directory) {
150
+            throw new \InvalidArgumentException('Search is only supported on directories');
151
+        }
152 152
 
153
-		$fileInfo = $node->getFileInfo();
154
-		$folder = $this->rootFolder->get($fileInfo->getPath());
155
-		/** @var Folder $folder $results */
156
-		$results = $folder->search($query);
153
+        $fileInfo = $node->getFileInfo();
154
+        $folder = $this->rootFolder->get($fileInfo->getPath());
155
+        /** @var Folder $folder $results */
156
+        $results = $folder->search($query);
157 157
 
158
-		return array_map(function (Node $node) {
159
-			if ($node instanceof Folder) {
160
-				return new SearchResult(new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager), $this->getHrefForNode($node));
161
-			} else {
162
-				return new SearchResult(new \OCA\DAV\Connector\Sabre\File($this->view, $node, $this->shareManager), $this->getHrefForNode($node));
163
-			}
164
-		}, $results);
165
-	}
158
+        return array_map(function (Node $node) {
159
+            if ($node instanceof Folder) {
160
+                return new SearchResult(new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager), $this->getHrefForNode($node));
161
+            } else {
162
+                return new SearchResult(new \OCA\DAV\Connector\Sabre\File($this->view, $node, $this->shareManager), $this->getHrefForNode($node));
163
+            }
164
+        }, $results);
165
+    }
166 166
 
167
-	/**
168
-	 * @param Node $node
169
-	 * @return string
170
-	 */
171
-	private function getHrefForNode(Node $node) {
172
-		$base = '/files/' . $this->user->getUID();
173
-		return $base . $this->view->getRelativePath($node->getPath());
174
-	}
167
+    /**
168
+     * @param Node $node
169
+     * @return string
170
+     */
171
+    private function getHrefForNode(Node $node) {
172
+        $base = '/files/' . $this->user->getUID();
173
+        return $base . $this->view->getRelativePath($node->getPath());
174
+    }
175 175
 
176
-	/**
177
-	 * @param BasicSearch $query
178
-	 * @return ISearchQuery
179
-	 */
180
-	private function transformQuery(BasicSearch $query) {
181
-		// TODO offset, limit
182
-		$orders = array_map([$this, 'mapSearchOrder'], $query->orderBy);
183
-		return new SearchQuery($this->transformSearchOperation($query->where), 0, 0, $orders, $this->user);
184
-	}
176
+    /**
177
+     * @param BasicSearch $query
178
+     * @return ISearchQuery
179
+     */
180
+    private function transformQuery(BasicSearch $query) {
181
+        // TODO offset, limit
182
+        $orders = array_map([$this, 'mapSearchOrder'], $query->orderBy);
183
+        return new SearchQuery($this->transformSearchOperation($query->where), 0, 0, $orders, $this->user);
184
+    }
185 185
 
186
-	/**
187
-	 * @param Order $order
188
-	 * @return ISearchOrder
189
-	 */
190
-	private function mapSearchOrder(Order $order) {
191
-		return new SearchOrder($order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING, $this->mapPropertyNameToColumn($order->property));
192
-	}
186
+    /**
187
+     * @param Order $order
188
+     * @return ISearchOrder
189
+     */
190
+    private function mapSearchOrder(Order $order) {
191
+        return new SearchOrder($order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING, $this->mapPropertyNameToColumn($order->property));
192
+    }
193 193
 
194
-	/**
195
-	 * @param Operator $operator
196
-	 * @return ISearchOperator
197
-	 */
198
-	private function transformSearchOperation(Operator $operator) {
199
-		list(, $trimmedType) = explode('}', $operator->type);
200
-		switch ($operator->type) {
201
-			case Operator::OPERATION_AND:
202
-			case Operator::OPERATION_OR:
203
-			case Operator::OPERATION_NOT:
204
-				$arguments = array_map([$this, 'transformSearchOperation'], $operator->arguments);
205
-				return new SearchBinaryOperator($trimmedType, $arguments);
206
-			case Operator::OPERATION_EQUAL:
207
-			case Operator::OPERATION_GREATER_OR_EQUAL_THAN:
208
-			case Operator::OPERATION_GREATER_THAN:
209
-			case Operator::OPERATION_LESS_OR_EQUAL_THAN:
210
-			case Operator::OPERATION_LESS_THAN:
211
-			case Operator::OPERATION_IS_LIKE:
212
-				if (count($operator->arguments) !== 2) {
213
-					throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation');
214
-				}
215
-				if (!is_string($operator->arguments[0])) {
216
-					throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property');
217
-				}
218
-				if (!($operator->arguments[1] instanceof Literal)) {
219
-					throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal');
220
-				}
221
-				return new SearchComparison($trimmedType, $this->mapPropertyNameToColumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value));
222
-			case Operator::OPERATION_IS_COLLECTION:
223
-				return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE);
224
-			default:
225
-				throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType . ' (' . $operator->type . ')');
226
-		}
227
-	}
194
+    /**
195
+     * @param Operator $operator
196
+     * @return ISearchOperator
197
+     */
198
+    private function transformSearchOperation(Operator $operator) {
199
+        list(, $trimmedType) = explode('}', $operator->type);
200
+        switch ($operator->type) {
201
+            case Operator::OPERATION_AND:
202
+            case Operator::OPERATION_OR:
203
+            case Operator::OPERATION_NOT:
204
+                $arguments = array_map([$this, 'transformSearchOperation'], $operator->arguments);
205
+                return new SearchBinaryOperator($trimmedType, $arguments);
206
+            case Operator::OPERATION_EQUAL:
207
+            case Operator::OPERATION_GREATER_OR_EQUAL_THAN:
208
+            case Operator::OPERATION_GREATER_THAN:
209
+            case Operator::OPERATION_LESS_OR_EQUAL_THAN:
210
+            case Operator::OPERATION_LESS_THAN:
211
+            case Operator::OPERATION_IS_LIKE:
212
+                if (count($operator->arguments) !== 2) {
213
+                    throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation');
214
+                }
215
+                if (!is_string($operator->arguments[0])) {
216
+                    throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property');
217
+                }
218
+                if (!($operator->arguments[1] instanceof Literal)) {
219
+                    throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal');
220
+                }
221
+                return new SearchComparison($trimmedType, $this->mapPropertyNameToColumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value));
222
+            case Operator::OPERATION_IS_COLLECTION:
223
+                return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE);
224
+            default:
225
+                throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType . ' (' . $operator->type . ')');
226
+        }
227
+    }
228 228
 
229
-	/**
230
-	 * @param string $propertyName
231
-	 * @return string
232
-	 */
233
-	private function mapPropertyNameToColumn($propertyName) {
234
-		switch ($propertyName) {
235
-			case '{DAV:}displayname':
236
-				return 'name';
237
-			case '{DAV:}getcontenttype':
238
-				return 'mimetype';
239
-			case '{DAV:}getlastmodified':
240
-				return 'mtime';
241
-			case FilesPlugin::SIZE_PROPERTYNAME:
242
-				return 'size';
243
-			case TagsPlugin::FAVORITE_PROPERTYNAME:
244
-				return 'favorite';
245
-			case TagsPlugin::TAGS_PROPERTYNAME:
246
-				return 'tagname';
247
-			case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME:
248
-				return 'fileid';
249
-			default:
250
-				throw new \InvalidArgumentException('Unsupported property for search or order: ' . $propertyName);
251
-		}
252
-	}
229
+    /**
230
+     * @param string $propertyName
231
+     * @return string
232
+     */
233
+    private function mapPropertyNameToColumn($propertyName) {
234
+        switch ($propertyName) {
235
+            case '{DAV:}displayname':
236
+                return 'name';
237
+            case '{DAV:}getcontenttype':
238
+                return 'mimetype';
239
+            case '{DAV:}getlastmodified':
240
+                return 'mtime';
241
+            case FilesPlugin::SIZE_PROPERTYNAME:
242
+                return 'size';
243
+            case TagsPlugin::FAVORITE_PROPERTYNAME:
244
+                return 'favorite';
245
+            case TagsPlugin::TAGS_PROPERTYNAME:
246
+                return 'tagname';
247
+            case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME:
248
+                return 'fileid';
249
+            default:
250
+                throw new \InvalidArgumentException('Unsupported property for search or order: ' . $propertyName);
251
+        }
252
+    }
253 253
 
254
-	private function castValue($propertyName, $value) {
255
-		$allProps = $this->getPropertyDefinitionsForScope('', '');
256
-		foreach ($allProps as $prop) {
257
-			if ($prop->name === $propertyName) {
258
-				$dataType = $prop->dataType;
259
-				switch ($dataType) {
260
-					case SearchPropertyDefinition::DATATYPE_BOOLEAN:
261
-						return $value === 'yes';
262
-					case SearchPropertyDefinition::DATATYPE_DECIMAL:
263
-					case SearchPropertyDefinition::DATATYPE_INTEGER:
264
-					case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER:
265
-						return 0 + $value;
266
-					case SearchPropertyDefinition::DATATYPE_DATETIME:
267
-						if (is_numeric($value)) {
268
-							return 0 + $value;
269
-						}
270
-						$date = \DateTime::createFromFormat(\DateTime::ATOM, $value);
271
-						return ($date instanceof \DateTime) ? $date->getTimestamp() : 0;
272
-					default:
273
-						return $value;
274
-				}
275
-			}
276
-		}
277
-		return $value;
278
-	}
254
+    private function castValue($propertyName, $value) {
255
+        $allProps = $this->getPropertyDefinitionsForScope('', '');
256
+        foreach ($allProps as $prop) {
257
+            if ($prop->name === $propertyName) {
258
+                $dataType = $prop->dataType;
259
+                switch ($dataType) {
260
+                    case SearchPropertyDefinition::DATATYPE_BOOLEAN:
261
+                        return $value === 'yes';
262
+                    case SearchPropertyDefinition::DATATYPE_DECIMAL:
263
+                    case SearchPropertyDefinition::DATATYPE_INTEGER:
264
+                    case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER:
265
+                        return 0 + $value;
266
+                    case SearchPropertyDefinition::DATATYPE_DATETIME:
267
+                        if (is_numeric($value)) {
268
+                            return 0 + $value;
269
+                        }
270
+                        $date = \DateTime::createFromFormat(\DateTime::ATOM, $value);
271
+                        return ($date instanceof \DateTime) ? $date->getTimestamp() : 0;
272
+                    default:
273
+                        return $value;
274
+                }
275
+            }
276
+        }
277
+        return $value;
278
+    }
279 279
 }
Please login to merge, or discard this patch.
lib/private/Lockdown/Filesystem/NullCache.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,6 @@
 block discarded – undo
22 22
 use OC\Files\Cache\CacheEntry;
23 23
 use OCP\Constants;
24 24
 use OCP\Files\Cache\ICache;
25
-use OCP\Files\Cache\ICacheEntry;
26 25
 use OCP\Files\FileInfo;
27 26
 use OCP\Files\Search\ISearchQuery;
28 27
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,8 +31,7 @@
 block discarded – undo
31 31
 	}
32 32
 
33 33
 	public function get($file) {
34
-		return $file !== '' ? null :
35
-			new CacheEntry([
34
+		return $file !== '' ? null : new CacheEntry([
36 35
 				'fileid' => -1,
37 36
 				'parent' => -1,
38 37
 				'name' => '',
Please login to merge, or discard this patch.
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -27,101 +27,101 @@
 block discarded – undo
27 27
 use OCP\Files\Search\ISearchQuery;
28 28
 
29 29
 class NullCache implements ICache {
30
-	public function getNumericStorageId() {
31
-		return -1;
32
-	}
33
-
34
-	public function get($file) {
35
-		return $file !== '' ? null :
36
-			new CacheEntry([
37
-				'fileid' => -1,
38
-				'parent' => -1,
39
-				'name' => '',
40
-				'path' => '',
41
-				'size' => '0',
42
-				'mtime' => time(),
43
-				'storage_mtime' => time(),
44
-				'etag' => '',
45
-				'mimetype' => FileInfo::MIMETYPE_FOLDER,
46
-				'mimepart' => 'httpd',
47
-				'permissions' => Constants::PERMISSION_READ
48
-			]);
49
-	}
50
-
51
-	public function getFolderContents($folder) {
52
-		return [];
53
-	}
54
-
55
-	public function getFolderContentsById($fileId) {
56
-		return [];
57
-	}
58
-
59
-	public function put($file, array $data) {
60
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
61
-	}
62
-
63
-	public function insert($file, array $data) {
64
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
65
-	}
66
-
67
-	public function update($id, array $data) {
68
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
69
-	}
70
-
71
-	public function getId($file) {
72
-		return -1;
73
-	}
74
-
75
-	public function getParentId($file) {
76
-		return -1;
77
-	}
78
-
79
-	public function inCache($file) {
80
-		return $file === '';
81
-	}
82
-
83
-	public function remove($file) {
84
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
85
-	}
86
-
87
-	public function move($source, $target) {
88
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
89
-	}
90
-
91
-	public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
92
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
93
-	}
94
-
95
-	public function getStatus($file) {
96
-		return ICache::COMPLETE;
97
-	}
98
-
99
-	public function search($pattern) {
100
-		return [];
101
-	}
102
-
103
-	public function searchByMime($mimetype) {
104
-		return [];
105
-	}
106
-
107
-	public function searchQuery(ISearchQuery $query) {
108
-		return [];
109
-	}
110
-
111
-	public function searchByTag($tag, $userId) {
112
-		return [];
113
-	}
114
-
115
-	public function getIncomplete() {
116
-		return [];
117
-	}
118
-
119
-	public function getPathById($id) {
120
-		return '';
121
-	}
122
-
123
-	public function normalize($path) {
124
-		return $path;
125
-	}
30
+    public function getNumericStorageId() {
31
+        return -1;
32
+    }
33
+
34
+    public function get($file) {
35
+        return $file !== '' ? null :
36
+            new CacheEntry([
37
+                'fileid' => -1,
38
+                'parent' => -1,
39
+                'name' => '',
40
+                'path' => '',
41
+                'size' => '0',
42
+                'mtime' => time(),
43
+                'storage_mtime' => time(),
44
+                'etag' => '',
45
+                'mimetype' => FileInfo::MIMETYPE_FOLDER,
46
+                'mimepart' => 'httpd',
47
+                'permissions' => Constants::PERMISSION_READ
48
+            ]);
49
+    }
50
+
51
+    public function getFolderContents($folder) {
52
+        return [];
53
+    }
54
+
55
+    public function getFolderContentsById($fileId) {
56
+        return [];
57
+    }
58
+
59
+    public function put($file, array $data) {
60
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
61
+    }
62
+
63
+    public function insert($file, array $data) {
64
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
65
+    }
66
+
67
+    public function update($id, array $data) {
68
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
69
+    }
70
+
71
+    public function getId($file) {
72
+        return -1;
73
+    }
74
+
75
+    public function getParentId($file) {
76
+        return -1;
77
+    }
78
+
79
+    public function inCache($file) {
80
+        return $file === '';
81
+    }
82
+
83
+    public function remove($file) {
84
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
85
+    }
86
+
87
+    public function move($source, $target) {
88
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
89
+    }
90
+
91
+    public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
92
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
93
+    }
94
+
95
+    public function getStatus($file) {
96
+        return ICache::COMPLETE;
97
+    }
98
+
99
+    public function search($pattern) {
100
+        return [];
101
+    }
102
+
103
+    public function searchByMime($mimetype) {
104
+        return [];
105
+    }
106
+
107
+    public function searchQuery(ISearchQuery $query) {
108
+        return [];
109
+    }
110
+
111
+    public function searchByTag($tag, $userId) {
112
+        return [];
113
+    }
114
+
115
+    public function getIncomplete() {
116
+        return [];
117
+    }
118
+
119
+    public function getPathById($id) {
120
+        return '';
121
+    }
122
+
123
+    public function normalize($path) {
124
+        return $path;
125
+    }
126 126
 
127 127
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/StreamResponse.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
 	private $filePath;
38 38
 
39 39
 	/**
40
-	 * @param string|resource $filePath the path to the file or a file handle which should be streamed
40
+	 * @param string $filePath the path to the file or a file handle which should be streamed
41 41
 	 * @since 8.1.0
42 42
 	 */
43 43
 	public function __construct ($filePath) {
Please login to merge, or discard this patch.
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -33,33 +33,33 @@
 block discarded – undo
33 33
  * @since 8.1.0
34 34
  */
35 35
 class StreamResponse extends Response implements ICallbackResponse {
36
-	/** @var string */
37
-	private $filePath;
36
+    /** @var string */
37
+    private $filePath;
38 38
 
39
-	/**
40
-	 * @param string|resource $filePath the path to the file or a file handle which should be streamed
41
-	 * @since 8.1.0
42
-	 */
43
-	public function __construct ($filePath) {
44
-		$this->filePath = $filePath;
45
-	}
39
+    /**
40
+     * @param string|resource $filePath the path to the file or a file handle which should be streamed
41
+     * @since 8.1.0
42
+     */
43
+    public function __construct ($filePath) {
44
+        $this->filePath = $filePath;
45
+    }
46 46
 
47 47
 
48
-	/**
49
-	 * Streams the file using readfile
50
-	 *
51
-	 * @param IOutput $output a small wrapper that handles output
52
-	 * @since 8.1.0
53
-	 */
54
-	public function callback (IOutput $output) {
55
-		// handle caching
56
-		if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) {
57
-			if (!(is_resource($this->filePath) || file_exists($this->filePath))) {
58
-				$output->setHttpResponseCode(Http::STATUS_NOT_FOUND);
59
-			} elseif ($output->setReadfile($this->filePath) === false) {
60
-				$output->setHttpResponseCode(Http::STATUS_BAD_REQUEST);
61
-			}
62
-		}
63
-	}
48
+    /**
49
+     * Streams the file using readfile
50
+     *
51
+     * @param IOutput $output a small wrapper that handles output
52
+     * @since 8.1.0
53
+     */
54
+    public function callback (IOutput $output) {
55
+        // handle caching
56
+        if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) {
57
+            if (!(is_resource($this->filePath) || file_exists($this->filePath))) {
58
+                $output->setHttpResponseCode(Http::STATUS_NOT_FOUND);
59
+            } elseif ($output->setReadfile($this->filePath) === false) {
60
+                $output->setHttpResponseCode(Http::STATUS_BAD_REQUEST);
61
+            }
62
+        }
63
+    }
64 64
 
65 65
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 * @param string|resource $filePath the path to the file or a file handle which should be streamed
41 41
 	 * @since 8.1.0
42 42
 	 */
43
-	public function __construct ($filePath) {
43
+	public function __construct($filePath) {
44 44
 		$this->filePath = $filePath;
45 45
 	}
46 46
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * @param IOutput $output a small wrapper that handles output
52 52
 	 * @since 8.1.0
53 53
 	 */
54
-	public function callback (IOutput $output) {
54
+	public function callback(IOutput $output) {
55 55
 		// handle caching
56 56
 		if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) {
57 57
 			if (!(is_resource($this->filePath) || file_exists($this->filePath))) {
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/DavAclPlugin.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -47,6 +47,9 @@
 block discarded – undo
47 47
 		$this->allowUnauthenticatedAccess = false;
48 48
 	}
49 49
 
50
+	/**
51
+	 * @param string $privileges
52
+	 */
50 53
 	function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) {
51 54
 		$access = parent::checkPrivileges($uri, $privileges, $recursion, false);
52 55
 		if($access === false && $throwExceptions) {
Please login to merge, or discard this patch.
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -25,14 +25,11 @@
 block discarded – undo
25 25
 
26 26
 use Sabre\CalDAV\Principal\User;
27 27
 use Sabre\DAV\Exception\NotFound;
28
-use Sabre\DAV\IFile;
29 28
 use Sabre\DAV\INode;
30 29
 use \Sabre\DAV\PropFind;
31 30
 use \Sabre\DAV\PropPatch;
32
-use Sabre\DAVACL\Exception\NeedPrivileges;
33 31
 use \Sabre\HTTP\RequestInterface;
34 32
 use \Sabre\HTTP\ResponseInterface;
35
-use Sabre\HTTP\URLUtil;
36 33
 
37 34
 /**
38 35
  * Class DavAclPlugin is a wrapper around \Sabre\DAVACL\Plugin that returns 404
Please login to merge, or discard this patch.
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -43,50 +43,50 @@
 block discarded – undo
43 43
  * @package OCA\DAV\Connector\Sabre
44 44
  */
45 45
 class DavAclPlugin extends \Sabre\DAVACL\Plugin {
46
-	public function __construct() {
47
-		$this->hideNodesFromListings = true;
48
-		$this->allowUnauthenticatedAccess = false;
49
-	}
46
+    public function __construct() {
47
+        $this->hideNodesFromListings = true;
48
+        $this->allowUnauthenticatedAccess = false;
49
+    }
50 50
 
51
-	function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) {
52
-		$access = parent::checkPrivileges($uri, $privileges, $recursion, false);
53
-		if($access === false && $throwExceptions) {
54
-			/** @var INode $node */
55
-			$node = $this->server->tree->getNodeForPath($uri);
51
+    function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) {
52
+        $access = parent::checkPrivileges($uri, $privileges, $recursion, false);
53
+        if($access === false && $throwExceptions) {
54
+            /** @var INode $node */
55
+            $node = $this->server->tree->getNodeForPath($uri);
56 56
 
57
-			switch(get_class($node)) {
58
-				case 'OCA\DAV\CardDAV\AddressBook':
59
-					$type = 'Addressbook';
60
-					break;
61
-				default:
62
-					$type = 'Node';
63
-					break;
64
-			}
65
-			throw new NotFound(
66
-				sprintf(
67
-					"%s with name '%s' could not be found",
68
-					$type,
69
-					$node->getName()
70
-				)
71
-			);
72
-		}
57
+            switch(get_class($node)) {
58
+                case 'OCA\DAV\CardDAV\AddressBook':
59
+                    $type = 'Addressbook';
60
+                    break;
61
+                default:
62
+                    $type = 'Node';
63
+                    break;
64
+            }
65
+            throw new NotFound(
66
+                sprintf(
67
+                    "%s with name '%s' could not be found",
68
+                    $type,
69
+                    $node->getName()
70
+                )
71
+            );
72
+        }
73 73
 
74
-		return $access;
75
-	}
74
+        return $access;
75
+    }
76 76
 
77
-	public function propFind(PropFind $propFind, INode $node) {
78
-		// If the node is neither readable nor writable then fail unless its of
79
-		// the standard user-principal
80
-		if(!($node instanceof User)) {
81
-			$path = $propFind->getPath();
82
-			$readPermissions = $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false);
83
-			$writePermissions = $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, false);
84
-			if ($readPermissions === false && $writePermissions === false) {
85
-				$this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, true);
86
-				$this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, true);
87
-			}
88
-		}
77
+    public function propFind(PropFind $propFind, INode $node) {
78
+        // If the node is neither readable nor writable then fail unless its of
79
+        // the standard user-principal
80
+        if(!($node instanceof User)) {
81
+            $path = $propFind->getPath();
82
+            $readPermissions = $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false);
83
+            $writePermissions = $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, false);
84
+            if ($readPermissions === false && $writePermissions === false) {
85
+                $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, true);
86
+                $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, true);
87
+            }
88
+        }
89 89
 
90
-		return parent::propFind($propFind, $node);
91
-	}
90
+        return parent::propFind($propFind, $node);
91
+    }
92 92
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 
51 51
 	function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) {
52 52
 		$access = parent::checkPrivileges($uri, $privileges, $recursion, false);
53
-		if($access === false && $throwExceptions) {
53
+		if ($access === false && $throwExceptions) {
54 54
 			/** @var INode $node */
55 55
 			$node = $this->server->tree->getNodeForPath($uri);
56 56
 
57
-			switch(get_class($node)) {
57
+			switch (get_class($node)) {
58 58
 				case 'OCA\DAV\CardDAV\AddressBook':
59 59
 					$type = 'Addressbook';
60 60
 					break;
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	public function propFind(PropFind $propFind, INode $node) {
78 78
 		// If the node is neither readable nor writable then fail unless its of
79 79
 		// the standard user-principal
80
-		if(!($node instanceof User)) {
80
+		if (!($node instanceof User)) {
81 81
 			$path = $propFind->getPath();
82 82
 			$readPermissions = $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false);
83 83
 			$writePermissions = $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, false);
Please login to merge, or discard this patch.
lib/private/Files/Storage/Storage.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -100,6 +100,7 @@  discard block
 block discarded – undo
100 100
 	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
101 101
 	 * @param \OCP\Lock\ILockingProvider $provider
102 102
 	 * @throws \OCP\Lock\LockedException
103
+	 * @return void
103 104
 	 */
104 105
 	public function acquireLock($path, $type, ILockingProvider $provider);
105 106
 
@@ -108,6 +109,7 @@  discard block
 block discarded – undo
108 109
 	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
109 110
 	 * @param \OCP\Lock\ILockingProvider $provider
110 111
 	 * @throws \OCP\Lock\LockedException
112
+	 * @return void
111 113
 	 */
112 114
 	public function releaseLock($path, $type, ILockingProvider $provider);
113 115
 
@@ -116,6 +118,7 @@  discard block
 block discarded – undo
116 118
 	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
117 119
 	 * @param \OCP\Lock\ILockingProvider $provider
118 120
 	 * @throws \OCP\Lock\LockedException
121
+	 * @return void
119 122
 	 */
120 123
 	public function changeLock($path, $type, ILockingProvider $provider);
121 124
 }
Please login to merge, or discard this patch.
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -32,90 +32,90 @@
 block discarded – undo
32 32
  */
33 33
 interface Storage extends \OCP\Files\Storage {
34 34
 
35
-	/**
36
-	 * get a cache instance for the storage
37
-	 *
38
-	 * @param string $path
39
-	 * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache
40
-	 * @return \OC\Files\Cache\Cache
41
-	 */
42
-	public function getCache($path = '', $storage = null);
35
+    /**
36
+     * get a cache instance for the storage
37
+     *
38
+     * @param string $path
39
+     * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache
40
+     * @return \OC\Files\Cache\Cache
41
+     */
42
+    public function getCache($path = '', $storage = null);
43 43
 
44
-	/**
45
-	 * get a scanner instance for the storage
46
-	 *
47
-	 * @param string $path
48
-	 * @param \OC\Files\Storage\Storage (optional) the storage to pass to the scanner
49
-	 * @return \OC\Files\Cache\Scanner
50
-	 */
51
-	public function getScanner($path = '', $storage = null);
44
+    /**
45
+     * get a scanner instance for the storage
46
+     *
47
+     * @param string $path
48
+     * @param \OC\Files\Storage\Storage (optional) the storage to pass to the scanner
49
+     * @return \OC\Files\Cache\Scanner
50
+     */
51
+    public function getScanner($path = '', $storage = null);
52 52
 
53 53
 
54
-	/**
55
-	 * get the user id of the owner of a file or folder
56
-	 *
57
-	 * @param string $path
58
-	 * @return string
59
-	 */
60
-	public function getOwner($path);
54
+    /**
55
+     * get the user id of the owner of a file or folder
56
+     *
57
+     * @param string $path
58
+     * @return string
59
+     */
60
+    public function getOwner($path);
61 61
 
62
-	/**
63
-	 * get a watcher instance for the cache
64
-	 *
65
-	 * @param string $path
66
-	 * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
67
-	 * @return \OC\Files\Cache\Watcher
68
-	 */
69
-	public function getWatcher($path = '', $storage = null);
62
+    /**
63
+     * get a watcher instance for the cache
64
+     *
65
+     * @param string $path
66
+     * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
67
+     * @return \OC\Files\Cache\Watcher
68
+     */
69
+    public function getWatcher($path = '', $storage = null);
70 70
 
71
-	/**
72
-	 * get a propagator instance for the cache
73
-	 *
74
-	 * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
75
-	 * @return \OC\Files\Cache\Propagator
76
-	 */
77
-	public function getPropagator($storage = null);
71
+    /**
72
+     * get a propagator instance for the cache
73
+     *
74
+     * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
75
+     * @return \OC\Files\Cache\Propagator
76
+     */
77
+    public function getPropagator($storage = null);
78 78
 
79
-	/**
80
-	 * get a updater instance for the cache
81
-	 *
82
-	 * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
83
-	 * @return \OC\Files\Cache\Updater
84
-	 */
85
-	public function getUpdater($storage = null);
79
+    /**
80
+     * get a updater instance for the cache
81
+     *
82
+     * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
83
+     * @return \OC\Files\Cache\Updater
84
+     */
85
+    public function getUpdater($storage = null);
86 86
 
87
-	/**
88
-	 * @return \OC\Files\Cache\Storage
89
-	 */
90
-	public function getStorageCache();
87
+    /**
88
+     * @return \OC\Files\Cache\Storage
89
+     */
90
+    public function getStorageCache();
91 91
 
92
-	/**
93
-	 * @param string $path
94
-	 * @return array
95
-	 */
96
-	public function getMetaData($path);
92
+    /**
93
+     * @param string $path
94
+     * @return array
95
+     */
96
+    public function getMetaData($path);
97 97
 
98
-	/**
99
-	 * @param string $path The path of the file to acquire the lock for
100
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
101
-	 * @param \OCP\Lock\ILockingProvider $provider
102
-	 * @throws \OCP\Lock\LockedException
103
-	 */
104
-	public function acquireLock($path, $type, ILockingProvider $provider);
98
+    /**
99
+     * @param string $path The path of the file to acquire the lock for
100
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
101
+     * @param \OCP\Lock\ILockingProvider $provider
102
+     * @throws \OCP\Lock\LockedException
103
+     */
104
+    public function acquireLock($path, $type, ILockingProvider $provider);
105 105
 
106
-	/**
107
-	 * @param string $path The path of the file to release the lock for
108
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
109
-	 * @param \OCP\Lock\ILockingProvider $provider
110
-	 * @throws \OCP\Lock\LockedException
111
-	 */
112
-	public function releaseLock($path, $type, ILockingProvider $provider);
106
+    /**
107
+     * @param string $path The path of the file to release the lock for
108
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
109
+     * @param \OCP\Lock\ILockingProvider $provider
110
+     * @throws \OCP\Lock\LockedException
111
+     */
112
+    public function releaseLock($path, $type, ILockingProvider $provider);
113 113
 
114
-	/**
115
-	 * @param string $path The path of the file to change the lock for
116
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
117
-	 * @param \OCP\Lock\ILockingProvider $provider
118
-	 * @throws \OCP\Lock\LockedException
119
-	 */
120
-	public function changeLock($path, $type, ILockingProvider $provider);
114
+    /**
115
+     * @param string $path The path of the file to change the lock for
116
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
117
+     * @param \OCP\Lock\ILockingProvider $provider
118
+     * @throws \OCP\Lock\LockedException
119
+     */
120
+    public function changeLock($path, $type, ILockingProvider $provider);
121 121
 }
Please login to merge, or discard this patch.