(2012-07-26, 09:45 PM)mobert Wrote: Is there any way to have
1. a user who logs into forum1 automatically logged into forum2? (and vice versa)
2. if they register for forum1 they are registered with forum2? (and vice versa)
3. If they update the password/email , it updates on both
Hi mobert,
Download the MyBBIntegrator constructor here:
http://phpdave.com/MyBBIntegrator/, this is a great script because it has basically everything you'd need to integrate your mybb with your front site ready and done.
So, I'm generous today, and I'll share my codes that I've spent time building, so I hope you'll be glad for it.
Login:
<?php
define('IN_MYBB', NULL);
global $mybb, $lang, $query, $db, $cache, $plugins, $displaygroupfields;
require_once '/path/to/mybb_forum/global.php';
require_once '/path/to/MyBBIntegrator.php';
$MyBBI = new MyBBIntegrator($mybb, $db, $cache, $plugins, $lang, $config);
$login_status = $MyBBI->login($_POST['username'], $_POST['password']);
if ($login_status == true) echo 'Logged in successfully';
else echo 'The login routine failed';
?>
Registration:
<?php
define('IN_MYBB', NULL);
global $mybb, $lang, $query, $db, $cache, $plugins, $displaygroupfields;
require_once '/path/to/mybb_forum/global.php';
require_once '/path/to/MyBBIntegrator.php';
$MyBBI = new MyBBIntegrator($mybb, $db, $cache, $plugins, $lang, $config);
$info = array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'password2' => $_POST['password_confirm'],
'email' => $_POST['email'],
'email2' => $_POST['email'],
'hideemail' => 1,
'allownotices' => 1,
'emailpmnotify' => 1,
'invisible' => 0,
'receivepms' => 1
);
$register_status = $MyBBI->register($info);
// Array means: registering failed
if (is_array($register_status))
{
echo implode('<br />', $register_status);
}
else
{
echo $register_status;
}
?>
Update password: (You must adjust the $_POST['newpassword'] after your html form input, you should use the same field name "<input name=" FIELD NAME " />" as you do in your POST variable.
<?php
define('IN_MYBB', NULL);
global $mybb, $lang, $query, $db, $cache, $plugins, $displaygroupfields;
require_once '/path/to/mybb_forum/global.php';
require_once '/path/to/MyBBIntegrator.php';
$MyBBI = new MyBBIntegrator($mybb, $db, $cache, $plugins, $lang, $config);
$myupdatepass = $MyBBI->updatePasswordOfUser($MyBBI->mybb->user['uid'], $_POST['newpassword']);
if ($myupdatepass === true)
{
echo 'Password updated';
}
else
{
echo $myupdatepass;
}
?>
Update email:
<?php
define('IN_MYBB', NULL);
global $mybb, $lang, $query, $db, $cache, $plugins, $displaygroupfields;
require_once '/path/to/mybb_forum/global.php';
require_once '/path/to/MyBBIntegrator.php';
$MyBBI = new MyBBIntegrator($mybb, $db, $cache, $plugins, $lang, $config);
/* You must change the $yourusernamevariable to whatever your system uses, most common are $user, $username or $uname. */
$username = $yourusernamevariable;
$email = $_POST['email'];
$db->update_query("users", $email, "uid='".$yourusername."'", 1);
$plugins->run_hooks('password_changed');
?>
If you find them helpful, please give me reputation for it, I'd be more than happy