Add a function to get the username from an e-mail address.

This commit is contained in:
Andrew McMillan 2008-10-24 17:59:11 +13:00
parent c429760384
commit 347045c4c4

View File

@ -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
*/