From 347045c4c4b074926b298a58e87cbfb7e71e050a Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Fri, 24 Oct 2008 17:59:11 +1300 Subject: [PATCH] Add a function to get the username from an e-mail address. --- inc/CalDAVPrincipal.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/inc/CalDAVPrincipal.php b/inc/CalDAVPrincipal.php index 33978a79..bdafe4b4 100644 --- a/inc/CalDAVPrincipal.php +++ b/inc/CalDAVPrincipal.php @@ -93,6 +93,13 @@ class CalDAVPrincipal else if ( isset($parameters['user_no']) ) { $usr = getUserByID($parameters['user_no']); } + else if ( isset($parameters['email']) && isset($parameters['options']['allow_by_email']) ) { + $parameters['options']['allow_by_email'] = false; + if ( $username = $this->UsernameFromEMail($parameters['email']) ) { + $usr = getUserByName($username); + $this->by_email = true; + } + } else if ( isset($parameters['path']) ) { dbg_error_log( "principal", "Finding Principal from path: '%s', options.allow_by_email: '%s'", $parameters['path'], $parameters['options']['allow_by_email'] ); if ( $username = $this->UsernameFromPath($parameters['path'], $parameters['options']) ) { @@ -209,6 +216,21 @@ class CalDAVPrincipal } + /** + * Work out the username, based on the given e-mail + * @param string $email The email address to be used. + */ + function UsernameFromEMail( $email ) { + $qry = new PgQuery("SELECT user_no, username FROM usr WHERE email = ?;", $email ); + if ( $qry->Exec("principal") && $user = $qry->Fetch() ) { + $user_no = $user->user_no; + $username = $user->username; + } + + return $username; + } + + /** * Returns the array of privilege names converted into XMLElements */