0 && $userinfo['group']!="")
{
for ($i = 0; $i < count($grouplist); $i++)
{
if (($userinfo['group'] == $grouplist[$i]['ldapgroup']) && is_numeric($grouplist[$i]['rsgroup']))
{
$group = $grouplist[$i]['rsgroup'];
$groupmatch=$userinfo['group'];
}
}
}
if (count($user) > 0)
{
$userid = $user[0]["ref"];
$expires = $user[0]["account_expires"];
if ($expires != "" && $expires != "0000-00-00 00:00:00" && strtotime($expires)<=time())
{
$result['error']=$lang["accountexpired"];
return $result;
}
if ($user[0]["approved"] != 1)
{
return false;
}
// user exists, so update info
if($simpleldap['update_group'])
{
ps_query("update user set origin='simpleldap', password = ?, usergroup = ?, fullname= ?, email= ?, telephone= ? where ref = ?",
[
's', $password_hash,
'i', $group,
's', $displayname,
's', $email,
's', $phone,
'i', $userid
]
);
}
else
{
ps_query("update user set origin='simpleldap', password = ?, fullname= ?, email= ?, telephone= ? where ref = ?",
[
's', $password_hash,
's', $displayname,
's', $email,
's', $phone,
'i', $userid
]
);
}
return true;
}
else
{
// user authenticated, but does not exist, so adopt/create if necessary
if ($simpleldap['createusers'] || $simpleldap['create_new_match_email'])
{
$email_matches= ps_query("select ref, username, fullname from user where email= ?", ['s', $email]);
if(count($email_matches)>0)
{
if(count($email_matches)==1 && $simpleldap['create_new_match_email'])
{
// We want adopt this matching account - update the username and details to match the new login credentials
debug("LDAP - user authenticated with matching email for existing user . " . $email . ", updating user account " . $email_matches[0]["username"] . " to new username " . $username);
if($simpleldap['update_group'])
{
ps_query("update user set origin='simpleldap',username= ?, password= ?, fullname= ?,email= ?,telephone= ?,usergroup= ?,comments=concat(comments,'\n', ?) where ref= ?",
[
's', $username,
's', $password_hash,
's', $displayname,
's', $email,
's', $phone,
'i', $group,
's', date("Y-m-d") . " " . $lang["simpleldap_usermatchcomment"] ,
'i', $email_matches[0]["ref"]
]
);
}
else
{
ps_query("update user set origin='simpleldap',username= ?, password= ?, fullname= ?,email= ?,telephone= ?,comments=concat(comments,'\n', ?) where ref= ?",
[
's', $username,
's', $password_hash,
's', $displayname,
's', $email,
's', $phone,
's', date("Y-m-d") . " " . $lang["simpleldap_usermatchcomment"] ,
'i', $email_matches[0]["ref"]
]
);
}
return true;
}
if (isset($simpleldap['notification_email']) && $simpleldap['notification_email']!="")
{
// Already account(s) with this email address, notify the administrator
global $lang, $baseurl, $email_from;
debug("LDAP - user authenticated with matching email for existing users: " . $email);
$emailtext=$lang['simpleldap_multiple_email_match_text'] . " " . $email . "
";
$emailtext.="
" . $lang["property-name"] . " | " . $lang["property-reference"] . " | " . $lang["username"] . " |
---|---|---|
" . $email_match["fullname"] . " | " . $email_match["ref"] . " | " . $email_match["username"] . " |