Hi, i know that this have been discussed before but i really need some help writing a plugin between the MODX authentication events and SMF forum. (If possible, WebLoginPE). Would be really great if we could get this to work between MODX and SMF.
I took some lines out of the SMF_Module and the smf_api.
Function Login
function smf_LoginById($username, $cookieLength = 3600){
global $smf_connection, $smf_settings;
// enable binary look up for MODx workaround.
$binaryLookup = !empty($smf_settings['reserveCase']) ? 'BINARY':'';
$sql = "SELECT *
FROM $smf_settings[db_prefix]members
WHERE $binaryLookup memberName = '".mysql_escape_string($username)."'
LIMIT 1";
$request = smf_query($sql, __FILE__, __LINE__);
$smf_user = mysql_fetch_assoc($request);
//Now login
smf_setLoginCookie($cookieLength, $smf_user['ID_MEMBER'], sha1($smf_user['passwd'] . $smf_user['passwordSalt']));
return smf_authenticateUser();
}
// Log out user - Added by Raymond
function smf_LogoutById($username){
global $smf_connection, $smf_settings;
Function used to authenticate a user from SMF.
function smf_authenticateUser()
{
global $smf_connection, $smf_settings, $smf_user_info;
// No connection, no authentication!
if (!$smf_connection)
return false;
// Check first the cookie, then the session.
if (isset($_COOKIE[$smf_settings['cookiename']]))
{
$_COOKIE[$smf_settings['cookiename']] = stripslashes($_COOKIE[$smf_settings['cookiename']]);
// Fix a security hole in PHP 4.3.9 and below...
if (preg_match('~^a:[34]:\{i:0;(i:\d{1,6}|s:[1-8]:"\d{1,8}");i:1;s:(0|40):"([a-fA-F0-9]{40})?";i:2;[id]:\d{1,14};(i:3;i:\d;)?\}$~', $_COOKIE[$smf_settings['cookiename']]) == 1)
{
list ($ID_MEMBER, $password) = @unserialize($_COOKIE[$smf_settings['cookiename']]);
$ID_MEMBER = !empty($ID_MEMBER) ? (int) $ID_MEMBER : 0;
}
else
$ID_MEMBER = 0;
}
elseif (isset($_SESSION['login_' . $smf_settings['cookiename']]))
{
list ($ID_MEMBER, $password, $login_span) = @unserialize(stripslashes($_SESSION['login_' . $smf_settings['cookiename']]));
$ID_MEMBER = !empty($ID_MEMBER) && $login_span > time() ? (int) $ID_MEMBER : 0;
}
else
$ID_MEMBER = 0;
Logout function.
function smf_LogoutById($username){
global $smf_connection, $smf_settings;
// enable binary look up for MODx workaround - Raymond
$binaryLookup = !empty($smf_settings['reserveCase']) ? 'BINARY':'';
// shouldn't have to do this but it works!!
$sql = "SELECT *
FROM $smf_settings[db_prefix]members
WHERE $binaryLookup memberName = '".mysql_escape_string($username)."'
LIMIT 1";
$request = smf_query($sql, __FILE__, __LINE__);
$smf_user = mysql_fetch_assoc($request);
smf_query("DELETE FROM $smf_settings[db_prefix]log_online WHERE ID_MEMBER = '".$smf_user['ID_MEMBER']."' LIMIT 1", __FILE__, __LINE__);
unset($_SESSION['login_' . $smf_settings['cookiename']]);
smf_setLoginCookie(-3600, $smf_user['ID_MEMBER']);
smf_setLoginCookie(-3600, 0);
}