new branch which introduces display names

first commit with some infrastructure code
This commit is contained in:
Björn Schießle 2013-01-24 13:07:59 +01:00
parent f9a9fc5670
commit d16574f070
3 changed files with 60 additions and 2 deletions

View File

@ -51,7 +51,15 @@ class User {
public static function getUsers($search = '', $limit = null, $offset = null) {
return \OC_USER::getUsers();
}
/**
* @brief get the user display name of the user currently logged in.
* @return string display name
*/
public static function getDisplayName() {
return \OC_USER::getDisplayName();
}
/**
* @brief Check if the user is logged in
* @returns true/false

View File

@ -251,6 +251,7 @@ class OC_User {
if($uid && $enabled) {
session_regenerate_id(true);
self::setUserId($uid);
self::setDisplayName($uid);
OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>$password ));
return true;
}
@ -264,6 +265,31 @@ class OC_User {
public static function setUserId($uid) {
$_SESSION['user_id'] = $uid;
}
/**
* @brief Sets user display name for session
*/
private static function setDisplayName($uid) {
$_SESSION['display_name'] = self::determineDisplayName($uid);
}
/**
* @brief get display name
* @param $uid The username
* @returns string display name or uid if no display name is defined
*
*/
private static function determineDisplayName( $uid ) {
foreach(self::$_usedBackends as $backend) {
if($backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) {
$result=$backend->getDisplayName( $uid );
if($result) {
return $result;
}
}
}
return $uid;
}
/**
* @brief Logs the current user out and kills all the session data
@ -319,7 +345,20 @@ class OC_User {
return false;
}
}
/**
* @brief get the display name of the user currently logged in.
* @return string uid or false
*/
public static function getDisplayName() {
if( isset($_SESSION['user_id']) AND $_SESSION['user_id'] ) {
return $_SESSION['display_name'];
}
else{
return false;
}
}
/**
* @brief Autogenerate a password
* @returns string

View File

@ -35,6 +35,7 @@ define('OC_USER_BACKEND_CREATE_USER', 0x000001);
define('OC_USER_BACKEND_SET_PASSWORD', 0x000010);
define('OC_USER_BACKEND_CHECK_PASSWORD', 0x000100);
define('OC_USER_BACKEND_GET_HOME', 0x001000);
define('OC_USER_BACKEND_GET_DISPLAYNAME', 0x010000);
/**
@ -50,6 +51,7 @@ abstract class OC_User_Backend implements OC_User_Interface {
OC_USER_BACKEND_SET_PASSWORD => 'setPassword',
OC_USER_BACKEND_CHECK_PASSWORD => 'checkPassword',
OC_USER_BACKEND_GET_HOME => 'getHome',
OC_USER_BACKEND_GET_DISPLAYNAME => 'getDisplayName',
);
/**
@ -120,4 +122,13 @@ abstract class OC_User_Backend implements OC_User_Interface {
public function getHome($uid) {
return false;
}
/**
* @brief get display name of the user
* @param $uid user ID of the user
* @return display name
*/
public function getDisplayName($uid) {
return $uid;
}
}