Re: Integrating ElkArte with existing users table? (Single-sign on)
Reply #1 –
A very quick&dirty example could be:
<?php
if (!defined('ELK'))
die('No access...');
class ValidateLogin_Integrate
{
public static function integrate_action_login()
{
global $context;
$context['disable_login_hashing'] = true;
}
public static function integrate_validate_login()
{
$db = database();
$request = $db->query('', '
SELECT *
FROM [icode]{your_database[/icode].[icode]{your_table}[/icode]
WHERE name = {string:username}
LIMIT 1',
array(
'username' => $_POST['user'],
'db_error_skip' => true
)
);
$result = $db->fetch_assoc($request);
echo '<pre>';
print_r($result);
// Check if the user exists in Elk {db_prefix}members as well
// If not create the new member using registerMember (and set 'interface' to something like 'external'
die();
}
}
The die above is just to show the result of the query, of course in the final code it should not be there.
The general idea is:
1) disable the Elk's client-side password hashing (otherwise you would not be able to compare the password),
2) verify the user exists in your database,
3) if exists create a new user in the Elk database.
The code above requires the two methods are "attached" to two hooks: integrate_action_login and integrate_validate_login.
I left out all the settings required for creating the new user, but if you need any hint feel free to ask.