@@ -51,291 +51,291 @@ |
||
| 51 | 51 | use OCP\Util; |
| 52 | 52 | |
| 53 | 53 | class LoginController extends Controller { |
| 54 | - /** @var IUserManager */ |
|
| 55 | - private $userManager; |
|
| 56 | - /** @var IConfig */ |
|
| 57 | - private $config; |
|
| 58 | - /** @var ISession */ |
|
| 59 | - private $session; |
|
| 60 | - /** @var IUserSession|Session */ |
|
| 61 | - private $userSession; |
|
| 62 | - /** @var IURLGenerator */ |
|
| 63 | - private $urlGenerator; |
|
| 64 | - /** @var ILogger */ |
|
| 65 | - private $logger; |
|
| 66 | - /** @var Manager */ |
|
| 67 | - private $twoFactorManager; |
|
| 68 | - /** @var Defaults */ |
|
| 69 | - private $defaults; |
|
| 54 | + /** @var IUserManager */ |
|
| 55 | + private $userManager; |
|
| 56 | + /** @var IConfig */ |
|
| 57 | + private $config; |
|
| 58 | + /** @var ISession */ |
|
| 59 | + private $session; |
|
| 60 | + /** @var IUserSession|Session */ |
|
| 61 | + private $userSession; |
|
| 62 | + /** @var IURLGenerator */ |
|
| 63 | + private $urlGenerator; |
|
| 64 | + /** @var ILogger */ |
|
| 65 | + private $logger; |
|
| 66 | + /** @var Manager */ |
|
| 67 | + private $twoFactorManager; |
|
| 68 | + /** @var Defaults */ |
|
| 69 | + private $defaults; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @param string $appName |
|
| 73 | - * @param IRequest $request |
|
| 74 | - * @param IUserManager $userManager |
|
| 75 | - * @param IConfig $config |
|
| 76 | - * @param ISession $session |
|
| 77 | - * @param IUserSession $userSession |
|
| 78 | - * @param IURLGenerator $urlGenerator |
|
| 79 | - * @param ILogger $logger |
|
| 80 | - * @param Manager $twoFactorManager |
|
| 81 | - * @param Defaults $defaults |
|
| 82 | - */ |
|
| 83 | - public function __construct($appName, |
|
| 84 | - IRequest $request, |
|
| 85 | - IUserManager $userManager, |
|
| 86 | - IConfig $config, |
|
| 87 | - ISession $session, |
|
| 88 | - IUserSession $userSession, |
|
| 89 | - IURLGenerator $urlGenerator, |
|
| 90 | - ILogger $logger, |
|
| 91 | - Manager $twoFactorManager, |
|
| 92 | - Defaults $defaults) { |
|
| 93 | - parent::__construct($appName, $request); |
|
| 94 | - $this->userManager = $userManager; |
|
| 95 | - $this->config = $config; |
|
| 96 | - $this->session = $session; |
|
| 97 | - $this->userSession = $userSession; |
|
| 98 | - $this->urlGenerator = $urlGenerator; |
|
| 99 | - $this->logger = $logger; |
|
| 100 | - $this->twoFactorManager = $twoFactorManager; |
|
| 101 | - $this->defaults = $defaults; |
|
| 102 | - } |
|
| 71 | + /** |
|
| 72 | + * @param string $appName |
|
| 73 | + * @param IRequest $request |
|
| 74 | + * @param IUserManager $userManager |
|
| 75 | + * @param IConfig $config |
|
| 76 | + * @param ISession $session |
|
| 77 | + * @param IUserSession $userSession |
|
| 78 | + * @param IURLGenerator $urlGenerator |
|
| 79 | + * @param ILogger $logger |
|
| 80 | + * @param Manager $twoFactorManager |
|
| 81 | + * @param Defaults $defaults |
|
| 82 | + */ |
|
| 83 | + public function __construct($appName, |
|
| 84 | + IRequest $request, |
|
| 85 | + IUserManager $userManager, |
|
| 86 | + IConfig $config, |
|
| 87 | + ISession $session, |
|
| 88 | + IUserSession $userSession, |
|
| 89 | + IURLGenerator $urlGenerator, |
|
| 90 | + ILogger $logger, |
|
| 91 | + Manager $twoFactorManager, |
|
| 92 | + Defaults $defaults) { |
|
| 93 | + parent::__construct($appName, $request); |
|
| 94 | + $this->userManager = $userManager; |
|
| 95 | + $this->config = $config; |
|
| 96 | + $this->session = $session; |
|
| 97 | + $this->userSession = $userSession; |
|
| 98 | + $this->urlGenerator = $urlGenerator; |
|
| 99 | + $this->logger = $logger; |
|
| 100 | + $this->twoFactorManager = $twoFactorManager; |
|
| 101 | + $this->defaults = $defaults; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * @NoAdminRequired |
|
| 106 | - * @UseSession |
|
| 107 | - * |
|
| 108 | - * @return RedirectResponse |
|
| 109 | - */ |
|
| 110 | - public function logout() { |
|
| 111 | - $loginToken = $this->request->getCookie('nc_token'); |
|
| 112 | - if (!is_null($loginToken)) { |
|
| 113 | - $this->config->deleteUserValue($this->userSession->getUser()->getUID(), 'login_token', $loginToken); |
|
| 114 | - } |
|
| 115 | - $this->userSession->logout(); |
|
| 104 | + /** |
|
| 105 | + * @NoAdminRequired |
|
| 106 | + * @UseSession |
|
| 107 | + * |
|
| 108 | + * @return RedirectResponse |
|
| 109 | + */ |
|
| 110 | + public function logout() { |
|
| 111 | + $loginToken = $this->request->getCookie('nc_token'); |
|
| 112 | + if (!is_null($loginToken)) { |
|
| 113 | + $this->config->deleteUserValue($this->userSession->getUser()->getUID(), 'login_token', $loginToken); |
|
| 114 | + } |
|
| 115 | + $this->userSession->logout(); |
|
| 116 | 116 | |
| 117 | - $response = new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm')); |
|
| 118 | - $response->addHeader('Clear-Site-Data', '"cache", "cookies", "storage", "executionContexts"'); |
|
| 119 | - return $response; |
|
| 120 | - } |
|
| 117 | + $response = new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm')); |
|
| 118 | + $response->addHeader('Clear-Site-Data', '"cache", "cookies", "storage", "executionContexts"'); |
|
| 119 | + return $response; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * @PublicPage |
|
| 124 | - * @NoCSRFRequired |
|
| 125 | - * @UseSession |
|
| 126 | - * |
|
| 127 | - * @param string $user |
|
| 128 | - * @param string $redirect_url |
|
| 129 | - * @param string $remember_login |
|
| 130 | - * |
|
| 131 | - * @return TemplateResponse|RedirectResponse |
|
| 132 | - */ |
|
| 133 | - public function showLoginForm($user, $redirect_url, $remember_login) { |
|
| 134 | - if ($this->userSession->isLoggedIn()) { |
|
| 135 | - return new RedirectResponse(OC_Util::getDefaultPageUrl()); |
|
| 136 | - } |
|
| 122 | + /** |
|
| 123 | + * @PublicPage |
|
| 124 | + * @NoCSRFRequired |
|
| 125 | + * @UseSession |
|
| 126 | + * |
|
| 127 | + * @param string $user |
|
| 128 | + * @param string $redirect_url |
|
| 129 | + * @param string $remember_login |
|
| 130 | + * |
|
| 131 | + * @return TemplateResponse|RedirectResponse |
|
| 132 | + */ |
|
| 133 | + public function showLoginForm($user, $redirect_url, $remember_login) { |
|
| 134 | + if ($this->userSession->isLoggedIn()) { |
|
| 135 | + return new RedirectResponse(OC_Util::getDefaultPageUrl()); |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - $parameters = array(); |
|
| 139 | - $loginMessages = $this->session->get('loginMessages'); |
|
| 140 | - $errors = []; |
|
| 141 | - $messages = []; |
|
| 142 | - if (is_array($loginMessages)) { |
|
| 143 | - list($errors, $messages) = $loginMessages; |
|
| 144 | - } |
|
| 145 | - $this->session->remove('loginMessages'); |
|
| 146 | - foreach ($errors as $value) { |
|
| 147 | - $parameters[$value] = true; |
|
| 148 | - } |
|
| 138 | + $parameters = array(); |
|
| 139 | + $loginMessages = $this->session->get('loginMessages'); |
|
| 140 | + $errors = []; |
|
| 141 | + $messages = []; |
|
| 142 | + if (is_array($loginMessages)) { |
|
| 143 | + list($errors, $messages) = $loginMessages; |
|
| 144 | + } |
|
| 145 | + $this->session->remove('loginMessages'); |
|
| 146 | + foreach ($errors as $value) { |
|
| 147 | + $parameters[$value] = true; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - $parameters['messages'] = $messages; |
|
| 151 | - if (!is_null($user) && $user !== '') { |
|
| 152 | - $parameters['loginName'] = $user; |
|
| 153 | - $parameters['user_autofocus'] = false; |
|
| 154 | - } else { |
|
| 155 | - $parameters['loginName'] = ''; |
|
| 156 | - $parameters['user_autofocus'] = true; |
|
| 157 | - } |
|
| 158 | - if (!empty($redirect_url)) { |
|
| 159 | - $parameters['redirect_url'] = $redirect_url; |
|
| 160 | - } |
|
| 150 | + $parameters['messages'] = $messages; |
|
| 151 | + if (!is_null($user) && $user !== '') { |
|
| 152 | + $parameters['loginName'] = $user; |
|
| 153 | + $parameters['user_autofocus'] = false; |
|
| 154 | + } else { |
|
| 155 | + $parameters['loginName'] = ''; |
|
| 156 | + $parameters['user_autofocus'] = true; |
|
| 157 | + } |
|
| 158 | + if (!empty($redirect_url)) { |
|
| 159 | + $parameters['redirect_url'] = $redirect_url; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - $parameters['canResetPassword'] = true; |
|
| 163 | - $parameters['resetPasswordLink'] = $this->config->getSystemValue('lost_password_link', ''); |
|
| 164 | - if (!$parameters['resetPasswordLink']) { |
|
| 165 | - if (!is_null($user) && $user !== '') { |
|
| 166 | - $userObj = $this->userManager->get($user); |
|
| 167 | - if ($userObj instanceof IUser) { |
|
| 168 | - $parameters['canResetPassword'] = $userObj->canChangePassword(); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - } elseif ($parameters['resetPasswordLink'] === 'disabled') { |
|
| 172 | - $parameters['canResetPassword'] = false; |
|
| 173 | - } |
|
| 162 | + $parameters['canResetPassword'] = true; |
|
| 163 | + $parameters['resetPasswordLink'] = $this->config->getSystemValue('lost_password_link', ''); |
|
| 164 | + if (!$parameters['resetPasswordLink']) { |
|
| 165 | + if (!is_null($user) && $user !== '') { |
|
| 166 | + $userObj = $this->userManager->get($user); |
|
| 167 | + if ($userObj instanceof IUser) { |
|
| 168 | + $parameters['canResetPassword'] = $userObj->canChangePassword(); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + } elseif ($parameters['resetPasswordLink'] === 'disabled') { |
|
| 172 | + $parameters['canResetPassword'] = false; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - $parameters['alt_login'] = OC_App::getAlternativeLogIns(); |
|
| 176 | - $parameters['rememberLoginState'] = !empty($remember_login) ? $remember_login : 0; |
|
| 175 | + $parameters['alt_login'] = OC_App::getAlternativeLogIns(); |
|
| 176 | + $parameters['rememberLoginState'] = !empty($remember_login) ? $remember_login : 0; |
|
| 177 | 177 | |
| 178 | - if (!is_null($user) && $user !== '') { |
|
| 179 | - $parameters['loginName'] = $user; |
|
| 180 | - $parameters['user_autofocus'] = false; |
|
| 181 | - } else { |
|
| 182 | - $parameters['loginName'] = ''; |
|
| 183 | - $parameters['user_autofocus'] = true; |
|
| 184 | - } |
|
| 178 | + if (!is_null($user) && $user !== '') { |
|
| 179 | + $parameters['loginName'] = $user; |
|
| 180 | + $parameters['user_autofocus'] = false; |
|
| 181 | + } else { |
|
| 182 | + $parameters['loginName'] = ''; |
|
| 183 | + $parameters['user_autofocus'] = true; |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - // OpenGraph Support: http://ogp.me/ |
|
| 187 | - Util::addHeader('meta', ['property' => 'og:title', 'content' => Util::sanitizeHTML($this->defaults->getName())]); |
|
| 188 | - Util::addHeader('meta', ['property' => 'og:description', 'content' => Util::sanitizeHTML($this->defaults->getSlogan())]); |
|
| 189 | - Util::addHeader('meta', ['property' => 'og:site_name', 'content' => Util::sanitizeHTML($this->defaults->getName())]); |
|
| 190 | - Util::addHeader('meta', ['property' => 'og:url', 'content' => $this->urlGenerator->getAbsoluteURL('/')]); |
|
| 191 | - Util::addHeader('meta', ['property' => 'og:type', 'content' => 'website']); |
|
| 192 | - Util::addHeader('meta', ['property' => 'og:image', 'content' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core','favicon-touch.png'))]); |
|
| 186 | + // OpenGraph Support: http://ogp.me/ |
|
| 187 | + Util::addHeader('meta', ['property' => 'og:title', 'content' => Util::sanitizeHTML($this->defaults->getName())]); |
|
| 188 | + Util::addHeader('meta', ['property' => 'og:description', 'content' => Util::sanitizeHTML($this->defaults->getSlogan())]); |
|
| 189 | + Util::addHeader('meta', ['property' => 'og:site_name', 'content' => Util::sanitizeHTML($this->defaults->getName())]); |
|
| 190 | + Util::addHeader('meta', ['property' => 'og:url', 'content' => $this->urlGenerator->getAbsoluteURL('/')]); |
|
| 191 | + Util::addHeader('meta', ['property' => 'og:type', 'content' => 'website']); |
|
| 192 | + Util::addHeader('meta', ['property' => 'og:image', 'content' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core','favicon-touch.png'))]); |
|
| 193 | 193 | |
| 194 | - return new TemplateResponse( |
|
| 195 | - $this->appName, 'login', $parameters, 'guest' |
|
| 196 | - ); |
|
| 197 | - } |
|
| 194 | + return new TemplateResponse( |
|
| 195 | + $this->appName, 'login', $parameters, 'guest' |
|
| 196 | + ); |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * @param string $redirectUrl |
|
| 201 | - * @return RedirectResponse |
|
| 202 | - */ |
|
| 203 | - private function generateRedirect($redirectUrl) { |
|
| 204 | - if (!is_null($redirectUrl) && $this->userSession->isLoggedIn()) { |
|
| 205 | - $location = $this->urlGenerator->getAbsoluteURL(urldecode($redirectUrl)); |
|
| 206 | - // Deny the redirect if the URL contains a @ |
|
| 207 | - // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
| 208 | - if (strpos($location, '@') === false) { |
|
| 209 | - return new RedirectResponse($location); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - return new RedirectResponse(OC_Util::getDefaultPageUrl()); |
|
| 213 | - } |
|
| 199 | + /** |
|
| 200 | + * @param string $redirectUrl |
|
| 201 | + * @return RedirectResponse |
|
| 202 | + */ |
|
| 203 | + private function generateRedirect($redirectUrl) { |
|
| 204 | + if (!is_null($redirectUrl) && $this->userSession->isLoggedIn()) { |
|
| 205 | + $location = $this->urlGenerator->getAbsoluteURL(urldecode($redirectUrl)); |
|
| 206 | + // Deny the redirect if the URL contains a @ |
|
| 207 | + // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
| 208 | + if (strpos($location, '@') === false) { |
|
| 209 | + return new RedirectResponse($location); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + return new RedirectResponse(OC_Util::getDefaultPageUrl()); |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * @PublicPage |
|
| 217 | - * @UseSession |
|
| 218 | - * @NoCSRFRequired |
|
| 219 | - * @BruteForceProtection(action=login) |
|
| 220 | - * |
|
| 221 | - * @param string $user |
|
| 222 | - * @param string $password |
|
| 223 | - * @param string $redirect_url |
|
| 224 | - * @param boolean $remember_login |
|
| 225 | - * @param string $timezone |
|
| 226 | - * @param string $timezone_offset |
|
| 227 | - * @return RedirectResponse |
|
| 228 | - */ |
|
| 229 | - public function tryLogin($user, $password, $redirect_url, $remember_login = false, $timezone = '', $timezone_offset = '') { |
|
| 230 | - if(!is_string($user)) { |
|
| 231 | - throw new \InvalidArgumentException('Username must be string'); |
|
| 232 | - } |
|
| 215 | + /** |
|
| 216 | + * @PublicPage |
|
| 217 | + * @UseSession |
|
| 218 | + * @NoCSRFRequired |
|
| 219 | + * @BruteForceProtection(action=login) |
|
| 220 | + * |
|
| 221 | + * @param string $user |
|
| 222 | + * @param string $password |
|
| 223 | + * @param string $redirect_url |
|
| 224 | + * @param boolean $remember_login |
|
| 225 | + * @param string $timezone |
|
| 226 | + * @param string $timezone_offset |
|
| 227 | + * @return RedirectResponse |
|
| 228 | + */ |
|
| 229 | + public function tryLogin($user, $password, $redirect_url, $remember_login = false, $timezone = '', $timezone_offset = '') { |
|
| 230 | + if(!is_string($user)) { |
|
| 231 | + throw new \InvalidArgumentException('Username must be string'); |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - // If the user is already logged in and the CSRF check does not pass then |
|
| 235 | - // simply redirect the user to the correct page as required. This is the |
|
| 236 | - // case when an user has already logged-in, in another tab. |
|
| 237 | - if(!$this->request->passesCSRFCheck()) { |
|
| 238 | - return $this->generateRedirect($redirect_url); |
|
| 239 | - } |
|
| 234 | + // If the user is already logged in and the CSRF check does not pass then |
|
| 235 | + // simply redirect the user to the correct page as required. This is the |
|
| 236 | + // case when an user has already logged-in, in another tab. |
|
| 237 | + if(!$this->request->passesCSRFCheck()) { |
|
| 238 | + return $this->generateRedirect($redirect_url); |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | - if ($this->userManager instanceof PublicEmitter) { |
|
| 242 | - $this->userManager->emit('\OC\User', 'preLogin', array($user, $password)); |
|
| 243 | - } |
|
| 241 | + if ($this->userManager instanceof PublicEmitter) { |
|
| 242 | + $this->userManager->emit('\OC\User', 'preLogin', array($user, $password)); |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - $originalUser = $user; |
|
| 246 | - // TODO: Add all the insane error handling |
|
| 247 | - /* @var $loginResult IUser */ |
|
| 248 | - $loginResult = $this->userManager->checkPasswordNoLogging($user, $password); |
|
| 249 | - if ($loginResult === false) { |
|
| 250 | - $users = $this->userManager->getByEmail($user); |
|
| 251 | - // we only allow login by email if unique |
|
| 252 | - if (count($users) === 1) { |
|
| 253 | - $user = $users[0]->getUID(); |
|
| 254 | - $loginResult = $this->userManager->checkPassword($user, $password); |
|
| 255 | - } else { |
|
| 256 | - $this->logger->warning('Login failed: \''. $user .'\' (Remote IP: \''. $this->request->getRemoteAddress(). '\')', ['app' => 'core']); |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - if ($loginResult === false) { |
|
| 260 | - // Read current user and append if possible - we need to return the unmodified user otherwise we will leak the login name |
|
| 261 | - $args = !is_null($user) ? ['user' => $originalUser] : []; |
|
| 262 | - if (!is_null($redirect_url)) { |
|
| 263 | - $args['redirect_url'] = $redirect_url; |
|
| 264 | - } |
|
| 265 | - $response = new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args)); |
|
| 266 | - $response->throttle(['user' => $user]); |
|
| 267 | - $this->session->set('loginMessages', [ |
|
| 268 | - ['invalidpassword'], [] |
|
| 269 | - ]); |
|
| 270 | - return $response; |
|
| 271 | - } |
|
| 272 | - // TODO: remove password checks from above and let the user session handle failures |
|
| 273 | - // requires https://github.com/owncloud/core/pull/24616 |
|
| 274 | - $this->userSession->completeLogin($loginResult, ['loginName' => $user, 'password' => $password]); |
|
| 275 | - $this->userSession->createSessionToken($this->request, $loginResult->getUID(), $user, $password, (int)$remember_login); |
|
| 245 | + $originalUser = $user; |
|
| 246 | + // TODO: Add all the insane error handling |
|
| 247 | + /* @var $loginResult IUser */ |
|
| 248 | + $loginResult = $this->userManager->checkPasswordNoLogging($user, $password); |
|
| 249 | + if ($loginResult === false) { |
|
| 250 | + $users = $this->userManager->getByEmail($user); |
|
| 251 | + // we only allow login by email if unique |
|
| 252 | + if (count($users) === 1) { |
|
| 253 | + $user = $users[0]->getUID(); |
|
| 254 | + $loginResult = $this->userManager->checkPassword($user, $password); |
|
| 255 | + } else { |
|
| 256 | + $this->logger->warning('Login failed: \''. $user .'\' (Remote IP: \''. $this->request->getRemoteAddress(). '\')', ['app' => 'core']); |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + if ($loginResult === false) { |
|
| 260 | + // Read current user and append if possible - we need to return the unmodified user otherwise we will leak the login name |
|
| 261 | + $args = !is_null($user) ? ['user' => $originalUser] : []; |
|
| 262 | + if (!is_null($redirect_url)) { |
|
| 263 | + $args['redirect_url'] = $redirect_url; |
|
| 264 | + } |
|
| 265 | + $response = new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args)); |
|
| 266 | + $response->throttle(['user' => $user]); |
|
| 267 | + $this->session->set('loginMessages', [ |
|
| 268 | + ['invalidpassword'], [] |
|
| 269 | + ]); |
|
| 270 | + return $response; |
|
| 271 | + } |
|
| 272 | + // TODO: remove password checks from above and let the user session handle failures |
|
| 273 | + // requires https://github.com/owncloud/core/pull/24616 |
|
| 274 | + $this->userSession->completeLogin($loginResult, ['loginName' => $user, 'password' => $password]); |
|
| 275 | + $this->userSession->createSessionToken($this->request, $loginResult->getUID(), $user, $password, (int)$remember_login); |
|
| 276 | 276 | |
| 277 | - // User has successfully logged in, now remove the password reset link, when it is available |
|
| 278 | - $this->config->deleteUserValue($loginResult->getUID(), 'core', 'lostpassword'); |
|
| 277 | + // User has successfully logged in, now remove the password reset link, when it is available |
|
| 278 | + $this->config->deleteUserValue($loginResult->getUID(), 'core', 'lostpassword'); |
|
| 279 | 279 | |
| 280 | - $this->session->set('last-password-confirm', $loginResult->getLastLogin()); |
|
| 280 | + $this->session->set('last-password-confirm', $loginResult->getLastLogin()); |
|
| 281 | 281 | |
| 282 | - if ($timezone_offset !== '') { |
|
| 283 | - $this->config->setUserValue($loginResult->getUID(), 'core', 'timezone', $timezone); |
|
| 284 | - $this->session->set('timezone', $timezone_offset); |
|
| 285 | - } |
|
| 282 | + if ($timezone_offset !== '') { |
|
| 283 | + $this->config->setUserValue($loginResult->getUID(), 'core', 'timezone', $timezone); |
|
| 284 | + $this->session->set('timezone', $timezone_offset); |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - if ($this->twoFactorManager->isTwoFactorAuthenticated($loginResult)) { |
|
| 288 | - $this->twoFactorManager->prepareTwoFactorLogin($loginResult, $remember_login); |
|
| 287 | + if ($this->twoFactorManager->isTwoFactorAuthenticated($loginResult)) { |
|
| 288 | + $this->twoFactorManager->prepareTwoFactorLogin($loginResult, $remember_login); |
|
| 289 | 289 | |
| 290 | - $providers = $this->twoFactorManager->getProviders($loginResult); |
|
| 291 | - if (count($providers) === 1) { |
|
| 292 | - // Single provider, hence we can redirect to that provider's challenge page directly |
|
| 293 | - /* @var $provider IProvider */ |
|
| 294 | - $provider = array_pop($providers); |
|
| 295 | - $url = 'core.TwoFactorChallenge.showChallenge'; |
|
| 296 | - $urlParams = [ |
|
| 297 | - 'challengeProviderId' => $provider->getId(), |
|
| 298 | - ]; |
|
| 299 | - } else { |
|
| 300 | - $url = 'core.TwoFactorChallenge.selectChallenge'; |
|
| 301 | - $urlParams = []; |
|
| 302 | - } |
|
| 290 | + $providers = $this->twoFactorManager->getProviders($loginResult); |
|
| 291 | + if (count($providers) === 1) { |
|
| 292 | + // Single provider, hence we can redirect to that provider's challenge page directly |
|
| 293 | + /* @var $provider IProvider */ |
|
| 294 | + $provider = array_pop($providers); |
|
| 295 | + $url = 'core.TwoFactorChallenge.showChallenge'; |
|
| 296 | + $urlParams = [ |
|
| 297 | + 'challengeProviderId' => $provider->getId(), |
|
| 298 | + ]; |
|
| 299 | + } else { |
|
| 300 | + $url = 'core.TwoFactorChallenge.selectChallenge'; |
|
| 301 | + $urlParams = []; |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - if (!is_null($redirect_url)) { |
|
| 305 | - $urlParams['redirect_url'] = $redirect_url; |
|
| 306 | - } |
|
| 304 | + if (!is_null($redirect_url)) { |
|
| 305 | + $urlParams['redirect_url'] = $redirect_url; |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - return new RedirectResponse($this->urlGenerator->linkToRoute($url, $urlParams)); |
|
| 309 | - } |
|
| 308 | + return new RedirectResponse($this->urlGenerator->linkToRoute($url, $urlParams)); |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | - if ($remember_login) { |
|
| 312 | - $this->userSession->createRememberMeToken($loginResult); |
|
| 313 | - } |
|
| 311 | + if ($remember_login) { |
|
| 312 | + $this->userSession->createRememberMeToken($loginResult); |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - return $this->generateRedirect($redirect_url); |
|
| 316 | - } |
|
| 315 | + return $this->generateRedirect($redirect_url); |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - /** |
|
| 319 | - * @NoAdminRequired |
|
| 320 | - * @UseSession |
|
| 321 | - * @BruteForceProtection(action=sudo) |
|
| 322 | - * |
|
| 323 | - * @license GNU AGPL version 3 or any later version |
|
| 324 | - * |
|
| 325 | - * @param string $password |
|
| 326 | - * @return DataResponse |
|
| 327 | - */ |
|
| 328 | - public function confirmPassword($password) { |
|
| 329 | - $loginName = $this->userSession->getLoginName(); |
|
| 330 | - $loginResult = $this->userManager->checkPassword($loginName, $password); |
|
| 331 | - if ($loginResult === false) { |
|
| 332 | - $response = new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 333 | - $response->throttle(); |
|
| 334 | - return $response; |
|
| 335 | - } |
|
| 318 | + /** |
|
| 319 | + * @NoAdminRequired |
|
| 320 | + * @UseSession |
|
| 321 | + * @BruteForceProtection(action=sudo) |
|
| 322 | + * |
|
| 323 | + * @license GNU AGPL version 3 or any later version |
|
| 324 | + * |
|
| 325 | + * @param string $password |
|
| 326 | + * @return DataResponse |
|
| 327 | + */ |
|
| 328 | + public function confirmPassword($password) { |
|
| 329 | + $loginName = $this->userSession->getLoginName(); |
|
| 330 | + $loginResult = $this->userManager->checkPassword($loginName, $password); |
|
| 331 | + if ($loginResult === false) { |
|
| 332 | + $response = new DataResponse([], Http::STATUS_FORBIDDEN); |
|
| 333 | + $response->throttle(); |
|
| 334 | + return $response; |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - $confirmTimestamp = time(); |
|
| 338 | - $this->session->set('last-password-confirm', $confirmTimestamp); |
|
| 339 | - return new DataResponse(['lastLogin' => $confirmTimestamp], Http::STATUS_OK); |
|
| 340 | - } |
|
| 337 | + $confirmTimestamp = time(); |
|
| 338 | + $this->session->set('last-password-confirm', $confirmTimestamp); |
|
| 339 | + return new DataResponse(['lastLogin' => $confirmTimestamp], Http::STATUS_OK); |
|
| 340 | + } |
|
| 341 | 341 | } |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | Util::addHeader('meta', ['property' => 'og:site_name', 'content' => Util::sanitizeHTML($this->defaults->getName())]); |
| 190 | 190 | Util::addHeader('meta', ['property' => 'og:url', 'content' => $this->urlGenerator->getAbsoluteURL('/')]); |
| 191 | 191 | Util::addHeader('meta', ['property' => 'og:type', 'content' => 'website']); |
| 192 | - Util::addHeader('meta', ['property' => 'og:image', 'content' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core','favicon-touch.png'))]); |
|
| 192 | + Util::addHeader('meta', ['property' => 'og:image', 'content' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'favicon-touch.png'))]); |
|
| 193 | 193 | |
| 194 | 194 | return new TemplateResponse( |
| 195 | 195 | $this->appName, 'login', $parameters, 'guest' |
@@ -227,14 +227,14 @@ discard block |
||
| 227 | 227 | * @return RedirectResponse |
| 228 | 228 | */ |
| 229 | 229 | public function tryLogin($user, $password, $redirect_url, $remember_login = false, $timezone = '', $timezone_offset = '') { |
| 230 | - if(!is_string($user)) { |
|
| 230 | + if (!is_string($user)) { |
|
| 231 | 231 | throw new \InvalidArgumentException('Username must be string'); |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | // If the user is already logged in and the CSRF check does not pass then |
| 235 | 235 | // simply redirect the user to the correct page as required. This is the |
| 236 | 236 | // case when an user has already logged-in, in another tab. |
| 237 | - if(!$this->request->passesCSRFCheck()) { |
|
| 237 | + if (!$this->request->passesCSRFCheck()) { |
|
| 238 | 238 | return $this->generateRedirect($redirect_url); |
| 239 | 239 | } |
| 240 | 240 | |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | $user = $users[0]->getUID(); |
| 254 | 254 | $loginResult = $this->userManager->checkPassword($user, $password); |
| 255 | 255 | } else { |
| 256 | - $this->logger->warning('Login failed: \''. $user .'\' (Remote IP: \''. $this->request->getRemoteAddress(). '\')', ['app' => 'core']); |
|
| 256 | + $this->logger->warning('Login failed: \''.$user.'\' (Remote IP: \''.$this->request->getRemoteAddress().'\')', ['app' => 'core']); |
|
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | if ($loginResult === false) { |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | // TODO: remove password checks from above and let the user session handle failures |
| 273 | 273 | // requires https://github.com/owncloud/core/pull/24616 |
| 274 | 274 | $this->userSession->completeLogin($loginResult, ['loginName' => $user, 'password' => $password]); |
| 275 | - $this->userSession->createSessionToken($this->request, $loginResult->getUID(), $user, $password, (int)$remember_login); |
|
| 275 | + $this->userSession->createSessionToken($this->request, $loginResult->getUID(), $user, $password, (int) $remember_login); |
|
| 276 | 276 | |
| 277 | 277 | // User has successfully logged in, now remove the password reset link, when it is available |
| 278 | 278 | $this->config->deleteUserValue($loginResult->getUID(), 'core', 'lostpassword'); |