New tools to help integrating SMF with something else

Started by Andre N, September 19, 2011, 01:35:36 PM

Previous topic - Next topic

kristen_tg

#80
Thank you for the quick reply, Andre. I haven't had a chance to look at $cookiename yet (been squeezing the forum into my existing template)

I do have another question though  ::)

SMF and my app are nicely sharing the same session. However, when I go to the forum itself, the session data my application requires disappears from the session. Backing out of the forums restores the 2 bits of data. Any ideas on what method or function is causing those two bits of data to be unset? There's a whole host of data I need to grab from my application to properly populate the template. The board is in fact loading the proper include file that handles this, but for some reason just those 2 pieces of information are getting dumped out of the session.

Nevermind. Got it all working beautifully. Thank you so much for the API.

stefann

Thanks for the API Andre, it's made my integration a whole lot less painful than expected!


However, as I am using SMF as only part of a two tier authentication system, I would like to be able to have my external integration call SMF's password reset functionality directly -- what's the best way to achieve this?


Thanks
full time lurker on freenode #smf

Andre N

Hi,
You can see how SMF is doing it in Sources/Reminder.php around line 245 (assuming 2.0)

// Randomly generate a new password, with only alpha numeric characters that is a max length of 10 chars.
require_once($sourcedir . '/Subs-Members.php');
$password = generateValidationCode();

require_once($sourcedir . '/Subs-Post.php');
$replacements = array(
'REALNAME' => $row['real_name'],
'REMINDLINK' => $scripturl . '?action=reminder;sa=setpassword;u=' . $row['id_member'] . ';code=' . $password,
'IP' => $user_info['ip'],
'MEMBERNAME' => $row['member_name'],
'OPENID' => $row['openid_uri'],
);

$emaildata = loadEmailTemplate('forgot_' . $context['account_type'], $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
$context['description'] = $txt['reminder_' . (!empty($row['openid_uri']) ? 'openid_' : '') . 'sent'];

// If they were using OpenID simply email them their OpenID identity.
sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
if (empty($row['openid_uri']))
// Set the password in the database.
updateMemberData($row['id_member'], array('validation_code' => substr(md5($password), 0, 10)));


I'd try it like that, setting all the variables first
"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?"

Ardenstone

Thanks for posting this!  I'm new to SMF and so been giving smf_2_integration_hooks.php a shot; seems like it will save a lot of steps.

What I'd like to do is that, when a user first signs up for the forum, write their username to a custom table in the same database.  The following code works fine (it writes the username to the database or throws the error if the username already exists) except that on a successful write to my table, the user just gets a blank screen and is sitting at index.php?action=register2.  Do I need to return a specific value out of this function or something?  Since it stops at this step the user obviously never gets entered into SMF itself which is doubly problematic. :)

Also: has the username been cleansed at this point or is it still the raw username that the user set?  I'm hoping SMF has already taken care of the security aspects, but if not I need to add that here, too.


function smf_register_function($regOptions, $theme_vars)
{
global $smcFunc;
$dc = 'tnt_';
$query = "SELECT userID from $dc" . "USERS WHERE UPPER(userName) = UPPER('" . $regOptions['username'] . "')";
$result = $smcFunc['db_query']('',"$query");
$row = $smcFunc['db_fetch_assoc']($result);
if (isset($row['userID'])) {
exit("Username is already taken.");
}
$query = "INSERT INTO $dc" . "USERS (userID, userName) SELECT MAX(userID) + 1, '" . $regOptions['username'] . "' FROM $dc" . "USERS";
$result = $smcFunc['db_query']('',"$query");
$smcFunc['db_free_result']($result);

exit();
}


Thank you,
   Chris

Andre N

Hi Chris,

It looks like you get a blank screen because of the exit() function. Try removing the second one.
The script will be called just before the data is inserted into the database so it should be cleaned up. You can check this in /Sources/Register.php  in the Register2() function around line 511, which is the point the integration hook is called
"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?"

Ardenstone

Thanks, Andre!  That worked like a charm.  I added that exit() earlier while trying to fix some other bug and never thought to take it out again.  Silliness on my part, and a quick and excellent response on yours.

All the best,
   Chris

souf0

Hi,
I'm searching for a api function for ban a user, but there aren't in this api file.
I think it's easy to make a function to ban some user using this api, there aren't no problem, no? Using $smcFunc['db_query'] and the query for to ban someone...
Thanks

Andre N

Hi :)
If you take a look at how SMF does it in Sources/ManageBans.php in the function BanEdit() you should be able to figure out the queries you'll need to create a new ban.
Alternatively, it looks like you can set the user value is_activated to be > 10 and the user will be banned... That's how it looks to me anyways from looking at the code. You'd do that like like this:

smfapi_updateMemberData($user, array('is_activated' => 11));

Where $user is the email address, member id or username of the person that will be banned
Try it out and let us know if you can
"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?"

stefann

Just a tip for anyone else using different database users for the bridge & forum, if you do not provide write access to the SMF settings table, you may experience random & intermittent fatal errors when including this or any other SSI script eg INSERT,DELETE command denied to user 'bridge_smf'@'localhost' for table 'smf_settings' so you probably want to look at the seed generation around line 645, or even comment it out if you know you can trust the forum for entropy
full time lurker on freenode #smf

EpicorUsersGroup

Thanks for the API it is working well for my application.  How would I go about creating new boards within my forum from my application?

Kindred

Why don't you just use SMF for that?

There are certain things which can/should be externally done, and others which really should be done, properly form inside the forum portion. Why would you need to create boards from an external source?
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

EpicorUsersGroup

I already have a website with supports sub-groups within our user community, I would like to be able to create and connect those sub-groups with their own discussion group within a specific category in the forum.  We are new to smf and I am trying to integrate the forum into our existing functionality as smoothly as possible with as little administrative effort as possible.

Kindred

I think that you may be using cross-purpose terms.

to SMF, a GROUP is a way of organizing users for security, permissions, access or visual organization.

If this is how you are using the term, the what you should do is - use the API to associate your group structure to a similar group structure in SMF and then use SMF's permissions to grant (or deny) access to boards in SMF.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

EpicorUsersGroup

That is not my point at all.  Please excuse the reference to "groups" this has nothing do with SMF member groups.  I understand how to use the API for that.  We are a software user group with an existing website, I am adding and integrating SMF into our existing website.  I am just trying to figure out if it is possible to create a new SMF board automatically when we activate a new "sub-group" within our membership.

Kindred

well, since creating a board is just a php routine, yes.... it is. Although setting the permissions might be a little tricky.

remember, once you load SSI or the API, you can often use internal SMF functions.

although I am uncertain which file the create_board routine is in...   you can check the WIKI and the function database...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

EpicorUsersGroup

I have been poking around in the source code.  yes it looks like createboard is the correct routine.  I just have to figure out all the parameters.

Thanks for your help.


trushkevich

Thank you Andre for the API! Man you saved several days of my life!

nathanmc

Hi there,

I've newly installed SMF and generally found it far easier than others (such as phpBB) to integrate my website and it's functionality.

I'm trying to install and setup the API to automate logging in, logging out and member info edits. I've created my own system, so I'm trying to use the API to do the same functions behind the scenes with SMF.

I cannot seem to find any documentation for the API. Where can I find an explanatory document and any "how to's" for the functions I want to set up? Would seem fairly run of the mill functionality for the API and would therefore have at least a basic document.

Can someone please help me with this.

Thanks very much.
Yours Sincerely,

Nathan McNamara
Inventerest
www.inventerest.com

Andre N

Hi :)

There is a lot of documentation inside the API file itself at the top that will explain how to use the functions. They are pretty easy to use.

1. include the API in your file
2. call the function(s)
smfapi_login($username);
now they are logged in

If you get stuck just reply with your problem and I'll help you :)
"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?"

nathanmc

Hi Andre,

Thanks for replying so quickly.

I'm attempting to add in a new registration and it doesn't want to work. Can you point out any error I have in my code.

require_once("forum/smf_2_api.php");
$regOptions = array('member_name' => $_POST['reguser'], 'email' => $_POST['email'], 'password' => $_POST['regpass'], 'memberGroup' => 4);
smfapi_registerMember($regOptions);

Thank you.
Yours Sincerely,

Nathan McNamara
Inventerest
www.inventerest.com

Advertisement: