also set user in UserSession when doing OC_User::setUserId

This commit is contained in:
Robin Appelman 2015-02-02 16:09:30 +01:00
parent 4d805b52cc
commit 434835b326
1 changed files with 36 additions and 5 deletions

View File

@ -64,6 +64,7 @@ class OC_User {
/** /**
* registers backend * registers backend
*
* @param string $backend name of the backend * @param string $backend name of the backend
* @deprecated Add classes by calling OC_User::useBackend() with a class instance instead * @deprecated Add classes by calling OC_User::useBackend() with a class instance instead
* @return bool * @return bool
@ -77,6 +78,7 @@ class OC_User {
/** /**
* gets available backends * gets available backends
*
* @deprecated * @deprecated
* @return array an array of backends * @return array an array of backends
* *
@ -88,6 +90,7 @@ class OC_User {
/** /**
* gets used backends * gets used backends
*
* @deprecated * @deprecated
* @return array an array of backends * @return array an array of backends
* *
@ -99,6 +102,7 @@ class OC_User {
/** /**
* Adds the backend to the list of used backends * Adds the backend to the list of used backends
*
* @param string|OC_User_Interface $backend default: database The backend to use for user management * @param string|OC_User_Interface $backend default: database The backend to use for user management
* @return bool * @return bool
* *
@ -171,6 +175,7 @@ class OC_User {
/** /**
* Create a new user * Create a new user
*
* @param string $uid The username of the user to create * @param string $uid The username of the user to create
* @param string $password The password of the new user * @param string $password The password of the new user
* @throws Exception * @throws Exception
@ -188,6 +193,7 @@ class OC_User {
/** /**
* delete a user * delete a user
*
* @param string $uid The username of the user to delete * @param string $uid The username of the user to delete
* @return bool * @return bool
* *
@ -205,6 +211,7 @@ class OC_User {
/** /**
* Try to login a user * Try to login a user
*
* @param string $loginname The login name of the user to log in * @param string $loginname The login name of the user to log in
* @param string $password The password of the user * @param string $password The password of the user
* @return boolean|null * @return boolean|null
@ -245,14 +252,14 @@ class OC_User {
$uid = $backend->getCurrentUserId(); $uid = $backend->getCurrentUserId();
$run = true; $run = true;
OC_Hook::emit( "OC_User", "pre_login", array( "run" => &$run, "uid" => $uid )); OC_Hook::emit("OC_User", "pre_login", array("run" => &$run, "uid" => $uid));
if($uid) { if ($uid) {
self::setUserId($uid); self::setUserId($uid);
self::setDisplayName($uid); self::setDisplayName($uid);
self::getUserSession()->setLoginName($uid); self::getUserSession()->setLoginName($uid);
OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>'' )); OC_Hook::emit("OC_User", "post_login", array("uid" => $uid, 'password' => ''));
return true; return true;
} }
return false; return false;
@ -286,11 +293,18 @@ class OC_User {
* Sets user id for session and triggers emit * Sets user id for session and triggers emit
*/ */
public static function setUserId($uid) { public static function setUserId($uid) {
\OC::$server->getSession()->set('user_id', $uid); $userSession = \OC::$server->getUserSession();
$userManager = \OC::$server->getUserManager();
if ($user = $userManager->get($uid)) {
$userSession->setUser($user);
} else {
\OC::$server->getSession()->set('user_id', $uid);
}
} }
/** /**
* Sets user display name for session * Sets user display name for session
*
* @param string $uid * @param string $uid
* @param null $displayName * @param null $displayName
* @return bool Whether the display name could get set * @return bool Whether the display name could get set
@ -320,13 +334,14 @@ class OC_User {
* Tries to login the user with HTTP Basic Authentication * Tries to login the user with HTTP Basic Authentication
*/ */
public static function tryBasicAuthLogin() { public static function tryBasicAuthLogin() {
if(!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) { if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) {
\OC_User::login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); \OC_User::login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
} }
} }
/** /**
* Check if the user is logged in, considers also the HTTP basic credentials * Check if the user is logged in, considers also the HTTP basic credentials
*
* @return bool * @return bool
*/ */
public static function isLoggedIn() { public static function isLoggedIn() {
@ -339,6 +354,7 @@ class OC_User {
/** /**
* set incognito mode, e.g. if a user wants to open a public link * set incognito mode, e.g. if a user wants to open a public link
*
* @param bool $status * @param bool $status
*/ */
public static function setIncognitoMode($status) { public static function setIncognitoMode($status) {
@ -347,6 +363,7 @@ class OC_User {
/** /**
* get incognito mode status * get incognito mode status
*
* @return bool * @return bool
*/ */
public static function isIncognitoMode() { public static function isIncognitoMode() {
@ -371,6 +388,7 @@ class OC_User {
/** /**
* Check if the user is an admin user * Check if the user is an admin user
*
* @param string $uid uid of the admin * @param string $uid uid of the admin
* @return bool * @return bool
*/ */
@ -384,6 +402,7 @@ class OC_User {
/** /**
* get the user id of the user currently logged in. * get the user id of the user currently logged in.
*
* @return string uid or false * @return string uid or false
*/ */
public static function getUser() { public static function getUser() {
@ -397,6 +416,7 @@ class OC_User {
/** /**
* get the display name of the user currently logged in. * get the display name of the user currently logged in.
*
* @param string $uid * @param string $uid
* @return string uid or false * @return string uid or false
*/ */
@ -420,6 +440,7 @@ class OC_User {
/** /**
* Autogenerate a password * Autogenerate a password
*
* @return string * @return string
* *
* generates a password * generates a password
@ -430,6 +451,7 @@ class OC_User {
/** /**
* Set password * Set password
*
* @param string $uid The username * @param string $uid The username
* @param string $password The new password * @param string $password The new password
* @param string $recoveryPassword for the encryption app to reset encryption keys * @param string $recoveryPassword for the encryption app to reset encryption keys
@ -448,6 +470,7 @@ class OC_User {
/** /**
* Check whether user can change his avatar * Check whether user can change his avatar
*
* @param string $uid The username * @param string $uid The username
* @return bool * @return bool
* *
@ -464,6 +487,7 @@ class OC_User {
/** /**
* Check whether user can change his password * Check whether user can change his password
*
* @param string $uid The username * @param string $uid The username
* @return bool * @return bool
* *
@ -480,6 +504,7 @@ class OC_User {
/** /**
* Check whether user can change his display name * Check whether user can change his display name
*
* @param string $uid The username * @param string $uid The username
* @return bool * @return bool
* *
@ -496,6 +521,7 @@ class OC_User {
/** /**
* Check if the password is correct * Check if the password is correct
*
* @param string $uid The username * @param string $uid The username
* @param string $password The password * @param string $password The password
* @return string|false user id a string on success, false otherwise * @return string|false user id a string on success, false otherwise
@ -530,6 +556,7 @@ class OC_User {
/** /**
* Get a list of all users * Get a list of all users
*
* @return array an array of all uids * @return array an array of all uids
* *
* Get a list of all users. * Get a list of all users.
@ -548,6 +575,7 @@ class OC_User {
/** /**
* Get a list of all users display name * Get a list of all users display name
*
* @param string $search * @param string $search
* @param int $limit * @param int $limit
* @param int $offset * @param int $offset
@ -567,6 +595,7 @@ class OC_User {
/** /**
* check if a user exists * check if a user exists
*
* @param string $uid the username * @param string $uid the username
* @return boolean * @return boolean
*/ */
@ -615,6 +644,7 @@ class OC_User {
/** /**
* Set cookie value to use in next page load * Set cookie value to use in next page load
*
* @param string $username username to be set * @param string $username username to be set
* @param string $token * @param string $token
*/ */
@ -631,6 +661,7 @@ class OC_User {
/** /**
* Returns the first active backend from self::$_usedBackends. * Returns the first active backend from self::$_usedBackends.
*
* @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend * @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend
*/ */
private static function findFirstActiveUsedBackend() { private static function findFirstActiveUsedBackend() {