/** * Gets the user's info * * Will take the users email, username or member id and return their data * * @param int || string $username the user's email address username or member id * @return array $results containing the user info || bool false * @since 0.1.2 */ function smfapi_getUserData($username = '') { if ('' == $username) { return false; } $user_data = array(); // we'll try id || email, then username if (is_numeric($username)) { // number is most likely a member id $user_data = smfapi_getUserById($username); } else { // the email can't be purely numeric $user_data = smfapi_getUserByEmail($username); } if (empty($user_data)) { $user_data = smfapi_getUserByUsername($username); } if (empty($user_data)) { return false; } else { return $user_data; } }
/** * Will log out a user * * Takes a username, email or member id and logs that user out. If it can't find * a match it will look for the currently logged user if any. * * @param string $username user's member name (or int member id or string email) * @return bool whether logout was successful or not * @since 0.1.0 */ function smfapi_logout($username = '') { global $sourcedir, $user_info, $user_settings, $context, $modSettings, $smcFunc; if ('' == $username && $user_info['is_guest']) { return false; } $user_data = smfapi_getUserData($username); if (!$user_data) { if (isset($user_info['id_member']) && false !== smfapi_getUserById($user_info['id_member'])) { $user_data['id_member'] = $user_info['id_member']; } else { return false; } } // if you log out, you aren't online anymore :P. $smcFunc['db_query']('', ' DELETE FROM {db_prefix}log_online WHERE id_member = {int:current_member}', array('current_member' => $user_data['id_member'])); if (isset($_SESSION['pack_ftp'])) { $_SESSION['pack_ftp'] = null; } // they cannot be open ID verified any longer. if (isset($_SESSION['openid'])) { unset($_SESSION['openid']); } // it won't be first login anymore. unset($_SESSION['first_login']); smfapi_setLoginCookie(-3600, 0); return true; }
/** * @param $uid */ static function smfOnUserDelete($uid) { global $modx, $MODX_SMF; if ($data = smfapi_getUserById($uid)) { $username = $data['member_name']; if ($user = $modx->getObject('modUser', array('username' => $username))) { $response = $MODX_SMF->runProcessor('security/user/delete', array('id' => $user->id)); if ($response->isError()) { $modx->log(modX::LOG_LEVEL_ERROR, "[SMF] Could not delete user \"{$username}\": " . print_r($response->getAllErrors(), true)); } } } }