From 5a4854079fbf9c6b359c1c9afdaeb5c6e19609e8 Mon Sep 17 00:00:00 2001
From: Georg Ehrke <dev@georgswebsite.de>
Date: Sun, 26 Aug 2012 16:24:25 +0200
Subject: [PATCH] implement getHome in OC_User

---
 lib/user.php           | 21 +++++++++++++++++++++
 lib/user/backend.php   | 11 +++++++++++
 lib/user/database.php  | 13 +++++++++++++
 lib/user/example.php   | 10 ++++++++++
 lib/user/http.php      | 13 +++++++++++++
 lib/user/interface.php |  7 +++++++
 6 files changed, 75 insertions(+)

diff --git a/lib/user.php b/lib/user.php
index 06a56b7f4a..97ec0c1050 100644
--- a/lib/user.php
+++ b/lib/user.php
@@ -332,6 +332,27 @@ class OC_User {
 		}
 	}
 
+	/**
+	 * @brief Check if the password is correct
+	 * @param $uid The username
+	 * @param $password The password
+	 * @returns string
+	 *
+	 * Check if the password is correct without logging in the user
+	 * returns the user id or false
+	 */
+	public static function getHome($uid){
+		foreach(self::$_usedBackends as $backend){
+			if($backend->implementsActions(OC_USER_BACKEND_GET_HOME)){
+				$result=$backend->getHome($uid);
+				if($result){
+					return $result;
+				}
+			}
+		}
+		return OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ) . '/' . $user;
+	}
+
 	/**
 	 * @brief Get a list of all users
 	 * @returns array with all uids
diff --git a/lib/user/backend.php b/lib/user/backend.php
index f67908cdac..36e4bd9f76 100644
--- a/lib/user/backend.php
+++ b/lib/user/backend.php
@@ -34,6 +34,7 @@ define('OC_USER_BACKEND_NOT_IMPLEMENTED',   -501);
 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);
 
 
 /**
@@ -48,6 +49,7 @@ abstract class OC_User_Backend implements OC_User_Interface {
 		OC_USER_BACKEND_CREATE_USER => 'createUser',
 		OC_USER_BACKEND_SET_PASSWORD => 'setPassword',
 		OC_USER_BACKEND_CHECK_PASSWORD => 'checkPassword',
+		OC_USER_BACKEND_GET_HOME => 'getHome',
 	);
 
 	/**
@@ -109,4 +111,13 @@ abstract class OC_User_Backend implements OC_User_Interface {
 	public function userExists($uid){
 		return false;
 	}
+
+	/**
+	* @brief get the user's home directory
+	* @param string $uid the username
+	* @return boolean
+	*/
+	public function getHome($uid){
+		return false;
+	}
 }
diff --git a/lib/user/database.php b/lib/user/database.php
index dff4d145fc..12cd804641 100644
--- a/lib/user/database.php
+++ b/lib/user/database.php
@@ -175,4 +175,17 @@ class OC_User_Database extends OC_User_Backend {
 		
 		return $result->numRows() > 0;
 	}
+
+	/**
+	* @brief get the user's home directory
+	* @param string $uid the username
+	* @return boolean
+	*/
+	public function getHome($uid){
+		if($this->userExists($uid)){
+			return OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ) . '/' . $user;
+		}else{
+			return false;
+		}
+	}
 }
diff --git a/lib/user/example.php b/lib/user/example.php
index 77246d8136..b2d0dc2541 100644
--- a/lib/user/example.php
+++ b/lib/user/example.php
@@ -57,4 +57,14 @@ abstract class OC_User_Example extends OC_User_Backend {
 		* returns the user id or false
 		*/
 	abstract public function checkPassword($uid, $password);
+
+	/**
+		* @brief get the user's home directory
+		* @param $uid The username
+		* @returns string
+		*
+		* get the user's home directory
+		* returns the path or false
+		*/
+	abstract public function getHome($uid);
 }
diff --git a/lib/user/http.php b/lib/user/http.php
index 009aa30c6f..87f3347a23 100644
--- a/lib/user/http.php
+++ b/lib/user/http.php
@@ -90,4 +90,17 @@ class OC_User_HTTP extends OC_User_Backend {
 	public function userExists($uid){
 		return $this->matchUrl($uid);
 	}
+
+	/**
+	* @brief get the user's home directory
+	* @param string $uid the username
+	* @return boolean
+	*/
+	public function getHome($uid){
+		if($this->userExists($uid)){
+			return OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ) . '/' . $user;
+		}else{
+			return false;
+		}
+	}
 }
\ No newline at end of file
diff --git a/lib/user/interface.php b/lib/user/interface.php
index a4903898fb..5e5efe0010 100644
--- a/lib/user/interface.php
+++ b/lib/user/interface.php
@@ -57,4 +57,11 @@ interface OC_User_Interface {
 	*/
 	public function userExists($uid);
 
+	/**
+	* @brief get the user's home directory
+	* @param string $uid the username
+	* @return boolean
+	*/
+	public function getHome($uid);
+
 }
\ No newline at end of file
-- 
GitLab