Advertisement:

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

Offline kristen_tg

  • Newbie
  • *
  • Posts: 2
Re: New tools to help integrating SMF with something else
« Reply #80 on: March 30, 2012, 08:34:53 PM »
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.
« Last Edit: March 30, 2012, 10:15:54 PM by kristen_tg »

Offline stefann

  • Semi-Newbie
  • *
  • Posts: 54
  • Gender: Male
Re: New tools to help integrating SMF with something else
« Reply #81 on: April 30, 2012, 11:11:46 AM »
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

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 #82 on: May 01, 2012, 11:27:54 AM »
Hi,
You can see how SMF is doing it in Sources/Reminder.php around line 245 (assuming 2.0)
Code: [Select]
// 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?"

Offline Ardenstone

  • Newbie
  • *
  • Posts: 7
Re: New tools to help integrating SMF with something else
« Reply #83 on: May 13, 2012, 09:28:50 PM »
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.

Code: [Select]
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

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 #84 on: May 13, 2012, 09:35:53 PM »
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?"

Offline Ardenstone

  • Newbie
  • *
  • Posts: 7
Re: New tools to help integrating SMF with something else
« Reply #85 on: May 13, 2012, 09:59:22 PM »
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

Offline souf0

  • Newbie
  • *
  • Posts: 1
Re: New tools to help integrating SMF with something else
« Reply #86 on: May 22, 2012, 05:32:18 AM »
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

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 #87 on: May 24, 2012, 09:26:19 PM »
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:
Code: [Select]
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?"

Offline stefann

  • Semi-Newbie
  • *
  • Posts: 54
  • Gender: Male
Re: New tools to help integrating SMF with something else
« Reply #88 on: May 25, 2012, 02:47:50 AM »
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
Code: [Select]
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

Offline EpicorUsersGroup

  • Newbie
  • *
  • Posts: 4
Re: New tools to help integrating SMF with something else
« Reply #89 on: May 25, 2012, 10:09:48 AM »
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?

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,430
  • Gender: Male
    • Kindred-999 on GitHub
Re: New tools to help integrating SMF with something else
« Reply #90 on: May 25, 2012, 10:28:36 AM »
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?
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline EpicorUsersGroup

  • Newbie
  • *
  • Posts: 4
Re: New tools to help integrating SMF with something else
« Reply #91 on: May 25, 2012, 10:51:34 AM »
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.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,430
  • Gender: Male
    • Kindred-999 on GitHub
Re: New tools to help integrating SMF with something else
« Reply #92 on: May 25, 2012, 10:55:01 AM »
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.
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline EpicorUsersGroup

  • Newbie
  • *
  • Posts: 4
Re: New tools to help integrating SMF with something else
« Reply #93 on: May 25, 2012, 11:45:34 AM »
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.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,430
  • Gender: Male
    • Kindred-999 on GitHub
Re: New tools to help integrating SMF with something else
« Reply #94 on: May 25, 2012, 01:58:06 PM »
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...
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline EpicorUsersGroup

  • Newbie
  • *
  • Posts: 4
Re: New tools to help integrating SMF with something else
« Reply #95 on: May 25, 2012, 02:31:21 PM »
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.


Offline trushkevich

  • Newbie
  • *
  • Posts: 1
Re: New tools to help integrating SMF with something else
« Reply #96 on: June 14, 2012, 06:57:31 AM »
Thank you Andre for the API! Man you saved several days of my life!

Offline nathanmc

  • Semi-Newbie
  • *
  • Posts: 14
    • Inventerest
Re: New tools to help integrating SMF with something else
« Reply #97 on: June 24, 2012, 10:23:46 PM »
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 [nofollow]

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 #98 on: June 24, 2012, 11:07:16 PM »
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)
Code: [Select]
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?"

Offline nathanmc

  • Semi-Newbie
  • *
  • Posts: 14
    • Inventerest
Re: New tools to help integrating SMF with something else
« Reply #99 on: June 25, 2012, 05:16:32 AM »
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 [nofollow]