Skip to content

Commit

Permalink
Merge pull request #4430 from nextcloud/refactor-auth
Browse files Browse the repository at this point in the history
Improve readability of login logic
  • Loading branch information
rullzer authored Apr 26, 2017
2 parents bec9f18 + fff6d6e commit 5b5c3a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
19 changes: 7 additions & 12 deletions lib/private/legacy/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,25 +332,20 @@ private static function loginUser() {
$userSession = \OC::$server->getUserSession();
$request = \OC::$server->getRequest();
try {
$loginSuccess = $userSession->tryTokenLogin($request);
if (!$loginSuccess) {
$loginSuccess = $userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler());
if ($userSession->tryTokenLogin($request)
|| $userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) {
self::$logoutRequired = true;
} else {
return false;
}
} catch (\OC\User\LoginException $e) {
return false;
}

if ($loginSuccess === true) {
self::$logoutRequired = true;

// initialize the user's filesystem
\OC_Util::setupFS(\OC_User::getUser());
self::$isLoggedIn = true;

return \OC_User::getUser();
} catch (\OC\User\LoginException $e) {
return false;
}

return false;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions lib/private/legacy/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ public static function loginWithApache(\OCP\Authentication\IApacheBackend $backe
if($setUidAsDisplayName) {
self::setDisplayName($uid);
}
self::getUserSession()->setLoginName($uid);
$userSession = self::getUserSession();
$userSession->setLoginName($uid);
$request = OC::$server->getRequest();
self::getUserSession()->createSessionToken($request, $uid, $uid);
$userSession->createSessionToken($request, $uid, $uid);
// setup the filesystem
OC_Util::setupFS($uid);
// first call the post_login hooks, the login-process needs to be
Expand Down

0 comments on commit 5b5c3a1

Please sign in to comment.