Completed
Pull Request — master (#9632)
by Christoph
20:58
created
core/Controller/LoginController.php 1 patch
Indentation   +295 added lines, -295 removed lines patch added patch discarded remove patch
@@ -58,299 +58,299 @@
 block discarded – undo
58 58
 use OCP\Util;
59 59
 
60 60
 class LoginController extends Controller {
61
-	/** @var IUserManager */
62
-	private $userManager;
63
-	/** @var IConfig */
64
-	private $config;
65
-	/** @var ISession */
66
-	private $session;
67
-	/** @var IUserSession|Session */
68
-	private $userSession;
69
-	/** @var IURLGenerator */
70
-	private $urlGenerator;
71
-	/** @var ILogger */
72
-	private $logger;
73
-	/** @var Manager */
74
-	private $twoFactorManager;
75
-	/** @var Defaults */
76
-	private $defaults;
77
-	/** @var Throttler */
78
-	private $throttler;
79
-
80
-	/**
81
-	 * @param string $appName
82
-	 * @param IRequest $request
83
-	 * @param IUserManager $userManager
84
-	 * @param IConfig $config
85
-	 * @param ISession $session
86
-	 * @param IUserSession $userSession
87
-	 * @param IURLGenerator $urlGenerator
88
-	 * @param ILogger $logger
89
-	 * @param Manager $twoFactorManager
90
-	 * @param Defaults $defaults
91
-	 * @param Throttler $throttler
92
-	 */
93
-	public function __construct($appName,
94
-								IRequest $request,
95
-								IUserManager $userManager,
96
-								IConfig $config,
97
-								ISession $session,
98
-								IUserSession $userSession,
99
-								IURLGenerator $urlGenerator,
100
-								ILogger $logger,
101
-								Manager $twoFactorManager,
102
-								Defaults $defaults,
103
-								Throttler $throttler) {
104
-		parent::__construct($appName, $request);
105
-		$this->userManager = $userManager;
106
-		$this->config = $config;
107
-		$this->session = $session;
108
-		$this->userSession = $userSession;
109
-		$this->urlGenerator = $urlGenerator;
110
-		$this->logger = $logger;
111
-		$this->twoFactorManager = $twoFactorManager;
112
-		$this->defaults = $defaults;
113
-		$this->throttler = $throttler;
114
-	}
115
-
116
-	/**
117
-	 * @NoAdminRequired
118
-	 * @UseSession
119
-	 *
120
-	 * @return RedirectResponse
121
-	 */
122
-	public function logout() {
123
-		$loginToken = $this->request->getCookie('nc_token');
124
-		if (!is_null($loginToken)) {
125
-			$this->config->deleteUserValue($this->userSession->getUser()->getUID(), 'login_token', $loginToken);
126
-		}
127
-		$this->userSession->logout();
128
-
129
-		$response = new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
130
-		$response->addHeader('Clear-Site-Data', '"cache", "cookies", "storage", "executionContexts"');
131
-		return $response;
132
-	}
133
-
134
-	/**
135
-	 * @PublicPage
136
-	 * @NoCSRFRequired
137
-	 * @UseSession
138
-	 *
139
-	 * @param string $user
140
-	 * @param string $redirect_url
141
-	 *
142
-	 * @return TemplateResponse|RedirectResponse
143
-	 */
144
-	public function showLoginForm(string $user = null, string $redirect_url = null): Http\Response {
145
-
146
-		if ($this->userSession->isLoggedIn()) {
147
-			return new RedirectResponse(OC_Util::getDefaultPageUrl());
148
-		}
149
-
150
-		$parameters = array();
151
-		$loginMessages = $this->session->get('loginMessages');
152
-		$errors = [];
153
-		$messages = [];
154
-		if (is_array($loginMessages)) {
155
-			list($errors, $messages) = $loginMessages;
156
-		}
157
-		$this->session->remove('loginMessages');
158
-		foreach ($errors as $value) {
159
-			$parameters[$value] = true;
160
-		}
161
-
162
-		$parameters['messages'] = $messages;
163
-		if ($user !== null && $user !== '') {
164
-			$parameters['loginName'] = $user;
165
-			$parameters['user_autofocus'] = false;
166
-		} else {
167
-			$parameters['loginName'] = '';
168
-			$parameters['user_autofocus'] = true;
169
-		}
170
-		if (!empty($redirect_url)) {
171
-			$parameters['redirect_url'] = $redirect_url;
172
-		}
173
-
174
-		$parameters['canResetPassword'] = true;
175
-		$parameters['resetPasswordLink'] = $this->config->getSystemValue('lost_password_link', '');
176
-		if (!$parameters['resetPasswordLink']) {
177
-			if ($user !== null && $user !== '') {
178
-				$userObj = $this->userManager->get($user);
179
-				if ($userObj instanceof IUser) {
180
-					$parameters['canResetPassword'] = $userObj->canChangePassword();
181
-				}
182
-			}
183
-		} elseif ($parameters['resetPasswordLink'] === 'disabled') {
184
-			$parameters['canResetPassword'] = false;
185
-		}
186
-
187
-		$parameters['alt_login'] = OC_App::getAlternativeLogIns();
188
-
189
-		if ($user !== null && $user !== '') {
190
-			$parameters['loginName'] = $user;
191
-			$parameters['user_autofocus'] = false;
192
-		} else {
193
-			$parameters['loginName'] = '';
194
-			$parameters['user_autofocus'] = true;
195
-		}
196
-
197
-		$parameters['throttle_delay'] = $this->throttler->getDelay($this->request->getRemoteAddress());
198
-
199
-		// OpenGraph Support: http://ogp.me/
200
-		Util::addHeader('meta', ['property' => 'og:title', 'content' => Util::sanitizeHTML($this->defaults->getName())]);
201
-		Util::addHeader('meta', ['property' => 'og:description', 'content' => Util::sanitizeHTML($this->defaults->getSlogan())]);
202
-		Util::addHeader('meta', ['property' => 'og:site_name', 'content' => Util::sanitizeHTML($this->defaults->getName())]);
203
-		Util::addHeader('meta', ['property' => 'og:url', 'content' => $this->urlGenerator->getAbsoluteURL('/')]);
204
-		Util::addHeader('meta', ['property' => 'og:type', 'content' => 'website']);
205
-		Util::addHeader('meta', ['property' => 'og:image', 'content' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core','favicon-touch.png'))]);
206
-
207
-		return new TemplateResponse(
208
-			$this->appName, 'login', $parameters, 'guest'
209
-		);
210
-	}
211
-
212
-	/**
213
-	 * @param string $redirectUrl
214
-	 * @return RedirectResponse
215
-	 */
216
-	private function generateRedirect($redirectUrl) {
217
-		if (!is_null($redirectUrl) && $this->userSession->isLoggedIn()) {
218
-			$location = $this->urlGenerator->getAbsoluteURL(urldecode($redirectUrl));
219
-			// Deny the redirect if the URL contains a @
220
-			// This prevents unvalidated redirects like ?redirect_url=:[email protected]
221
-			if (strpos($location, '@') === false) {
222
-				return new RedirectResponse($location);
223
-			}
224
-		}
225
-		return new RedirectResponse(OC_Util::getDefaultPageUrl());
226
-	}
227
-
228
-	/**
229
-	 * @PublicPage
230
-	 * @UseSession
231
-	 * @NoCSRFRequired
232
-	 * @BruteForceProtection(action=login)
233
-	 *
234
-	 * @param string $user
235
-	 * @param string $password
236
-	 * @param string $redirect_url
237
-	 * @param boolean $remember_login
238
-	 * @param string $timezone
239
-	 * @param string $timezone_offset
240
-	 * @return RedirectResponse
241
-	 */
242
-	public function tryLogin($user, $password, $redirect_url, $remember_login = true, $timezone = '', $timezone_offset = '') {
243
-		if(!is_string($user)) {
244
-			throw new \InvalidArgumentException('Username must be string');
245
-		}
246
-
247
-		// If the user is already logged in and the CSRF check does not pass then
248
-		// simply redirect the user to the correct page as required. This is the
249
-		// case when an user has already logged-in, in another tab.
250
-		if(!$this->request->passesCSRFCheck()) {
251
-			return $this->generateRedirect($redirect_url);
252
-		}
253
-
254
-		if ($this->userManager instanceof PublicEmitter) {
255
-			$this->userManager->emit('\OC\User', 'preLogin', array($user, $password));
256
-		}
257
-
258
-		$originalUser = $user;
259
-		// TODO: Add all the insane error handling
260
-		/* @var $loginResult IUser */
261
-		$loginResult = $this->userManager->checkPasswordNoLogging($user, $password);
262
-		if ($loginResult === false) {
263
-			$users = $this->userManager->getByEmail($user);
264
-			// we only allow login by email if unique
265
-			if (count($users) === 1) {
266
-				$previousUser = $user;
267
-				$user = $users[0]->getUID();
268
-				if($user !== $previousUser) {
269
-					$loginResult = $this->userManager->checkPassword($user, $password);
270
-				}
271
-			}
272
-		}
273
-		if ($loginResult === false) {
274
-			$this->logger->warning('Login failed: \''. $user .'\' (Remote IP: \''. $this->request->getRemoteAddress(). '\')', ['app' => 'core']);
275
-			// Read current user and append if possible - we need to return the unmodified user otherwise we will leak the login name
276
-			$args = !is_null($user) ? ['user' => $originalUser] : [];
277
-			if (!is_null($redirect_url)) {
278
-				$args['redirect_url'] = $redirect_url;
279
-			}
280
-			$response = new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args));
281
-			$response->throttle(['user' => $user]);
282
-			$this->session->set('loginMessages', [
283
-				['invalidpassword'], []
284
-			]);
285
-			return $response;
286
-		}
287
-		// TODO: remove password checks from above and let the user session handle failures
288
-		// requires https://github.com/owncloud/core/pull/24616
289
-		$this->userSession->completeLogin($loginResult, ['loginName' => $user, 'password' => $password]);
290
-		$this->userSession->createSessionToken($this->request, $loginResult->getUID(), $user, $password, IToken::REMEMBER);
291
-
292
-		// User has successfully logged in, now remove the password reset link, when it is available
293
-		$this->config->deleteUserValue($loginResult->getUID(), 'core', 'lostpassword');
294
-
295
-		$this->session->set('last-password-confirm', $loginResult->getLastLogin());
296
-
297
-		if ($timezone_offset !== '') {
298
-			$this->config->setUserValue($loginResult->getUID(), 'core', 'timezone', $timezone);
299
-			$this->session->set('timezone', $timezone_offset);
300
-		}
301
-
302
-		if ($this->twoFactorManager->isTwoFactorAuthenticated($loginResult)) {
303
-			$this->twoFactorManager->prepareTwoFactorLogin($loginResult, $remember_login);
304
-
305
-			$providers = $this->twoFactorManager->getProviderSet($loginResult)->getProviders();
306
-			if (count($providers) === 1) {
307
-				// Single provider, hence we can redirect to that provider's challenge page directly
308
-				/* @var $provider IProvider */
309
-				$provider = array_pop($providers);
310
-				$url = 'core.TwoFactorChallenge.showChallenge';
311
-				$urlParams = [
312
-					'challengeProviderId' => $provider->getId(),
313
-				];
314
-			} else {
315
-				$url = 'core.TwoFactorChallenge.selectChallenge';
316
-				$urlParams = [];
317
-			}
318
-
319
-			if (!is_null($redirect_url)) {
320
-				$urlParams['redirect_url'] = $redirect_url;
321
-			}
322
-
323
-			return new RedirectResponse($this->urlGenerator->linkToRoute($url, $urlParams));
324
-		}
325
-
326
-		if ($remember_login) {
327
-			$this->userSession->createRememberMeToken($loginResult);
328
-		}
329
-
330
-		return $this->generateRedirect($redirect_url);
331
-	}
332
-
333
-	/**
334
-	 * @NoAdminRequired
335
-	 * @UseSession
336
-	 * @BruteForceProtection(action=sudo)
337
-	 *
338
-	 * @license GNU AGPL version 3 or any later version
339
-	 *
340
-	 * @param string $password
341
-	 * @return DataResponse
342
-	 */
343
-	public function confirmPassword($password) {
344
-		$loginName = $this->userSession->getLoginName();
345
-		$loginResult = $this->userManager->checkPassword($loginName, $password);
346
-		if ($loginResult === false) {
347
-			$response = new DataResponse([], Http::STATUS_FORBIDDEN);
348
-			$response->throttle();
349
-			return $response;
350
-		}
351
-
352
-		$confirmTimestamp = time();
353
-		$this->session->set('last-password-confirm', $confirmTimestamp);
354
-		return new DataResponse(['lastLogin' => $confirmTimestamp], Http::STATUS_OK);
355
-	}
61
+    /** @var IUserManager */
62
+    private $userManager;
63
+    /** @var IConfig */
64
+    private $config;
65
+    /** @var ISession */
66
+    private $session;
67
+    /** @var IUserSession|Session */
68
+    private $userSession;
69
+    /** @var IURLGenerator */
70
+    private $urlGenerator;
71
+    /** @var ILogger */
72
+    private $logger;
73
+    /** @var Manager */
74
+    private $twoFactorManager;
75
+    /** @var Defaults */
76
+    private $defaults;
77
+    /** @var Throttler */
78
+    private $throttler;
79
+
80
+    /**
81
+     * @param string $appName
82
+     * @param IRequest $request
83
+     * @param IUserManager $userManager
84
+     * @param IConfig $config
85
+     * @param ISession $session
86
+     * @param IUserSession $userSession
87
+     * @param IURLGenerator $urlGenerator
88
+     * @param ILogger $logger
89
+     * @param Manager $twoFactorManager
90
+     * @param Defaults $defaults
91
+     * @param Throttler $throttler
92
+     */
93
+    public function __construct($appName,
94
+                                IRequest $request,
95
+                                IUserManager $userManager,
96
+                                IConfig $config,
97
+                                ISession $session,
98
+                                IUserSession $userSession,
99
+                                IURLGenerator $urlGenerator,
100
+                                ILogger $logger,
101
+                                Manager $twoFactorManager,
102
+                                Defaults $defaults,
103
+                                Throttler $throttler) {
104
+        parent::__construct($appName, $request);
105
+        $this->userManager = $userManager;
106
+        $this->config = $config;
107
+        $this->session = $session;
108
+        $this->userSession = $userSession;
109
+        $this->urlGenerator = $urlGenerator;
110
+        $this->logger = $logger;
111
+        $this->twoFactorManager = $twoFactorManager;
112
+        $this->defaults = $defaults;
113
+        $this->throttler = $throttler;
114
+    }
115
+
116
+    /**
117
+     * @NoAdminRequired
118
+     * @UseSession
119
+     *
120
+     * @return RedirectResponse
121
+     */
122
+    public function logout() {
123
+        $loginToken = $this->request->getCookie('nc_token');
124
+        if (!is_null($loginToken)) {
125
+            $this->config->deleteUserValue($this->userSession->getUser()->getUID(), 'login_token', $loginToken);
126
+        }
127
+        $this->userSession->logout();
128
+
129
+        $response = new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
130
+        $response->addHeader('Clear-Site-Data', '"cache", "cookies", "storage", "executionContexts"');
131
+        return $response;
132
+    }
133
+
134
+    /**
135
+     * @PublicPage
136
+     * @NoCSRFRequired
137
+     * @UseSession
138
+     *
139
+     * @param string $user
140
+     * @param string $redirect_url
141
+     *
142
+     * @return TemplateResponse|RedirectResponse
143
+     */
144
+    public function showLoginForm(string $user = null, string $redirect_url = null): Http\Response {
145
+
146
+        if ($this->userSession->isLoggedIn()) {
147
+            return new RedirectResponse(OC_Util::getDefaultPageUrl());
148
+        }
149
+
150
+        $parameters = array();
151
+        $loginMessages = $this->session->get('loginMessages');
152
+        $errors = [];
153
+        $messages = [];
154
+        if (is_array($loginMessages)) {
155
+            list($errors, $messages) = $loginMessages;
156
+        }
157
+        $this->session->remove('loginMessages');
158
+        foreach ($errors as $value) {
159
+            $parameters[$value] = true;
160
+        }
161
+
162
+        $parameters['messages'] = $messages;
163
+        if ($user !== null && $user !== '') {
164
+            $parameters['loginName'] = $user;
165
+            $parameters['user_autofocus'] = false;
166
+        } else {
167
+            $parameters['loginName'] = '';
168
+            $parameters['user_autofocus'] = true;
169
+        }
170
+        if (!empty($redirect_url)) {
171
+            $parameters['redirect_url'] = $redirect_url;
172
+        }
173
+
174
+        $parameters['canResetPassword'] = true;
175
+        $parameters['resetPasswordLink'] = $this->config->getSystemValue('lost_password_link', '');
176
+        if (!$parameters['resetPasswordLink']) {
177
+            if ($user !== null && $user !== '') {
178
+                $userObj = $this->userManager->get($user);
179
+                if ($userObj instanceof IUser) {
180
+                    $parameters['canResetPassword'] = $userObj->canChangePassword();
181
+                }
182
+            }
183
+        } elseif ($parameters['resetPasswordLink'] === 'disabled') {
184
+            $parameters['canResetPassword'] = false;
185
+        }
186
+
187
+        $parameters['alt_login'] = OC_App::getAlternativeLogIns();
188
+
189
+        if ($user !== null && $user !== '') {
190
+            $parameters['loginName'] = $user;
191
+            $parameters['user_autofocus'] = false;
192
+        } else {
193
+            $parameters['loginName'] = '';
194
+            $parameters['user_autofocus'] = true;
195
+        }
196
+
197
+        $parameters['throttle_delay'] = $this->throttler->getDelay($this->request->getRemoteAddress());
198
+
199
+        // OpenGraph Support: http://ogp.me/
200
+        Util::addHeader('meta', ['property' => 'og:title', 'content' => Util::sanitizeHTML($this->defaults->getName())]);
201
+        Util::addHeader('meta', ['property' => 'og:description', 'content' => Util::sanitizeHTML($this->defaults->getSlogan())]);
202
+        Util::addHeader('meta', ['property' => 'og:site_name', 'content' => Util::sanitizeHTML($this->defaults->getName())]);
203
+        Util::addHeader('meta', ['property' => 'og:url', 'content' => $this->urlGenerator->getAbsoluteURL('/')]);
204
+        Util::addHeader('meta', ['property' => 'og:type', 'content' => 'website']);
205
+        Util::addHeader('meta', ['property' => 'og:image', 'content' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core','favicon-touch.png'))]);
206
+
207
+        return new TemplateResponse(
208
+            $this->appName, 'login', $parameters, 'guest'
209
+        );
210
+    }
211
+
212
+    /**
213
+     * @param string $redirectUrl
214
+     * @return RedirectResponse
215
+     */
216
+    private function generateRedirect($redirectUrl) {
217
+        if (!is_null($redirectUrl) && $this->userSession->isLoggedIn()) {
218
+            $location = $this->urlGenerator->getAbsoluteURL(urldecode($redirectUrl));
219
+            // Deny the redirect if the URL contains a @
220
+            // This prevents unvalidated redirects like ?redirect_url=:[email protected]
221
+            if (strpos($location, '@') === false) {
222
+                return new RedirectResponse($location);
223
+            }
224
+        }
225
+        return new RedirectResponse(OC_Util::getDefaultPageUrl());
226
+    }
227
+
228
+    /**
229
+     * @PublicPage
230
+     * @UseSession
231
+     * @NoCSRFRequired
232
+     * @BruteForceProtection(action=login)
233
+     *
234
+     * @param string $user
235
+     * @param string $password
236
+     * @param string $redirect_url
237
+     * @param boolean $remember_login
238
+     * @param string $timezone
239
+     * @param string $timezone_offset
240
+     * @return RedirectResponse
241
+     */
242
+    public function tryLogin($user, $password, $redirect_url, $remember_login = true, $timezone = '', $timezone_offset = '') {
243
+        if(!is_string($user)) {
244
+            throw new \InvalidArgumentException('Username must be string');
245
+        }
246
+
247
+        // If the user is already logged in and the CSRF check does not pass then
248
+        // simply redirect the user to the correct page as required. This is the
249
+        // case when an user has already logged-in, in another tab.
250
+        if(!$this->request->passesCSRFCheck()) {
251
+            return $this->generateRedirect($redirect_url);
252
+        }
253
+
254
+        if ($this->userManager instanceof PublicEmitter) {
255
+            $this->userManager->emit('\OC\User', 'preLogin', array($user, $password));
256
+        }
257
+
258
+        $originalUser = $user;
259
+        // TODO: Add all the insane error handling
260
+        /* @var $loginResult IUser */
261
+        $loginResult = $this->userManager->checkPasswordNoLogging($user, $password);
262
+        if ($loginResult === false) {
263
+            $users = $this->userManager->getByEmail($user);
264
+            // we only allow login by email if unique
265
+            if (count($users) === 1) {
266
+                $previousUser = $user;
267
+                $user = $users[0]->getUID();
268
+                if($user !== $previousUser) {
269
+                    $loginResult = $this->userManager->checkPassword($user, $password);
270
+                }
271
+            }
272
+        }
273
+        if ($loginResult === false) {
274
+            $this->logger->warning('Login failed: \''. $user .'\' (Remote IP: \''. $this->request->getRemoteAddress(). '\')', ['app' => 'core']);
275
+            // Read current user and append if possible - we need to return the unmodified user otherwise we will leak the login name
276
+            $args = !is_null($user) ? ['user' => $originalUser] : [];
277
+            if (!is_null($redirect_url)) {
278
+                $args['redirect_url'] = $redirect_url;
279
+            }
280
+            $response = new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args));
281
+            $response->throttle(['user' => $user]);
282
+            $this->session->set('loginMessages', [
283
+                ['invalidpassword'], []
284
+            ]);
285
+            return $response;
286
+        }
287
+        // TODO: remove password checks from above and let the user session handle failures
288
+        // requires https://github.com/owncloud/core/pull/24616
289
+        $this->userSession->completeLogin($loginResult, ['loginName' => $user, 'password' => $password]);
290
+        $this->userSession->createSessionToken($this->request, $loginResult->getUID(), $user, $password, IToken::REMEMBER);
291
+
292
+        // User has successfully logged in, now remove the password reset link, when it is available
293
+        $this->config->deleteUserValue($loginResult->getUID(), 'core', 'lostpassword');
294
+
295
+        $this->session->set('last-password-confirm', $loginResult->getLastLogin());
296
+
297
+        if ($timezone_offset !== '') {
298
+            $this->config->setUserValue($loginResult->getUID(), 'core', 'timezone', $timezone);
299
+            $this->session->set('timezone', $timezone_offset);
300
+        }
301
+
302
+        if ($this->twoFactorManager->isTwoFactorAuthenticated($loginResult)) {
303
+            $this->twoFactorManager->prepareTwoFactorLogin($loginResult, $remember_login);
304
+
305
+            $providers = $this->twoFactorManager->getProviderSet($loginResult)->getProviders();
306
+            if (count($providers) === 1) {
307
+                // Single provider, hence we can redirect to that provider's challenge page directly
308
+                /* @var $provider IProvider */
309
+                $provider = array_pop($providers);
310
+                $url = 'core.TwoFactorChallenge.showChallenge';
311
+                $urlParams = [
312
+                    'challengeProviderId' => $provider->getId(),
313
+                ];
314
+            } else {
315
+                $url = 'core.TwoFactorChallenge.selectChallenge';
316
+                $urlParams = [];
317
+            }
318
+
319
+            if (!is_null($redirect_url)) {
320
+                $urlParams['redirect_url'] = $redirect_url;
321
+            }
322
+
323
+            return new RedirectResponse($this->urlGenerator->linkToRoute($url, $urlParams));
324
+        }
325
+
326
+        if ($remember_login) {
327
+            $this->userSession->createRememberMeToken($loginResult);
328
+        }
329
+
330
+        return $this->generateRedirect($redirect_url);
331
+    }
332
+
333
+    /**
334
+     * @NoAdminRequired
335
+     * @UseSession
336
+     * @BruteForceProtection(action=sudo)
337
+     *
338
+     * @license GNU AGPL version 3 or any later version
339
+     *
340
+     * @param string $password
341
+     * @return DataResponse
342
+     */
343
+    public function confirmPassword($password) {
344
+        $loginName = $this->userSession->getLoginName();
345
+        $loginResult = $this->userManager->checkPassword($loginName, $password);
346
+        if ($loginResult === false) {
347
+            $response = new DataResponse([], Http::STATUS_FORBIDDEN);
348
+            $response->throttle();
349
+            return $response;
350
+        }
351
+
352
+        $confirmTimestamp = time();
353
+        $this->session->set('last-password-confirm', $confirmTimestamp);
354
+        return new DataResponse(['lastLogin' => $confirmTimestamp], Http::STATUS_OK);
355
+    }
356 356
 }
Please login to merge, or discard this patch.
core/Command/TwoFactorAuth/State.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -35,76 +35,76 @@
 block discarded – undo
35 35
 
36 36
 class State extends Base {
37 37
 
38
-	/** @var IRegistry */
39
-	private $registry;
40
-
41
-	/** @var IUserManager */
42
-	private $userManager;
43
-
44
-	public function __construct(IRegistry $registry, IUserManager $userManager) {
45
-		parent::__construct('twofactorauth:state');
46
-
47
-		$this->registry = $registry;
48
-		$this->userManager = $userManager;
49
-	}
50
-
51
-	protected function configure() {
52
-		parent::configure();
53
-
54
-		$this->setName('twofactorauth:state');
55
-		$this->setDescription('Get the two-factor authentication (2FA) state of a user');
56
-		$this->addArgument('uid', InputArgument::REQUIRED);
57
-	}
58
-
59
-	protected function execute(InputInterface $input, OutputInterface $output) {
60
-		$uid = $input->getArgument('uid');
61
-		$user = $this->userManager->get($uid);
62
-		if (is_null($user)) {
63
-			$output->writeln("<error>Invalid UID</error>");
64
-			return;
65
-		}
66
-
67
-		$providerStates = $this->registry->getProviderStates($user);
68
-		$filtered = $this->filterEnabledDisabledUnknownProviders($providerStates);
69
-		list ($enabled, $disabled) = $filtered;
70
-
71
-		if (!empty($enabled)) {
72
-			$output->writeln("Two-factor authentication is enabled for user $uid");
73
-		} else {
74
-			$output->writeln("Two-factor authentication is not enabled for user $uid");
75
-		}
76
-
77
-		$output->writeln("");
78
-		$this->printProviders("Enabled providers", $enabled, $output);
79
-		$this->printProviders("Disabled providers", $disabled, $output);
80
-	}
81
-
82
-	private function filterEnabledDisabledUnknownProviders(array $providerStates): array {
83
-		$enabled = [];
84
-		$disabled = [];
85
-
86
-		foreach ($providerStates as $providerId => $isEnabled) {
87
-			if ($isEnabled) {
88
-				$enabled[] = $providerId;
89
-			} else {
90
-				$disabled[] = $providerId;
91
-			}
92
-		}
93
-
94
-		return [$enabled, $disabled];
95
-	}
96
-
97
-	private function printProviders(string $title, array $providers,
98
-		OutputInterface $output) {
99
-		if (empty($providers)) {
100
-			// Ignore and don't print anything
101
-			return;
102
-		}
103
-
104
-		$output->writeln($title . ":");
105
-		foreach ($providers as $provider) {
106
-			$output->writeln("- " . $provider);
107
-		}
108
-	}
38
+    /** @var IRegistry */
39
+    private $registry;
40
+
41
+    /** @var IUserManager */
42
+    private $userManager;
43
+
44
+    public function __construct(IRegistry $registry, IUserManager $userManager) {
45
+        parent::__construct('twofactorauth:state');
46
+
47
+        $this->registry = $registry;
48
+        $this->userManager = $userManager;
49
+    }
50
+
51
+    protected function configure() {
52
+        parent::configure();
53
+
54
+        $this->setName('twofactorauth:state');
55
+        $this->setDescription('Get the two-factor authentication (2FA) state of a user');
56
+        $this->addArgument('uid', InputArgument::REQUIRED);
57
+    }
58
+
59
+    protected function execute(InputInterface $input, OutputInterface $output) {
60
+        $uid = $input->getArgument('uid');
61
+        $user = $this->userManager->get($uid);
62
+        if (is_null($user)) {
63
+            $output->writeln("<error>Invalid UID</error>");
64
+            return;
65
+        }
66
+
67
+        $providerStates = $this->registry->getProviderStates($user);
68
+        $filtered = $this->filterEnabledDisabledUnknownProviders($providerStates);
69
+        list ($enabled, $disabled) = $filtered;
70
+
71
+        if (!empty($enabled)) {
72
+            $output->writeln("Two-factor authentication is enabled for user $uid");
73
+        } else {
74
+            $output->writeln("Two-factor authentication is not enabled for user $uid");
75
+        }
76
+
77
+        $output->writeln("");
78
+        $this->printProviders("Enabled providers", $enabled, $output);
79
+        $this->printProviders("Disabled providers", $disabled, $output);
80
+    }
81
+
82
+    private function filterEnabledDisabledUnknownProviders(array $providerStates): array {
83
+        $enabled = [];
84
+        $disabled = [];
85
+
86
+        foreach ($providerStates as $providerId => $isEnabled) {
87
+            if ($isEnabled) {
88
+                $enabled[] = $providerId;
89
+            } else {
90
+                $disabled[] = $providerId;
91
+            }
92
+        }
93
+
94
+        return [$enabled, $disabled];
95
+    }
96
+
97
+    private function printProviders(string $title, array $providers,
98
+        OutputInterface $output) {
99
+        if (empty($providers)) {
100
+            // Ignore and don't print anything
101
+            return;
102
+        }
103
+
104
+        $output->writeln($title . ":");
105
+        foreach ($providers as $provider) {
106
+            $output->writeln("- " . $provider);
107
+        }
108
+    }
109 109
 
110 110
 }
Please login to merge, or discard this patch.
core/register_command.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -43,124 +43,124 @@
 block discarded – undo
43 43
 $application->add(new OC\Core\Command\App\CheckCode());
44 44
 $application->add(new OC\Core\Command\L10n\CreateJs());
45 45
 $application->add(new \OC\Core\Command\Integrity\SignApp(
46
-		\OC::$server->getIntegrityCodeChecker(),
47
-		new \OC\IntegrityCheck\Helpers\FileAccessHelper(),
48
-		\OC::$server->getURLGenerator()
46
+        \OC::$server->getIntegrityCodeChecker(),
47
+        new \OC\IntegrityCheck\Helpers\FileAccessHelper(),
48
+        \OC::$server->getURLGenerator()
49 49
 ));
50 50
 $application->add(new \OC\Core\Command\Integrity\SignCore(
51
-		\OC::$server->getIntegrityCodeChecker(),
52
-		new \OC\IntegrityCheck\Helpers\FileAccessHelper()
51
+        \OC::$server->getIntegrityCodeChecker(),
52
+        new \OC\IntegrityCheck\Helpers\FileAccessHelper()
53 53
 ));
54 54
 $application->add(new \OC\Core\Command\Integrity\CheckApp(
55
-		\OC::$server->getIntegrityCodeChecker()
55
+        \OC::$server->getIntegrityCodeChecker()
56 56
 ));
57 57
 $application->add(new \OC\Core\Command\Integrity\CheckCore(
58
-		\OC::$server->getIntegrityCodeChecker()
58
+        \OC::$server->getIntegrityCodeChecker()
59 59
 ));
60 60
 
61 61
 
62 62
 if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
63
-	$application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager()));
64
-	$application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager()));
65
-	$application->add(new OC\Core\Command\App\Install());
66
-	$application->add(new OC\Core\Command\App\GetPath());
67
-	$application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager()));
63
+    $application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager()));
64
+    $application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager()));
65
+    $application->add(new OC\Core\Command\App\Install());
66
+    $application->add(new OC\Core\Command\App\GetPath());
67
+    $application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager()));
68 68
 
69
-	$application->add(new OC\Core\Command\TwoFactorAuth\Enable(
70
-		\OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager()
71
-	));
72
-	$application->add(new OC\Core\Command\TwoFactorAuth\Disable(
73
-		\OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager()
74
-	));
75
-	$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\State::class));
69
+    $application->add(new OC\Core\Command\TwoFactorAuth\Enable(
70
+        \OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager()
71
+    ));
72
+    $application->add(new OC\Core\Command\TwoFactorAuth\Disable(
73
+        \OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager()
74
+    ));
75
+    $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\State::class));
76 76
 
77
-	$application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig()));
78
-	$application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig()));
79
-	$application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig()));
77
+    $application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig()));
78
+    $application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig()));
79
+    $application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig()));
80 80
 
81
-	$application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig()));
82
-	$application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig()));
83
-	$application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig()));
84
-	$application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig()));
85
-	$application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig()));
86
-	$application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig()));
87
-	$application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig()));
88
-	$application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig()));
81
+    $application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig()));
82
+    $application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig()));
83
+    $application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig()));
84
+    $application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig()));
85
+    $application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig()));
86
+    $application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig()));
87
+    $application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig()));
88
+    $application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig()));
89 89
 
90
-	$application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig())));
91
-	$application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->getLogger()));
92
-	$application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->getDatabaseConnection()));
93
-	$application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher()));
94
-	$application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->getDatabaseConnection()));
95
-	$application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->getDatabaseConnection()));
96
-	$application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager()));
97
-	$application->add(new OC\Core\Command\Db\Migrations\GenerateFromSchemaFileCommand(\OC::$server->getConfig(), \OC::$server->getAppManager(), \OC::$server->getDatabaseConnection()));
98
-	$application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager(), \OC::$server->getConfig()));
90
+    $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig())));
91
+    $application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->getLogger()));
92
+    $application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->getDatabaseConnection()));
93
+    $application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher()));
94
+    $application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->getDatabaseConnection()));
95
+    $application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->getDatabaseConnection()));
96
+    $application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager()));
97
+    $application->add(new OC\Core\Command\Db\Migrations\GenerateFromSchemaFileCommand(\OC::$server->getConfig(), \OC::$server->getAppManager(), \OC::$server->getDatabaseConnection()));
98
+    $application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager(), \OC::$server->getConfig()));
99 99
 
100
-	$application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig()));
101
-	$application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager()));
102
-	$application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager()));
103
-	$application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager()));
104
-	$application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager()));
105
-	$application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper()));
106
-	$application->add(new OC\Core\Command\Encryption\DecryptAll(
107
-		\OC::$server->getEncryptionManager(),
108
-		\OC::$server->getAppManager(),
109
-		\OC::$server->getConfig(),
110
-		new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getUserManager(), new \OC\Files\View()),
111
-		new \Symfony\Component\Console\Helper\QuestionHelper())
112
-	);
100
+    $application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig()));
101
+    $application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager()));
102
+    $application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager()));
103
+    $application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager()));
104
+    $application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager()));
105
+    $application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper()));
106
+    $application->add(new OC\Core\Command\Encryption\DecryptAll(
107
+        \OC::$server->getEncryptionManager(),
108
+        \OC::$server->getAppManager(),
109
+        \OC::$server->getConfig(),
110
+        new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getUserManager(), new \OC\Files\View()),
111
+        new \Symfony\Component\Console\Helper\QuestionHelper())
112
+    );
113 113
 
114
-	$application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig()));
115
-	$application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig()));
114
+    $application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig()));
115
+    $application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig()));
116 116
 
117
-	$view = new \OC\Files\View();
118
-	$util = new \OC\Encryption\Util(
119
-		$view,
120
-		\OC::$server->getUserManager(),
121
-		\OC::$server->getGroupManager(),
122
-		\OC::$server->getConfig()
123
-	);
124
-	$application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot(
125
-			$view,
126
-			\OC::$server->getUserManager(),
127
-			\OC::$server->getConfig(),
128
-			$util,
129
-			new \Symfony\Component\Console\Helper\QuestionHelper()
130
-		)
131
-	);
132
-	$application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util));
117
+    $view = new \OC\Files\View();
118
+    $util = new \OC\Encryption\Util(
119
+        $view,
120
+        \OC::$server->getUserManager(),
121
+        \OC::$server->getGroupManager(),
122
+        \OC::$server->getConfig()
123
+    );
124
+    $application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot(
125
+            $view,
126
+            \OC::$server->getUserManager(),
127
+            \OC::$server->getConfig(),
128
+            $util,
129
+            new \Symfony\Component\Console\Helper\QuestionHelper()
130
+        )
131
+    );
132
+    $application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util));
133 133
 
134
-	$application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory()));
135
-	$application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader()));
136
-	$application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector()));
137
-	$application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig()));
138
-	$application->add(new OC\Core\Command\Maintenance\UpdateHtaccess());
139
-	$application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory()));
134
+    $application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory()));
135
+    $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader()));
136
+    $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector()));
137
+    $application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig()));
138
+    $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess());
139
+    $application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory()));
140 140
 
141
-	$application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class)));
142
-	$application->add(new OC\Core\Command\Maintenance\Repair(
143
-		new \OC\Repair(\OC\Repair::getRepairSteps(), \OC::$server->getEventDispatcher()), \OC::$server->getConfig(),
144
-		\OC::$server->getEventDispatcher(), \OC::$server->getAppManager()));
141
+    $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class)));
142
+    $application->add(new OC\Core\Command\Maintenance\Repair(
143
+        new \OC\Repair(\OC\Repair::getRepairSteps(), \OC::$server->getEventDispatcher()), \OC::$server->getConfig(),
144
+        \OC::$server->getEventDispatcher(), \OC::$server->getAppManager()));
145 145
 
146
-	$application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
147
-	$application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager()));
148
-	$application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager()));
149
-	$application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager()));
150
-	$application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager()));
151
-	$application->add(new OC\Core\Command\User\Report(\OC::$server->getUserManager()));
152
-	$application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager()));
153
-	$application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection()));
154
-	$application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager()));
155
-	$application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
146
+    $application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
147
+    $application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager()));
148
+    $application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager()));
149
+    $application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager()));
150
+    $application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager()));
151
+    $application->add(new OC\Core\Command\User\Report(\OC::$server->getUserManager()));
152
+    $application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager()));
153
+    $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection()));
154
+    $application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager()));
155
+    $application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
156 156
 
157
-	$application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager()));
158
-	$application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
159
-	$application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
157
+    $application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager()));
158
+    $application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
159
+    $application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
160 160
 
161
-	$application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(null), \OC::$server->getL10N('core')));
162
-	$application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null)));
163
-	$application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null)));
161
+    $application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(null), \OC::$server->getL10N('core')));
162
+    $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null)));
163
+    $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null)));
164 164
 } else {
165
-	$application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getSystemConfig()));
165
+    $application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getSystemConfig()));
166 166
 }
Please login to merge, or discard this patch.
core/Migrations/Version14000Date20180522074438.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -31,52 +31,52 @@
 block discarded – undo
31 31
 
32 32
 class Version14000Date20180522074438 extends SimpleMigrationStep {
33 33
 
34
-	/**
35
-	 * @param IOutput $output
36
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
37
-	 * @param array $options
38
-	 */
39
-	public function preSchemaChange(IOutput $output, Closure $schemaClosure,
40
-		array $options) {
34
+    /**
35
+     * @param IOutput $output
36
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
37
+     * @param array $options
38
+     */
39
+    public function preSchemaChange(IOutput $output, Closure $schemaClosure,
40
+        array $options) {
41 41
 		
42
-	}
42
+    }
43 43
 
44
-	public function changeSchema(IOutput $output, Closure $schemaClosure,
45
-		array $options): ISchemaWrapper {
44
+    public function changeSchema(IOutput $output, Closure $schemaClosure,
45
+        array $options): ISchemaWrapper {
46 46
 
47
-		$schema = $schemaClosure();
47
+        $schema = $schemaClosure();
48 48
 
49
-		if (!$schema->hasTable('twofactor_providers')) {
50
-			$table = $schema->createTable('twofactor_providers');
51
-			$table->addColumn('provider_id', 'string',
52
-				[
53
-				'notnull' => true,
54
-				'length' => 32,
55
-			]);
56
-			$table->addColumn('uid', 'string',
57
-				[
58
-				'notnull' => true,
59
-				'length' => 64,
60
-			]);
61
-			$table->addColumn('enabled', 'smallint',
62
-				[
63
-				'notnull' => true,
64
-				'length' => 1,
65
-			]);
66
-			$table->setPrimaryKey(['provider_id', 'uid']);
67
-		}
49
+        if (!$schema->hasTable('twofactor_providers')) {
50
+            $table = $schema->createTable('twofactor_providers');
51
+            $table->addColumn('provider_id', 'string',
52
+                [
53
+                'notnull' => true,
54
+                'length' => 32,
55
+            ]);
56
+            $table->addColumn('uid', 'string',
57
+                [
58
+                'notnull' => true,
59
+                'length' => 64,
60
+            ]);
61
+            $table->addColumn('enabled', 'smallint',
62
+                [
63
+                'notnull' => true,
64
+                'length' => 1,
65
+            ]);
66
+            $table->setPrimaryKey(['provider_id', 'uid']);
67
+        }
68 68
 
69
-		return $schema;
70
-	}
69
+        return $schema;
70
+    }
71 71
 
72
-	/**
73
-	 * @param IOutput $output
74
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
75
-	 * @param array $options
76
-	 */
77
-	public function postSchemaChange(IOutput $output, Closure $schemaClosure,
78
-		array $options) {
72
+    /**
73
+     * @param IOutput $output
74
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
75
+     * @param array $options
76
+     */
77
+    public function postSchemaChange(IOutput $output, Closure $schemaClosure,
78
+        array $options) {
79 79
 		
80
-	}
80
+    }
81 81
 
82 82
 }
Please login to merge, or discard this patch.
lib/private/Authentication/TwoFactorAuth/Registry.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -33,23 +33,23 @@
 block discarded – undo
33 33
 
34 34
 class Registry implements IRegistry {
35 35
 
36
-	/** @var ProviderUserAssignmentDao */
37
-	private $assignmentDao;
36
+    /** @var ProviderUserAssignmentDao */
37
+    private $assignmentDao;
38 38
 
39
-	public function __construct(ProviderUserAssignmentDao $assignmentDao) {
40
-		$this->assignmentDao = $assignmentDao;
41
-	}
39
+    public function __construct(ProviderUserAssignmentDao $assignmentDao) {
40
+        $this->assignmentDao = $assignmentDao;
41
+    }
42 42
 
43
-	public function getProviderStates(IUser $user): array {
44
-		return $this->assignmentDao->getState($user->getUID());
45
-	}
43
+    public function getProviderStates(IUser $user): array {
44
+        return $this->assignmentDao->getState($user->getUID());
45
+    }
46 46
 
47
-	public function enableProviderFor(IProvider $provider, IUser $user) {
48
-		$this->assignmentDao->persist($provider->getId(), $user->getUID(), true);
49
-	}
47
+    public function enableProviderFor(IProvider $provider, IUser $user) {
48
+        $this->assignmentDao->persist($provider->getId(), $user->getUID(), true);
49
+    }
50 50
 
51
-	public function disableProviderFor(IProvider $provider, IUser $user) {
52
-		$this->assignmentDao->persist($provider->getId(), $user->getUID(), false);
53
-	}
51
+    public function disableProviderFor(IProvider $provider, IUser $user) {
52
+        $this->assignmentDao->persist($provider->getId(), $user->getUID(), false);
53
+    }
54 54
 
55 55
 }
Please login to merge, or discard this patch.
lib/private/Authentication/TwoFactorAuth/ProviderLoader.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -34,55 +34,55 @@
 block discarded – undo
34 34
 
35 35
 class ProviderLoader {
36 36
 
37
-	const BACKUP_CODES_APP_ID = 'twofactor_backupcodes';
37
+    const BACKUP_CODES_APP_ID = 'twofactor_backupcodes';
38 38
 
39
-	/** @var IAppManager */
40
-	private $appManager;
39
+    /** @var IAppManager */
40
+    private $appManager;
41 41
 
42
-	public function __construct(IAppManager $appManager) {
43
-		$this->appManager = $appManager;
44
-	}
42
+    public function __construct(IAppManager $appManager) {
43
+        $this->appManager = $appManager;
44
+    }
45 45
 
46
-	/**
47
-	 * Get the list of 2FA providers for the given user
48
-	 *
49
-	 * @return IProvider[]
50
-	 * @throws Exception
51
-	 */
52
-	public function getProviders(IUser $user): array {
53
-		$allApps = $this->appManager->getEnabledAppsForUser($user);
54
-		$providers = [];
46
+    /**
47
+     * Get the list of 2FA providers for the given user
48
+     *
49
+     * @return IProvider[]
50
+     * @throws Exception
51
+     */
52
+    public function getProviders(IUser $user): array {
53
+        $allApps = $this->appManager->getEnabledAppsForUser($user);
54
+        $providers = [];
55 55
 
56
-		foreach ($allApps as $appId) {
57
-			$info = $this->appManager->getAppInfo($appId);
58
-			if (isset($info['two-factor-providers'])) {
59
-				/** @var string[] $providerClasses */
60
-				$providerClasses = $info['two-factor-providers'];
61
-				foreach ($providerClasses as $class) {
62
-					try {
63
-						$this->loadTwoFactorApp($appId);
64
-						$provider = OC::$server->query($class);
65
-						$providers[$provider->getId()] = $provider;
66
-					} catch (QueryException $exc) {
67
-						// Provider class can not be resolved
68
-						throw new Exception("Could not load two-factor auth provider $class");
69
-					}
70
-				}
71
-			}
72
-		}
56
+        foreach ($allApps as $appId) {
57
+            $info = $this->appManager->getAppInfo($appId);
58
+            if (isset($info['two-factor-providers'])) {
59
+                /** @var string[] $providerClasses */
60
+                $providerClasses = $info['two-factor-providers'];
61
+                foreach ($providerClasses as $class) {
62
+                    try {
63
+                        $this->loadTwoFactorApp($appId);
64
+                        $provider = OC::$server->query($class);
65
+                        $providers[$provider->getId()] = $provider;
66
+                    } catch (QueryException $exc) {
67
+                        // Provider class can not be resolved
68
+                        throw new Exception("Could not load two-factor auth provider $class");
69
+                    }
70
+                }
71
+            }
72
+        }
73 73
 
74
-		return $providers;
75
-	}
74
+        return $providers;
75
+    }
76 76
 
77
-	/**
78
-	 * Load an app by ID if it has not been loaded yet
79
-	 *
80
-	 * @param string $appId
81
-	 */
82
-	protected function loadTwoFactorApp(string $appId) {
83
-		if (!OC_App::isAppLoaded($appId)) {
84
-			OC_App::loadApp($appId);
85
-		}
86
-	}
77
+    /**
78
+     * Load an app by ID if it has not been loaded yet
79
+     *
80
+     * @param string $appId
81
+     */
82
+    protected function loadTwoFactorApp(string $appId) {
83
+        if (!OC_App::isAppLoaded($appId)) {
84
+            OC_App::loadApp($appId);
85
+        }
86
+    }
87 87
 
88 88
 }
Please login to merge, or discard this patch.
lib/public/Authentication/TwoFactorAuth/IRegistry.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -39,27 +39,27 @@
 block discarded – undo
39 39
  */
40 40
 interface IRegistry {
41 41
 
42
-	/**
43
-	 * Get a key-value map of providers and their enabled/disabled state for
44
-	 * the given user.
45
-	 *
46
-	 * @since 14.0.0
47
-	 * @return string[] where the array key is the provider ID (string) and the
48
-	 *                  value is the enabled state (bool)
49
-	 */
50
-	public function getProviderStates(IUser $user): array;
42
+    /**
43
+     * Get a key-value map of providers and their enabled/disabled state for
44
+     * the given user.
45
+     *
46
+     * @since 14.0.0
47
+     * @return string[] where the array key is the provider ID (string) and the
48
+     *                  value is the enabled state (bool)
49
+     */
50
+    public function getProviderStates(IUser $user): array;
51 51
 
52
-	/**
53
-	 * Enable the given 2FA provider for the given user
54
-	 *
55
-	 * @since 14.0.0
56
-	 */
57
-	public function enableProviderFor(IProvider $provider, IUser $user);
52
+    /**
53
+     * Enable the given 2FA provider for the given user
54
+     *
55
+     * @since 14.0.0
56
+     */
57
+    public function enableProviderFor(IProvider $provider, IUser $user);
58 58
 
59
-	/**
60
-	 * Disable the given 2FA provider for the given user
61
-	 *
62
-	 * @since 14.0.0
63
-	 */
64
-	public function disableProviderFor(IProvider $provider, IUser $user);
59
+    /**
60
+     * Disable the given 2FA provider for the given user
61
+     *
62
+     * @since 14.0.0
63
+     */
64
+    public function disableProviderFor(IProvider $provider, IUser $user);
65 65
 }
Please login to merge, or discard this patch.
core/Controller/TwoFactorChallengeController.php 1 patch
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -42,171 +42,171 @@
 block discarded – undo
42 42
 
43 43
 class TwoFactorChallengeController extends Controller {
44 44
 
45
-	/** @var Manager */
46
-	private $twoFactorManager;
47
-
48
-	/** @var IUserSession */
49
-	private $userSession;
50
-
51
-	/** @var ISession */
52
-	private $session;
53
-
54
-	/** @var IURLGenerator */
55
-	private $urlGenerator;
56
-
57
-	/**
58
-	 * @param string $appName
59
-	 * @param IRequest $request
60
-	 * @param Manager $twoFactorManager
61
-	 * @param IUserSession $userSession
62
-	 * @param ISession $session
63
-	 * @param IURLGenerator $urlGenerator
64
-	 */
65
-	public function __construct($appName, IRequest $request, Manager $twoFactorManager, IUserSession $userSession,
66
-		ISession $session, IURLGenerator $urlGenerator) {
67
-		parent::__construct($appName, $request);
68
-		$this->twoFactorManager = $twoFactorManager;
69
-		$this->userSession = $userSession;
70
-		$this->session = $session;
71
-		$this->urlGenerator = $urlGenerator;
72
-	}
73
-
74
-	/**
75
-	 * @return string
76
-	 */
77
-	protected function getLogoutUrl() {
78
-		return OC_User::getLogoutUrl($this->urlGenerator);
79
-	}
45
+    /** @var Manager */
46
+    private $twoFactorManager;
47
+
48
+    /** @var IUserSession */
49
+    private $userSession;
50
+
51
+    /** @var ISession */
52
+    private $session;
53
+
54
+    /** @var IURLGenerator */
55
+    private $urlGenerator;
56
+
57
+    /**
58
+     * @param string $appName
59
+     * @param IRequest $request
60
+     * @param Manager $twoFactorManager
61
+     * @param IUserSession $userSession
62
+     * @param ISession $session
63
+     * @param IURLGenerator $urlGenerator
64
+     */
65
+    public function __construct($appName, IRequest $request, Manager $twoFactorManager, IUserSession $userSession,
66
+        ISession $session, IURLGenerator $urlGenerator) {
67
+        parent::__construct($appName, $request);
68
+        $this->twoFactorManager = $twoFactorManager;
69
+        $this->userSession = $userSession;
70
+        $this->session = $session;
71
+        $this->urlGenerator = $urlGenerator;
72
+    }
73
+
74
+    /**
75
+     * @return string
76
+     */
77
+    protected function getLogoutUrl() {
78
+        return OC_User::getLogoutUrl($this->urlGenerator);
79
+    }
80 80
 	
81
-	/**
82
-	 * @param IProvider[] $providers
83
-	 */
84
-	private function splitProvidersAndBackupCodes(array $providers): array {
85
-		$regular = [];
86
-		$backup = null;
87
-		foreach ($providers as $provider) {
88
-			if ($provider->getId() === 'backup_codes') {
89
-				$backup = $provider;
90
-			} else {
91
-				$regular[] = $provider;
92
-			}
93
-		}
94
-
95
-		return [$regular, $backup];
96
-	}
97
-
98
-	/**
99
-	 * @NoAdminRequired
100
-	 * @NoCSRFRequired
101
-	 *
102
-	 * @param string $redirect_url
103
-	 * @return TemplateResponse
104
-	 */
105
-	public function selectChallenge($redirect_url) {
106
-		$user = $this->userSession->getUser();
107
-		$providerSet = $this->twoFactorManager->getProviderSet($user);
108
-		$allProviders = $providerSet->getProviders();
109
-		list($providers, $backupProvider) = $this->splitProvidersAndBackupCodes($allProviders);
110
-
111
-		$data = [
112
-			'providers' => $providers,
113
-			'backupProvider' => $backupProvider,
114
-			'providerMissing' => $providerSet->isProviderMissing(),
115
-			'redirect_url' => $redirect_url,
116
-			'logout_url' => $this->getLogoutUrl(),
117
-		];
118
-		return new TemplateResponse($this->appName, 'twofactorselectchallenge', $data, 'guest');
119
-	}
120
-
121
-	/**
122
-	 * @NoAdminRequired
123
-	 * @NoCSRFRequired
124
-	 * @UseSession
125
-	 *
126
-	 * @param string $challengeProviderId
127
-	 * @param string $redirect_url
128
-	 * @return TemplateResponse|RedirectResponse
129
-	 */
130
-	public function showChallenge($challengeProviderId, $redirect_url) {
131
-		$user = $this->userSession->getUser();
132
-		$providerSet = $this->twoFactorManager->getProviderSet($user);
133
-		$provider = $providerSet->getProvider($challengeProviderId);
134
-		if (is_null($provider)) {
135
-			return new RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.selectChallenge'));
136
-		}
137
-
138
-		$backupProvider = $providerSet->getProvider('backup_codes');
139
-		if (!is_null($backupProvider) && $backupProvider->getId() === $provider->getId()) {
140
-			// Don't show the backup provider link if we're already showing that provider's challenge
141
-			$backupProvider = null;
142
-		}
143
-
144
-		$errorMessage = '';
145
-		$error = false;
146
-		if ($this->session->exists('two_factor_auth_error')) {
147
-			$this->session->remove('two_factor_auth_error');
148
-			$error = true;
149
-			$errorMessage = $this->session->get("two_factor_auth_error_message");
150
-			$this->session->remove('two_factor_auth_error_message');
151
-		}
152
-		$tmpl = $provider->getTemplate($user);
153
-		$tmpl->assign('redirect_url', $redirect_url);
154
-		$data = [
155
-			'error' => $error,
156
-			'error_message' => $errorMessage,
157
-			'provider' => $provider,
158
-			'backupProvider' => $backupProvider,
159
-			'logout_url' => $this->getLogoutUrl(),
160
-			'redirect_url' => $redirect_url,
161
-			'template' => $tmpl->fetchPage(),
162
-		];
163
-		$response = new TemplateResponse($this->appName, 'twofactorshowchallenge', $data, 'guest');
164
-		if ($provider instanceof IProvidesCustomCSP) {
165
-			$response->setContentSecurityPolicy($provider->getCSP());
166
-		}
167
-		return $response;
168
-	}
169
-
170
-	/**
171
-	 * @NoAdminRequired
172
-	 * @NoCSRFRequired
173
-	 * @UseSession
174
-	 *
175
-	 * @UserRateThrottle(limit=5, period=100)
176
-	 *
177
-	 * @param string $challengeProviderId
178
-	 * @param string $challenge
179
-	 * @param string $redirect_url
180
-	 * @return RedirectResponse
181
-	 */
182
-	public function solveChallenge($challengeProviderId, $challenge, $redirect_url = null) {
183
-		$user = $this->userSession->getUser();
184
-		$provider = $this->twoFactorManager->getProvider($user, $challengeProviderId);
185
-		if (is_null($provider)) {
186
-			return new RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.selectChallenge'));
187
-		}
188
-
189
-		try {
190
-			if ($this->twoFactorManager->verifyChallenge($challengeProviderId, $user, $challenge)) {
191
-				if (!is_null($redirect_url)) {
192
-					return new RedirectResponse($this->urlGenerator->getAbsoluteURL(urldecode($redirect_url)));
193
-				}
194
-				return new RedirectResponse(OC_Util::getDefaultPageUrl());
195
-			}
196
-		} catch (TwoFactorException $e) {
197
-			/*
81
+    /**
82
+     * @param IProvider[] $providers
83
+     */
84
+    private function splitProvidersAndBackupCodes(array $providers): array {
85
+        $regular = [];
86
+        $backup = null;
87
+        foreach ($providers as $provider) {
88
+            if ($provider->getId() === 'backup_codes') {
89
+                $backup = $provider;
90
+            } else {
91
+                $regular[] = $provider;
92
+            }
93
+        }
94
+
95
+        return [$regular, $backup];
96
+    }
97
+
98
+    /**
99
+     * @NoAdminRequired
100
+     * @NoCSRFRequired
101
+     *
102
+     * @param string $redirect_url
103
+     * @return TemplateResponse
104
+     */
105
+    public function selectChallenge($redirect_url) {
106
+        $user = $this->userSession->getUser();
107
+        $providerSet = $this->twoFactorManager->getProviderSet($user);
108
+        $allProviders = $providerSet->getProviders();
109
+        list($providers, $backupProvider) = $this->splitProvidersAndBackupCodes($allProviders);
110
+
111
+        $data = [
112
+            'providers' => $providers,
113
+            'backupProvider' => $backupProvider,
114
+            'providerMissing' => $providerSet->isProviderMissing(),
115
+            'redirect_url' => $redirect_url,
116
+            'logout_url' => $this->getLogoutUrl(),
117
+        ];
118
+        return new TemplateResponse($this->appName, 'twofactorselectchallenge', $data, 'guest');
119
+    }
120
+
121
+    /**
122
+     * @NoAdminRequired
123
+     * @NoCSRFRequired
124
+     * @UseSession
125
+     *
126
+     * @param string $challengeProviderId
127
+     * @param string $redirect_url
128
+     * @return TemplateResponse|RedirectResponse
129
+     */
130
+    public function showChallenge($challengeProviderId, $redirect_url) {
131
+        $user = $this->userSession->getUser();
132
+        $providerSet = $this->twoFactorManager->getProviderSet($user);
133
+        $provider = $providerSet->getProvider($challengeProviderId);
134
+        if (is_null($provider)) {
135
+            return new RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.selectChallenge'));
136
+        }
137
+
138
+        $backupProvider = $providerSet->getProvider('backup_codes');
139
+        if (!is_null($backupProvider) && $backupProvider->getId() === $provider->getId()) {
140
+            // Don't show the backup provider link if we're already showing that provider's challenge
141
+            $backupProvider = null;
142
+        }
143
+
144
+        $errorMessage = '';
145
+        $error = false;
146
+        if ($this->session->exists('two_factor_auth_error')) {
147
+            $this->session->remove('two_factor_auth_error');
148
+            $error = true;
149
+            $errorMessage = $this->session->get("two_factor_auth_error_message");
150
+            $this->session->remove('two_factor_auth_error_message');
151
+        }
152
+        $tmpl = $provider->getTemplate($user);
153
+        $tmpl->assign('redirect_url', $redirect_url);
154
+        $data = [
155
+            'error' => $error,
156
+            'error_message' => $errorMessage,
157
+            'provider' => $provider,
158
+            'backupProvider' => $backupProvider,
159
+            'logout_url' => $this->getLogoutUrl(),
160
+            'redirect_url' => $redirect_url,
161
+            'template' => $tmpl->fetchPage(),
162
+        ];
163
+        $response = new TemplateResponse($this->appName, 'twofactorshowchallenge', $data, 'guest');
164
+        if ($provider instanceof IProvidesCustomCSP) {
165
+            $response->setContentSecurityPolicy($provider->getCSP());
166
+        }
167
+        return $response;
168
+    }
169
+
170
+    /**
171
+     * @NoAdminRequired
172
+     * @NoCSRFRequired
173
+     * @UseSession
174
+     *
175
+     * @UserRateThrottle(limit=5, period=100)
176
+     *
177
+     * @param string $challengeProviderId
178
+     * @param string $challenge
179
+     * @param string $redirect_url
180
+     * @return RedirectResponse
181
+     */
182
+    public function solveChallenge($challengeProviderId, $challenge, $redirect_url = null) {
183
+        $user = $this->userSession->getUser();
184
+        $provider = $this->twoFactorManager->getProvider($user, $challengeProviderId);
185
+        if (is_null($provider)) {
186
+            return new RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.selectChallenge'));
187
+        }
188
+
189
+        try {
190
+            if ($this->twoFactorManager->verifyChallenge($challengeProviderId, $user, $challenge)) {
191
+                if (!is_null($redirect_url)) {
192
+                    return new RedirectResponse($this->urlGenerator->getAbsoluteURL(urldecode($redirect_url)));
193
+                }
194
+                return new RedirectResponse(OC_Util::getDefaultPageUrl());
195
+            }
196
+        } catch (TwoFactorException $e) {
197
+            /*
198 198
 			 * The 2FA App threw an TwoFactorException. Now we display more
199 199
 			 * information to the user. The exception text is stored in the
200 200
 			 * session to be used in showChallenge()
201 201
 			 */
202
-			$this->session->set('two_factor_auth_error_message', $e->getMessage());
203
-		}
204
-
205
-		$this->session->set('two_factor_auth_error', true);
206
-		return new RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.showChallenge', [
207
-			'challengeProviderId' => $provider->getId(),
208
-			'redirect_url' => $redirect_url,
209
-		]));
210
-	}
202
+            $this->session->set('two_factor_auth_error_message', $e->getMessage());
203
+        }
204
+
205
+        $this->session->set('two_factor_auth_error', true);
206
+        return new RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.showChallenge', [
207
+            'challengeProviderId' => $provider->getId(),
208
+            'redirect_url' => $redirect_url,
209
+        ]));
210
+    }
211 211
 
212 212
 }
Please login to merge, or discard this patch.
lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -35,52 +35,52 @@
 block discarded – undo
35 35
  */
36 36
 class ProviderUserAssignmentDao {
37 37
 
38
-	const TABLE_NAME = 'twofactor_providers';
38
+    const TABLE_NAME = 'twofactor_providers';
39 39
 
40
-	/** @var IDBConnection */
41
-	private $conn;
40
+    /** @var IDBConnection */
41
+    private $conn;
42 42
 
43
-	public function __construct(IDBConnection $dbConn) {
44
-		$this->conn = $dbConn;
45
-	}
43
+    public function __construct(IDBConnection $dbConn) {
44
+        $this->conn = $dbConn;
45
+    }
46 46
 
47
-	/**
48
-	 * Get all assigned provider IDs for the given user ID
49
-	 *
50
-	 * @return string[] where the array key is the provider ID (string) and the
51
-	 *                  value is the enabled state (bool)
52
-	 */
53
-	public function getState(string $uid): array {
54
-		$qb = $this->conn->getQueryBuilder();
47
+    /**
48
+     * Get all assigned provider IDs for the given user ID
49
+     *
50
+     * @return string[] where the array key is the provider ID (string) and the
51
+     *                  value is the enabled state (bool)
52
+     */
53
+    public function getState(string $uid): array {
54
+        $qb = $this->conn->getQueryBuilder();
55 55
 
56
-		$query = $qb->select('provider_id', 'enabled')
57
-			->from(self::TABLE_NAME)
58
-			->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)));
59
-		$result = $query->execute();
60
-		$providers = [];
61
-		foreach ($result->fetchAll() as $row) {
62
-			$providers[$row['provider_id']] = 1 === (int) $row['enabled'];
63
-		}
64
-		$result->closeCursor();
56
+        $query = $qb->select('provider_id', 'enabled')
57
+            ->from(self::TABLE_NAME)
58
+            ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)));
59
+        $result = $query->execute();
60
+        $providers = [];
61
+        foreach ($result->fetchAll() as $row) {
62
+            $providers[$row['provider_id']] = 1 === (int) $row['enabled'];
63
+        }
64
+        $result->closeCursor();
65 65
 
66
-		return $providers;
67
-	}
66
+        return $providers;
67
+    }
68 68
 
69
-	/**
70
-	 * Persist a new/updated (provider_id, uid, enabled) tuple
71
-	 */
72
-	public function persist(string $providerId, string $uid, bool $enabled) {
73
-		$qb = $this->conn->getQueryBuilder();
69
+    /**
70
+     * Persist a new/updated (provider_id, uid, enabled) tuple
71
+     */
72
+    public function persist(string $providerId, string $uid, bool $enabled) {
73
+        $qb = $this->conn->getQueryBuilder();
74 74
 
75
-		// TODO: concurrency? What if (providerId, uid) private key is inserted
76
-		//       twice at the same time?
77
-		$query = $qb->insert(self::TABLE_NAME)->values([
78
-			'provider_id' => $qb->createNamedParameter($providerId),
79
-			'uid' => $qb->createNamedParameter($uid),
80
-			'enabled' => $qb->createNamedParameter($enabled, IQueryBuilder::PARAM_BOOL),
81
-		]);
75
+        // TODO: concurrency? What if (providerId, uid) private key is inserted
76
+        //       twice at the same time?
77
+        $query = $qb->insert(self::TABLE_NAME)->values([
78
+            'provider_id' => $qb->createNamedParameter($providerId),
79
+            'uid' => $qb->createNamedParameter($uid),
80
+            'enabled' => $qb->createNamedParameter($enabled, IQueryBuilder::PARAM_BOOL),
81
+        ]);
82 82
 
83
-		$query->execute();
84
-	}
83
+        $query->execute();
84
+    }
85 85
 
86 86
 }
Please login to merge, or discard this patch.