Advertisement:

Author Topic: New tools to help integrating SMF with something else  (Read 220425 times)

Offline DECEiFER

  • Newbie
  • *
  • Posts: 2
Re: New tools to help integrating SMF with something else
« Reply #40 on: February 18, 2012, 02:22:05 AM »
Hi. I've just come across your API tonight as I am building a custom system from scratch that I'd like to bridge with SMF 2.

I'm just performing a few tests at the moment to see how the API works. I've managed to register a user just fine, but no activation e-mails are being sent out, and I've noticed that there's nothing in the API for that. I'm not familiar with SMF as I've always been a phpBB user up to now (shame on me!), so I was wondering if there's any method to generate the activation e-mail from the forum's settings (i.e. use the default)?

Here is my *working* test implementation:

Code: [Select]
public function run() {
include "libs/nucaptcha/leapmarketingclient.php";
include "config/settings.php";
include "smf_2_api.php";

// First, check to see if all of our VALID arguments are there (NOTE that $_POST is passed first, which invalidates the need for checkPostVar).
if(!Common::checkPost() || !Common::areAllArgumentsSet($_POST, $_POST['username'], $_POST['password'], $_POST['verifypassword'], $_POST['email'], $_POST['country'])) {
Common::error("You have not completely filled out the form.");
return;
}

Common::makePostSafe($_POST);

// Next, see if our NuCaptcha data matches.
if($regUsingLeap && array_key_exists('leap', $_SESSION) && Leap::WasSubmitted()) {
Leap::SetClientKey($regLeapClientKey);
$lastTransaction = Leap::ValidateTransaction($_SESSION['leap']);
if($lastTransaction !== true) {
Common::error("You have incorrectly entered the moving red letters.");
return;
}
}

$regOptions['member_name'] = $_POST['username'];
$regOptions['password'] = $_POST['password'];
$regOptions['password_check'] = $_POST['verifypassword'];
$regOptions['email'] = $_POST['email'];
$regOptions['location'] = $_POST['country'];
$regOptions['require'] = "activation";

if (smfapi_registerMember($regOptions) !== false) echo "Success";
else echo "Fail";
}

I know it's just a matter of getting the verification_code from the database, which seems to be generated and then inserted to the database just fine in the smfapi_registerMember() function. I just need to know how to generate the activation e-mail body, where this is stored in SMF:

Quote from: SMF Activation E-mail
Thank you for registering at R N' D Studios - Forum. Your username is DECEiFER. If you forget your password, you can reset it by visiting forum.com/index.php?action=reminder.

Before you can login, you first need to activate your account. To do so, please follow this link:

forum.com/index.php?action=activate;u=1;code=xxxxxxxxxx

Should you have any problems with activation, please visit forum.com/index.php?action=activate;u=1 use the code "xxxxxxxxxx".

Regards,
Forum Team.

Once I have that, I can simply work the rest out. :)


Thanks in advance for any assistance.
« Last Edit: February 18, 2012, 02:25:23 AM by DECEiFER »

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #41 on: February 18, 2012, 03:37:28 AM »
im trying to synchronize the login of my site with smf.

im using it this way:

Code: [Select]
require_once ('/forum/smf_2_api.php');
if (smfapi_authenticate($username, $password))
smfapi_login($username);

but nothing seems to happen.

i open 2 browser tabs, my site and smf, bothe logged off.

i login into my website and go to smf tab and refresh the page, but its still logged off!

can you help me?

@frytec try this:
Code: [Select]
require_once ('/forum/smf_2_api.php');
smfapi_login($username);
Make sure the $username variable is populated and contains a valid SMF username, email address or SMF ID
ALso, be sure your SMF cookie is set on path '/'



Hi. I've just come across your API tonight as I am building a custom system from scratch that I'd like to bridge with SMF 2.

I'm just performing a few tests at the moment to see how the API works. I've managed to register a user just fine, but no activation e-mails are being sent out, and I've noticed that there's nothing in the API for that. I'm not familiar with SMF as I've always been a phpBB user up to now (shame on me!), so I was wondering if there's any method to generate the activation e-mail from the forum's settings (i.e. use the default)?

Here is my *working* test implementation:

Code: [Select]
public function run() {
include "libs/nucaptcha/leapmarketingclient.php";
include "config/settings.php";
include "smf_2_api.php";

// First, check to see if all of our VALID arguments are there (NOTE that $_POST is passed first, which invalidates the need for checkPostVar).
if(!Common::checkPost() || !Common::areAllArgumentsSet($_POST, $_POST['username'], $_POST['password'], $_POST['verifypassword'], $_POST['email'], $_POST['country'])) {
Common::error("You have not completely filled out the form.");
return;
}

Common::makePostSafe($_POST);

// Next, see if our NuCaptcha data matches.
if($regUsingLeap && array_key_exists('leap', $_SESSION) && Leap::WasSubmitted()) {
Leap::SetClientKey($regLeapClientKey);
$lastTransaction = Leap::ValidateTransaction($_SESSION['leap']);
if($lastTransaction !== true) {
Common::error("You have incorrectly entered the moving red letters.");
return;
}
}

$regOptions['member_name'] = $_POST['username'];
$regOptions['password'] = $_POST['password'];
$regOptions['password_check'] = $_POST['verifypassword'];
$regOptions['email'] = $_POST['email'];
$regOptions['location'] = $_POST['country'];
$regOptions['require'] = "activation";

if (smfapi_registerMember($regOptions) !== false) echo "Success";
else echo "Fail";
}

I know it's just a matter of getting the verification_code from the database, which seems to be generated and then inserted to the database just fine in the smfapi_registerMember() function. I just need to know how to generate the activation e-mail body, where this is stored in SMF:

Quote from: SMF Activation E-mail
Thank you for registering at R N' D Studios - Forum. Your username is DECEiFER. If you forget your password, you can reset it by visiting forum.com/index.php?action=reminder.

Before you can login, you first need to activate your account. To do so, please follow this link:

forum.com/index.php?action=activate;u=1;code=xxxxxxxxxx

Should you have any problems with activation, please visit forum.com/index.php?action=activate;u=1 use the code "xxxxxxxxxx".

Regards,
Forum Team.

Once I have that, I can simply work the rest out. :)


Thanks in advance for any assistance.
@DECEiFER check out the way SMF does this in /Sources/Register.php ~line 600

It might be easier to just do this in the API by modifying the API after the registration is successful. The variable with the activation code is '$validation_code'. You can copy the SMF template and replace the variables with the ones used for registration.

Another possibilty would be to try cURL'ing the url from the API right after registration.
Build the url like this with the variables and you should be able to cUrl to it which will send the email to the member silently. Do it just after the member ID is returned
Code: [Select]
$url = $_SERVER['HTTP_HOST'] . '/forum.com/index.php?action=activate;u=' . $memberID . ';code=' .$validation_code;
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline frytec

  • Jr. Member
  • **
  • Posts: 134
  • Admin Aika Fórum
    • CataLink.com.br
Re: New tools to help integrating SMF with something else
« Reply #42 on: February 24, 2012, 11:57:36 AM »
i figured out how to make the login synch work, but couldnt figure out how to make the logout neither the registration.

can you help me?

here is my function:

Code: [Select]
    public function theme_index_top($h)
    {
       $username = $h->cage->post->testUsername('username');
       $password = $h->cage->post->testPassword('password');
       $email = $h->cage->post->testEmail('email'); 
       require_once ('./forum/smf_2_api.php');

        switch ($h->pageName)
        {
            case 'logout':
                smfapi_logout($username);
                $h->currentUser->destroyCookieAndSession();
                header("Location: " . BASEURL);
                exit;
                break;
            case 'login':
                $h->pageTitle = $h->lang["user_signin_login"];
                $h->pageType = 'login';
                if ($this->login($h)) {
                    // success, return to front page, logged IN.
                    $return = str_replace('&', '&', $h->cage->post->getHtmLawed('return'));
                    if ($return) {
                        header("Location: " . $return);

                    } else {
                        header("Location: " . BASEURL);
                    }
                    smfapi_login($username);
                    die(); exit;
                }
                break;
            case 'register':
                $h->pageTitle = $h->lang["user_signin_register"];
                $h->pageType = 'register';
                $user_signin_settings = $h->getSerializedSettings('user_signin');
                $h->vars['useRecaptcha'] = $user_signin_settings['recaptcha_enabled'];
                $h->vars['useEmailConf'] = $user_signin_settings['emailconf_enabled'];
                $h->vars['regStatus'] = $user_signin_settings['registration_status'];
                $h->vars['useEmailNotify'] = $user_signin_settings['email_notify'];

                $userid = $this->register($h);
                if ($userid) {
                    // success!
                    if ($h->vars['useEmailConf']) {
                        $h->vars['send_email_confirmation'] = true;
                        $this->sendConfirmationEmail($h, $userid);
                        // fall through and display "email sent" message
                    } else {
                        // redirect to login page
                        header("Location: " . BASEURL . "index.php?page=login");
                        die(); exit;
                    }
                }
                break;
            case 'emailconf':
                $h->pageTitle = $h->lang['user_signin_register_emailconf'];
                $h->pageType = 'register';
                break;
        }
    }
Comunidade Aika Forum > http://www.aikaforum.com.br
Portal DetetiveWEB > http://www.detetiveweb.com.br
CataLink.com.br > http://www.catalink.com.br

Offline DECEiFER

  • Newbie
  • *
  • Posts: 2
Re: New tools to help integrating SMF with something else
« Reply #43 on: February 24, 2012, 12:09:25 PM »
i figured out how to make the login synch work, but couldnt figure out how to make the logout neither the registration.

can you help me?

here is my function:

Code: [Select]
    public function theme_index_top($h)
    {
       $username = $h->cage->post->testUsername('username');
       $password = $h->cage->post->testPassword('password');
       $email = $h->cage->post->testEmail('email'); 
       require_once ('./forum/smf_2_api.php');

        switch ($h->pageName)
        {
            case 'logout':
                smfapi_logout($username);
                $h->currentUser->destroyCookieAndSession();
                header("Location: " . BASEURL);
                exit;
                break;
            case 'login':
                $h->pageTitle = $h->lang["user_signin_login"];
                $h->pageType = 'login';
                if ($this->login($h)) {
                    // success, return to front page, logged IN.
                    $return = str_replace('&', '&', $h->cage->post->getHtmLawed('return'));
                    if ($return) {
                        header("Location: " . $return);

                    } else {
                        header("Location: " . BASEURL);
                    }
                    smfapi_login($username);
                    die(); exit;
                }
                break;
            case 'register':
                $h->pageTitle = $h->lang["user_signin_register"];
                $h->pageType = 'register';
                $user_signin_settings = $h->getSerializedSettings('user_signin');
                $h->vars['useRecaptcha'] = $user_signin_settings['recaptcha_enabled'];
                $h->vars['useEmailConf'] = $user_signin_settings['emailconf_enabled'];
                $h->vars['regStatus'] = $user_signin_settings['registration_status'];
                $h->vars['useEmailNotify'] = $user_signin_settings['email_notify'];

                $userid = $this->register($h);
                if ($userid) {
                    // success!
                    if ($h->vars['useEmailConf']) {
                        $h->vars['send_email_confirmation'] = true;
                        $this->sendConfirmationEmail($h, $userid);
                        // fall through and display "email sent" message
                    } else {
                        // redirect to login page
                        header("Location: " . BASEURL . "index.php?page=login");
                        die(); exit;
                    }
                }
                break;
            case 'emailconf':
                $h->pageTitle = $h->lang['user_signin_register_emailconf'];
                $h->pageType = 'register';
                break;
        }
    }

This is what I've been doing. It's basic, for now, but it does register the user correctly into the SMF database.

Code: [Select]
public function run() {
include "libs/nucaptcha/leapmarketingclient.php";
include "config/settings.php";
include "smf_2_api.php";

Common::logHTTPData();

// Validiate the HTTP Referer (sic) to ensure that the POST came from this domain
if (!Common::validateReferer()){
Common::logBadReferer();
// Let's not be too specific about what this error returns to the user
Common::error("Invalid request.");
}

// First, check to see if all of our VALID arguments are there (NOTE that $_POST is passed first, which invalidates the need for checkPostVar).
if(!Common::checkPost() || !Common::areAllArgumentsSet($_POST, $_POST['username'], $_POST['password'], $_POST['verifypassword'], $_POST['email'], $_POST['country'])) {
Common::error("You have not completely filled out the form.");
return;
}

Common::makePostSafe($_POST);

// Next, see if our NuCaptcha data matches.
if($regUsingLeap && array_key_exists('leap', $_SESSION) && Leap::WasSubmitted()) {
Leap::SetClientKey($regLeapClientKey);
$lastTransaction = Leap::ValidateTransaction($_SESSION['leap']);
if($lastTransaction !== true) {
Common::error("You have incorrectly entered the moving red letters.");
return;
}
}

$regOptions['member_name'] = $_POST['username'];
$regOptions['password'] = $_POST['password'];
$regOptions['password_check'] = $_POST['verifypassword'];
$regOptions['email'] = $_POST['email'];
$regOptions['location'] = $_POST['country'];
$regOptions['require'] = "activation";

if (smfapi_registerMember($regOptions) === false) return false;

$_SESSION['success'] = true;
$_SESSION['email'] = $_POST['email'];
header("location: /register");
die;
}


To logout, it's as simple as this:

Code: [Select]
public function logout(){
global $user_info;
if(isset($user_info) && $user_info['is_guest'] == 0) {
smfapi_logout($user_info['username']);
}
header('location: /login');
die;
}
« Last Edit: February 24, 2012, 12:18:07 PM by DECEiFER »

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #44 on: February 24, 2012, 01:20:12 PM »
The logout function is very simple. All you need to do to effectively log them out of SMF is destroy the cookie. If the logout function isn't working, first check to make sure your script can see the SMF cookie. It must be set on path '/'.
Also make sure the cookie data has no slashes in it. If it does turn off magic quotes on your server in the php ini. When this is the case, the logout function scans the cookie to see if anyone is logged in, and if there are slashes it won't unserialize the data, so unserialize will fail and the logout script will assume nobody is logged in and exit. Try using this instead of smfapi_logout()
Code: [Select]
smfapi_setLoginCookie(-3600, 0);
If that does the job, your cookie data probably has slashes in it.

For the Register issue you're having, it doesn't look like you are calling smfapi_register() at all.
Inside your switch statement under 'register' is where I'm guessing it should be...
For the registration function, you need to set up the array correctly, making sure the array keys have the correct names. You need at minimum a username, password and email. The API will return false if the username or email is already taken. Check your values carefully to make sure they are all set and be extra precise and this function will work
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline frytec

  • Jr. Member
  • **
  • Posts: 134
  • Admin Aika Fórum
    • CataLink.com.br
Re: New tools to help integrating SMF with something else
« Reply #45 on: February 24, 2012, 01:53:36 PM »
Thanks for your answers guys.
I going one step at a time, so i first trying to logout, before trying to register.

@andre nickatina, using smfapi_setLoginCookie(-3600, 0); it works, i am being succefully logged out of smf when i log out my site.

can i use it that way? Or is it just a "test"?

magic quotes are off according to phpinfo.
magic_quotes_gpc      Off   Off
magic_quotes_runtime   Off   Off
magic_quotes_sybase   Off   Off

Comunidade Aika Forum > http://www.aikaforum.com.br
Portal DetetiveWEB > http://www.detetiveweb.com.br
CataLink.com.br > http://www.catalink.com.br

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #46 on: February 24, 2012, 02:05:23 PM »
Thanks for your answers guys.
I going one step at a time, so i first trying to logout, before trying to register.

@andre nickatina, using smfapi_setLoginCookie(-3600, 0); it works, i am being succefully logged out of smf when i log out my site.

can i use it that way? Or is it just a "test"?

magic quotes are off according to phpinfo.
magic_quotes_gpc      Off   Off
magic_quotes_runtime   Off   Off
magic_quotes_sybase   Off   Off



Your other script might be turning them on. Using it like that will work, but it's not the best solution as the user will still show in the who's online list and appear to be online even though they're not. The function also unsets a few session variables that need to be destroyed.
Can you look at the cookie data in firebug or something to verify there are slashes in the data? If so, you can add the stripslashes() php function to the API by replacing $_COOKIE[$cookiename] with stripslashes($_COOKIE[$cookiename]) in the 3 places where the cookie data gets checked and unserialized. You can use find/replace for that :) They should be in the function smfapi_loadUserSettings
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline frytec

  • Jr. Member
  • **
  • Posts: 134
  • Admin Aika Fórum
    • CataLink.com.br
Re: New tools to help integrating SMF with something else
« Reply #47 on: February 24, 2012, 02:14:21 PM »
@andre, thats all info on smfcookie via firecookies

SMFCookie520
   
Value: a:4:{i:0;s:1:"1";i:1;s:40:"c3ea46ccb2e2d848578f51dd6196044c1159f221";i:2;i:1519328009;i:3;i:2;}

Domain:    .catalink.com.br   

Size: 107 B
   
Path: /

Raw: a%3A4%3A%7Bi%3A0%3Bs%3A1%3A%221%22%3Bi%3A1%3Bs%3A40%3A%22c3ea46ccb2e2d848578f51dd6196044c1159f221%22%3Bi%3A2%3Bi%3A1519328009%3Bi%3A3%3Bi%3A2%3B%7D
« Last Edit: February 24, 2012, 02:37:33 PM by frytec »
Comunidade Aika Forum > http://www.aikaforum.com.br
Portal DetetiveWEB > http://www.detetiveweb.com.br
CataLink.com.br > http://www.catalink.com.br

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #48 on: February 24, 2012, 05:03:45 PM »
Create a test page with this code:
Code: [Select]
<?php
require_once ('./forum/smf_2_api.php');
global 
$cookiename;
$data $_COOKIE[$cookiename];
echo 
$data '<br />';
echo 
'Without stripslashes:<br /><pre>';
print_r(unserialize($data));
echo 
'</pre>';
echo 
'With stripslashes:<br /><pre>';
print_r(unserialize(stripslashes($data)));
echo 
'</pre>';
name it test.php or something, upload it, navigate to it and see what the output is and post what you get
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline lilsammy1989

  • Newbie
  • *
  • Posts: 7
Re: New tools to help integrating SMF with something else
« Reply #49 on: February 25, 2012, 01:32:15 PM »
Hi I tried to make a simple ajax login from my main website like so:
Code: [Select]
<?php 
$is_ajax 
$_REQUEST['is_ajax'];

if(isset(
$is_ajax) && $is_ajax){
$user $_REQUEST['username'];
$pass $_REQUEST['password'];


require_once ('./smf_2_api.php');


$login smfapi_authenticate($username=$user$password=$pass);

    if (!
$login) {
        echo 
"wrong";
    } else {
$cookie smfapi_login($username=$user$cookieLength=525600);
if (!$login) {
        
echo "wrong";
}else{
echo "success";
};
};
};
?>


It threw some errors and then I thought maybe I will try your test script and it did the same :/


Anyway I tried your test script and it throws the same errors.

Code: [Select]
Warning: opendir(/home/sam/public_html/pug4u.com./forums/Settings.php) [function.opendir]: failed to open dir: No such file or directory in /home/sam/public_html/pug4u.com/static/classes/smf_2_api.php on line 3231

Warning: readdir(): supplied argument is not a valid Directory resource in /home/sam/public_html/pug4u.com/static/classes/smf_2_api.php on line 3232

Warning: closedir(): supplied argument is not a valid Directory resource in /home/sam/public_html/pug4u.com/static/classes/smf_2_api.php on line 3243

Without stripslashes:

With stripslashes:

Was hoping you could shed some light on my problem I would be so greatful.

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #50 on: February 25, 2012, 01:36:26 PM »
@lilsamm71989
Try putting the full path to the API in the require_once function
Also, try putting the API script in your forum directory to see if that helps
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline lilsammy1989

  • Newbie
  • *
  • Posts: 7
Re: New tools to help integrating SMF with something else
« Reply #51 on: February 25, 2012, 01:59:36 PM »
@andre nickatina

I think I am including it correctly because if I set the path wrong I get an error about not finding it but when I set it correctly it outputs:

Code: [Select]
<br />
<b>Warning</b>:  opendir(/home/sam/public_html/pug4u.com./forums/Settings.php) [<a href='function.opendir'>function.opendir</a>]: failed to open dir: No such file or directory in <b>/home/sam/public_html/pug4u.com/static/classes/smf_2_api.php</b> on line <b>3231</b><br />
<br />
<b>Warning</b>:  readdir(): supplied argument is not a valid Directory resource in <b>/home/sam/public_html/pug4u.com/static/classes/smf_2_api.php</b> on line <b>3232</b><br />
<br />
<b>Warning</b>:  closedir(): supplied argument is not a valid Directory resource in <b>/home/sam/public_html/pug4u.com/static/classes/smf_2_api.php</b> on line <b>3243</b><br />
<br />
<b>Fatal error</b>:  Function name must be a string in <b>/home/sam/public_html/pug4u.com/static/classes/smf_2_api.php</b> on line <b>755</b><br />

Also I tried it on the forum it gives the same error. Any other Ideas?

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #52 on: February 25, 2012, 02:04:10 PM »
Did you try moving the API script to your SMF directory? Cause these are the errors it will throw if it can't find your settings php file. Or you could edit line ~574 to give the script your path to settings php
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline frytec

  • Jr. Member
  • **
  • Posts: 134
  • Admin Aika Fórum
    • CataLink.com.br
Re: New tools to help integrating SMF with something else
« Reply #53 on: February 25, 2012, 02:17:11 PM »
Create a test page with this code:
....
name it test.php or something, upload it, navigate to it and see what the output is and post what you get


Code: [Select]
a:4:{i:0;s:1:"1";i:1;s:40:"c3ea46ccb2e2d848578f51dd6196044c1159f221";i:2;i:1361733187;i:3;i:2;}
Without stripslashes:

Array
(
    [0] => 1
    [1] => c3ea46ccb2e2d848578f51dd6196044c1159f221
    [2] => 1361733187
    [3] => 2
)

With stripslashes:

Array
(
    [0] => 1
    [1] => c3ea46ccb2e2d848578f51dd6196044c1159f221
    [2] => 1361733187
    [3] => 2
)
Comunidade Aika Forum > http://www.aikaforum.com.br
Portal DetetiveWEB > http://www.detetiveweb.com.br
CataLink.com.br > http://www.catalink.com.br

Offline lilsammy1989

  • Newbie
  • *
  • Posts: 7
Re: New tools to help integrating SMF with something else
« Reply #54 on: February 25, 2012, 02:22:45 PM »
Yeah I tried it in the forum directory same thing. Could you tell me if I have done these settings right?

My file structure looks like this:


Code: [Select]

// get the forum's settings for database and file paths
if (file_exists(dirname(__FILE__) . '../../forums/Settings.php')) {
    require_once(dirname(__FILE__) . '../../forums/Settings.php');
} elseif (isset($settings_path)) {
    require_once($settings_path);
} else {
    $directory = $_SERVER['DOCUMENT_ROOT'] . './forums/Settings.php';
    $exempt = array('.', '..');
    $files = smfapi_getDirectoryContents($directory, $exempt);
    $matches = smfapi_getMatchingFile($files, '../../forums/Settings.php');

    // we're going to search for it...
@set_time_limit(600);
// try to get some more memory
if (@ini_get('memory_limit') < 128) {
@ini_set('memory_limit', '128M');
    }

    if (1 == count($matches)) {
        require_once($matches[0]);
        $settings_path = $matches[0];
        file_put_contents($saveFile, base64_encode($settings_path));
    } elseif (1 < count($matches)) {
        $matches = smfapi_getMatchingFile($files, 'Settings_bak.php');
        $matches[0] = str_replace('_bak.php', '.php', $matches[0]);
        require_once($matches[0]);
        $settings_path = $matches[0];
        file_put_contents($saveFile, base64_encode($settings_path));
    } else {
        return false;
    }
}

$scripturl = $boardurl . '../../index.php';

// make absolutely sure the cache directory is defined
if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '../../forums/cache')) {
$cachedir = $boarddir . '../../forums/cache';
}

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #55 on: February 25, 2012, 02:35:28 PM »
@lilsammy1989 You don't appear to have a Settings.php file in your forum root directory... The API needs that location of the Settings.php file so it can make the db connections and get the cookiename to read the cookie... How does your forum work without it?

@frytec That's very weird. Your cookie is being read correctly but the logout is still failing for you. Try calling smfapi_loadUserSettings() before logout, and also, don't pass any variable to the logout function:
Code: [Select]
smfapi_loadUserSettings();
smfapi_logout();
If that doesn't work, try modifying it like so:
Code: [Select]
smfapi_loadUserSettings();
global $user_info;
echo '<pre>';
print_r($user_info);
echo '</pre>';
exit('The user info should be above in an array');
smfapi_logout();
and see if the API is getting the current user from the cookie.
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline lilsammy1989

  • Newbie
  • *
  • Posts: 7
Re: New tools to help integrating SMF with something else
« Reply #56 on: February 25, 2012, 02:48:08 PM »
Its there sorry I knew that I should of mentioned I did not download my entire forum as installed it from another location and did not need the files on this PC so didn't bother downloading the entire remote forums folder but its there on the actual server thats my local view.

Sorry for the confusion.

Offline frytec

  • Jr. Member
  • **
  • Posts: 134
  • Admin Aika Fórum
    • CataLink.com.br
Re: New tools to help integrating SMF with something else
« Reply #57 on: February 25, 2012, 02:50:41 PM »
Quote from: andre nickatina
@frytec That's very weird. Your cookie is being read correctly but the logout is still failing for you. Try calling smfapi_loadUserSettings() before logout, and also, don't pass any variable to the logout function:
Code: [Select]
smfapi_loadUserSettings();
smfapi_logout();

that does not work.

Quote from: andre nickatina
If that doesn't work, try modifying it like so:
Code: [Select]
smfapi_loadUserSettings();
global $user_info;
echo '<pre>';
print_r($user_info);
echo '</pre>';
exit('The user info should be above in an array');
smfapi_logout();
and see if the API is getting the current user from the cookie.

this give me a page with above results, but still dont logout from smf.

Code: [Select]
Array
(
    [groups] => Array
        (
            [0] => 1
            [1] => 0
        )

    [possibly_robot] =>
    [id] => 1
    [username] => catalink
    [name] => catalink
    [email] => suporte@catalink.com.br
    [passwd] => 8769590b35433ffbfc768e09af9efda6fc8bfb4a
    [language] => portuguese_brazilian-utf8
    [is_guest] =>
    [is_admin] => 1
    [theme] => 0
    [last_login] => 1330199182
    [ip] =>
    [ip2] =>
    [posts] => 0
    [time_format] => %B %d, %Y, %I:%M:%S %p
    [time_offset] => 0
    [avatar] => Array
        (
            [url] =>
            [filename] =>
            [custom_dir] =>
            [id_attach] => 0
        )

    [smiley_set] =>
    [messages] => 0
    [unread_messages] => 0
    [total_time_logged_in] => 8878
    [buddies] => Array
        (
        )

    [ignoreboards] => Array
        (
        )

    [ignoreusers] => Array
        (
        )

    [warning] => 0
    [permissions] => Array
        (
        )

)

The user info should be above in an array
Comunidade Aika Forum > http://www.aikaforum.com.br
Portal DetetiveWEB > http://www.detetiveweb.com.br
CataLink.com.br > http://www.catalink.com.br

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #58 on: February 25, 2012, 03:42:01 PM »
@frytec I think I see your problem. There is a bug in the logout function. Go to ~line 1047 of the API to where the code says:
Code: [Select]
    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;
        }
    }
and change it to
Code: [Select]
    if (!$user_data) {
        if (isset($user_info['id']) && false !== smfapi_getUserById($user_info['id'])) {
            $user_data['id_member'] = $user_info['id'];
        } else {
            return false;
        }
    }
It looks like I had been using the wrong variable name for the member ID  :-[

@lilsammy1989 Please confirm you have the API script in the same directory as the Settings.php file. Also, look for a file named smfapi_settings.txt and delete it so the API can generate a new one with the correct path. If you want to specify the path in the, do it like this:
Code: [Select]
$_SERVER['DOCUMENT_ROOT'] . '/forums/Settings.php';
That looks like it is the path you should use. That won't be necessary if you have the API in the same directory as the settings file though... either way, try it and let me know :)
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline lilsammy1989

  • Newbie
  • *
  • Posts: 7
Re: New tools to help integrating SMF with something else
« Reply #59 on: February 25, 2012, 05:12:01 PM »
@andre nickatina

Thanks it worked when I used it from the forum and set the directory to settings. Can I ask tho why when I made my registration function quoted below it worked fine and its located outside of the forum directory?

Code: [Select]
<?php
if (!isset($_POST['name']) && !isset($_POST['steam']) && !isset($_POST['email']) && !isset($_POST['email2']) && !isset($_POST['password']) && !isset($_POST['password2']) && !isset($_POST['acceptTerms'])) {
echo "";
}else{
include './static/classes/validation.php';

$name $_POST['name'];
$steam $_POST['steam'];
$email $_POST['email'];
$email2 $_POST['email2'];
$pass $_POST['password'];
$pass2 $_POST['password2'];
$userIP getenv('REMOTE_ADDR');
require_once ('./static/classes/smf_2_api.php');

$sha_passwd sha1(strtolower($name).smfapi_unHtmlspecialchars($pass));
  
if((validate_username($name) == true) && ($email == $email2) && (check_email_address($email) == true) && ($pass == $pass2)){
include './static/classes/config.php';

$conn mysql_connect($host,$user,$pass);
if (!$conn) {
die('Could not connect: ' mysql_error());
}

mysql_select_db($db$conn);
mysql_set_charset('utf8',$conn);

$sql_username="SELECT * FROM User WHERE User_Name = '$name'";
$sql_email="SELECT * FROM User WHERE User_Email = '$email'";

$user_check=mysql_query($sql_username);
$email_check=mysql_query($sql_email);

if (mysql_num_rows($user_check) > 0){
echo "Error - 02"// Username in Use.
}else{
if (mysql_num_rows($email_check) > 0){
echo "Error - 03"// Email in Use.
}else{

$reg= array(
'member_name' => $name,
'email' => $email,
'require' => 'nothing',
'password' => $pass,
'password_check' => $pass2,
);
smfapi_registerMember($reg);

$new_user=mysql_query("INSERT INTO User (User_Name, User_Pass, User_IP, User_Admin, User_Beta, User_SteamID, User_Registered, User_Email) VALUES ('$name', '$sha_passwd', '$userIP', '0', '1', '$steam', 'NOW()', '$email')");
if (!$new_user) {
$message  'Invalid query: ' mysql_error() . "\n";
$message .= 'Whole query: ' $query;
die($message);
};

echo "<script language='javascript'>window.location.href='http://mysite.com/welcome.php?name=".$name."';</script>";
};
};
};
};
?>