Customizing SMF > SMF Coding Discussion
Custom login method
JamesWC:
I'm using SMF 2.0.2, and want to use Janrain Engage to have users log into my forum with their Facebook, Twitter, Google (etc) accounts.
Once the user has authenticated himself as the owner of a certain (eg) Facebook ID, and I've matched that against a member in the forum database, how can I then bypass SMF's usual login system to the stage where I can say "its all good, go ahead and log him in as this member"? Where is the piece of code in the SMF files that does this?
Thanks for any help. :)
Yoshi:
Hello JamesWC,
You can try to get Login.php, located in the Sources folder, to do the job for you.
JamesWC:
I don't know how I missed it, but thank you! The bits I need are indeed in LogInOut.php - fingers crossed from here on out.
Yoshi:
--- Quote from: JamesWC on August 09, 2012, 05:15:25 PM ---I don't know how I missed it, but thank you! The bits I need are indeed in LogInOut.php - fingers crossed from here on out.
--- End quote ---
Ah LogInOut.php, of course ;)
Good luck with your project :)
JamesWC:
Back again, as I'm having problems...
At the top of my non-SMF page I include two SMF files:
--- Code: ---require_once('forum/index-custom.php');
require_once('forum/Sources/LogInOut.php');
--- End code ---
index-custom.php is a modified version of SMF's root index.php, omitting sections that would cause anything to be displayed on the page:
--- Code: ---<?php
/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines http://www.simplemachines.org
* @copyright 2011 Simple Machines
* @license http://www.simplemachines.org/about/smf/license.php BSD
*
* @version 2.0.2
*/
/* This, as you have probably guessed, is the crux on which SMF functions.
Everything should start here, so all the setup and security is done
properly. The most interesting part of this file is the action array in
the smf_main() function. It is formatted as so:
'action-in-url' => array('Source-File.php', 'FunctionToCall'),
Then, you can access the FunctionToCall() function from Source-File.php
with the URL index.php?action=action-in-url. Relatively simple, no?
*/
$forum_version = 'SMF 2.0.2';
// Get everything started up...
define('SMF', 1);
if (function_exists('set_magic_quotes_runtime'))
@set_magic_quotes_runtime(0);
error_reporting(defined('E_STRICT') ? E_ALL | E_STRICT : E_ALL);
$time_start = microtime();
// This makes it so headers can be sent!
ob_start();
// Do some cleaning, just in case.
foreach (array('db_character_set', 'cachedir') as $variable)
if (isset($GLOBALS[$variable]))
unset($GLOBALS[$variable], $GLOBALS[$variable]);
// Load the settings...
require_once(dirname(__FILE__) . '/Settings.php');
// Make absolutely sure the cache directory is defined.
if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
$cachedir = $boarddir . '/cache';
// And important includes.
require_once($sourcedir . '/QueryString.php');
require_once($sourcedir . '/Subs.php');
require_once($sourcedir . '/Errors.php');
require_once($sourcedir . '/Load.php');
require_once($sourcedir . '/Security.php');
// Using an pre-PHP 5.1 version?
if (@version_compare(PHP_VERSION, '5.1') == -1)
require_once($sourcedir . '/Subs-Compat.php');
// If $maintenance is set specifically to 2, then we're upgrading or something.
if (!empty($maintenance) && $maintenance == 2)
db_fatal_error();
// Create a variable to store some SMF specific functions in.
$smcFunc = array();
// Initate the database connection and define some database functions to use.
loadDatabase();
// Load the settings from the settings table, and perform operations like optimizing.
reloadSettings();
// Clean the request variables, add slashes, etc.
cleanRequest();
$context = array();
// Seed the random generator.
if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69)
smf_seed_generator();
// Register an error handler.
set_error_handler('error_handler');
// Start the session. (assuming it hasn't already been.)
loadSession();
?>
--- End code ---
After my non-SMF page is satisfied that the user is a specific member in the database, I run this code to try and get SMF to acknowledge them as logged in:
--- Code: --- require_once('forum/Sources/Subs-Auth.php');
$user_settings['member_name'] = $confirmed_name;
$user_settings['id_member'] = $confirmed_id;
DoLogin();
--- End code ---
This sadly results in being directed to an SMF page displaying the following:
--- Quote ---An Error Has Occurred!
You were unable to login. Please check your cookie settings.
--- End quote ---
I can log in fine the normal way, so I don't think it's an issue with any settings per se, it's clearly my amateur coding that's the problem.
So as I bang my head on the desk crying, I'd really appreciate some advice on how to make SMF just accept that the user is who my own page says they are... :(
Navigation
[0] Message Index
[#] Next page
Go to full version