From 24672a02a1f5992b22e67ac82a6f6ea82465f715 Mon Sep 17 00:00:00 2001 From: SJ Date: Mon, 26 Nov 2012 23:15:56 +0100 Subject: [PATCH] fixed an SSO issue --- webui/model/user/auth.php | 2 +- webui/model/user/user.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/webui/model/user/auth.php b/webui/model/user/auth.php index 180fabe0..6f3d5dbd 100644 --- a/webui/model/user/auth.php +++ b/webui/model/user/auth.php @@ -82,7 +82,7 @@ class ModelUserAuth extends Model { $_SESSION['username'] = $query->row['username']; $_SESSION['uid'] = $query->row['uid']; $_SESSION['admin_user'] = $query->row['isadmin']; - $_SESSION['email'] = $username; + $_SESSION['email'] = $this->model_user_user->get_primary_email_by_domain($query->row['uid'], $query->row['domain']); $_SESSION['domain'] = $query->row['domain']; $_SESSION['realname'] = $query->row['realname']; diff --git a/webui/model/user/user.php b/webui/model/user/user.php index 7c727f94..befd96c3 100644 --- a/webui/model/user/user.php +++ b/webui/model/user/user.php @@ -124,6 +124,21 @@ class ModelUserUser extends Model { } + public function get_primary_email_by_domain($uid = 0, $domain = '') { + $email = ""; + + $query = $this->db->query("SELECT email FROM " . TABLE_EMAIL . " WHERE uid=?", array((int)$uid)); + + if(isset($query->row)) { $email = $query->row['email']; } + + foreach ($query->rows as $q) { + if(preg_match("/\@$domain$/", $q['email'])) { return $q['email']; } + } + + return $email; + } + + public function get_user_by_dn($dn = '') { if($dn == '') { return array(); }