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)?

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".

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)?

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

"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?"

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()

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

Logged

"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?"

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 Offmagic_quotes_runtime Off Offmagic_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

Logged

"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?"

<?phprequire_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

Logged

"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?"

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.

@lilsamm71989Try putting the full path to the API in the require_once functionAlso, try putting the API script in your forum directory to see if that helps

Logged

"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?"

<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?

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

Logged

"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?"

@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:

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.

Logged

"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?"

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.

@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:

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.

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:

$_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

Logged

"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?"

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?