Single log in
Posted by ality
|
Single log in October 07, 2008 11:24PM |
Registered: 17 years ago Posts: 14 |
Users can register on main site once, they would have both account of main system and phorum. So I add a function to insert new registration info. at the same time when somebody does its registration at main system.
[code="php"]
$query="INSERT INTO phorum.phorum_users (username, display_name, password) VALUES ('".mysql_escape_string($username)."','".mysql_escape_string($disname)."','".mysql_escape_string($pwd)."')";
[/code]
After registration, data does exist in table phorum_users, but when I try to log in the phorum, it said "That username/password was not found or is inactive. Please try again.".
"active" in the table was set to 1 by default.
Could anyone tell tell me what is wrong? Thanks a lot!
[code="php"]
$query="INSERT INTO phorum.phorum_users (username, display_name, password) VALUES ('".mysql_escape_string($username)."','".mysql_escape_string($disname)."','".mysql_escape_string($pwd)."')";
[/code]
After registration, data does exist in table phorum_users, but when I try to log in the phorum, it said "That username/password was not found or is inactive. Please try again.".
"active" in the table was set to 1 by default.
Could anyone tell tell me what is wrong? Thanks a lot!
|
Re: Single log in October 08, 2008 02:27AM |
Admin Registered: 21 years ago Posts: 8,532 |
Using the Phorum user API is probably the best way to create the Phorum user (phorum_api_user_save()). Basic code:
[code="php"]
<?php
$curcwd = getcwd();
chdir("/your/phorum/dir");
include("./common.php");
phorum_api_user_save(array(
"user_id" => NULL, // or the user id from your main user database
"username" => $username,
"real_name" => $disname,
"password" => $pasword,
"active" => PHORUM_USER_ACTIVE
));
chdir($curcwd);
?>
[/code]
If you want to implement single login, then search for "user_session_restore" in these forums for examples on how to do that using a module that implement the session restore hook. When doing that, you wouldn't even have to sync the password in the user table, because Phorum would not do the authentication. It would simply inherit your main user system's authenticated user. For that, it would be easy to have the user_id the same in both dbs (if your user table has a numerical user id for the user), since that would make the mapping easy inside the module code (you'll have to tell Phorum what Phorum user_id to make active).
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
[code="php"]
<?php
$curcwd = getcwd();
chdir("/your/phorum/dir");
include("./common.php");
phorum_api_user_save(array(
"user_id" => NULL, // or the user id from your main user database
"username" => $username,
"real_name" => $disname,
"password" => $pasword,
"active" => PHORUM_USER_ACTIVE
));
chdir($curcwd);
?>
[/code]
If you want to implement single login, then search for "user_session_restore" in these forums for examples on how to do that using a module that implement the session restore hook. When doing that, you wouldn't even have to sync the password in the user table, because Phorum would not do the authentication. It would simply inherit your main user system's authenticated user. For that, it would be easy to have the user_id the same in both dbs (if your user table has a numerical user id for the user), since that would make the mapping easy inside the module code (you'll have to tell Phorum what Phorum user_id to make active).
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
|
Re: Single log in October 08, 2008 04:30AM |
Registered: 17 years ago Posts: 14 |
hi Maurice:
just add the codes in my signup.php as your wrote above, and change the varible accordingly. But it seems not working. Registration Info. has not been inserted into phorum_users. Why that happened? btw, should I modify the function phorum_api_user_save in ./include/api/user.php? thanks a lot!
just add the codes in my signup.php as your wrote above, and change the varible accordingly. But it seems not working. Registration Info. has not been inserted into phorum_users. Why that happened? btw, should I modify the function phorum_api_user_save in ./include/api/user.php? thanks a lot!
|
Re: Single log in October 08, 2008 04:40AM |
Admin Registered: 21 years ago Posts: 8,532 |
Why would you change the function in include/api/user.php?
This code should work like this. Is this code really called? Do you see anything useful in your error log?
Two things that I forgot:
Here's a script that I just tested out successfully on my 5.2 test install:
[code="php"]
<?php
chdir('/home/...../phorum_5_2');
define('phorum_page','create_user');
include_once("./common.php");
phorum_api_user_save(array(
'user_id' => NULL,
'username' => 'testing2',
'password' => 'coolpass',
'email' => 'testing2@example.com',
'real_name' => 'Test user',
'active' => PHORUM_USER_ACTIVE
));
?>
[/code]
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
This code should work like this. Is this code really called? Do you see anything useful in your error log?
Two things that I forgot:
- common.php expects a "phorum_page" define (but omitting that should mainly raise a warning)
- an e-mail address is required.
Here's a script that I just tested out successfully on my 5.2 test install:
[code="php"]
<?php
chdir('/home/...../phorum_5_2');
define('phorum_page','create_user');
include_once("./common.php");
phorum_api_user_save(array(
'user_id' => NULL,
'username' => 'testing2',
'password' => 'coolpass',
'email' => 'testing2@example.com',
'real_name' => 'Test user',
'active' => PHORUM_USER_ACTIVE
));
?>
[/code]
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
|
Re: Single log in October 08, 2008 04:50AM |
Registered: 17 years ago Posts: 14 |
[code="php"]
$curcwd = getcwd();
chdir("/phorum");
include("./common.php");
include("./include/api/user.php");
include("./include/db/mysql.php");
phorum_api_user_save(array(
"user_id" => NULL,
"username" => $_POST['username'],
"password" => $_POST['pwd'],
"active" => 1,
));
chdir($curcwd);
}
[/code]
$curcwd = getcwd();
chdir("/phorum");
include("./common.php");
include("./include/api/user.php");
include("./include/db/mysql.php");
phorum_api_user_save(array(
"user_id" => NULL,
"username" => $_POST['username'],
"password" => $_POST['pwd'],
"active" => 1,
));
chdir($curcwd);
}
[/code]
|
Re: Single log in October 08, 2008 04:54AM |
Admin Registered: 21 years ago Posts: 8,532 |
Sorry, but what is your question? Must I guess?
My last code example works. Go from there I would say. I see that you are using different code now. Yours should work I guess, but you include too many files (common.php will take care of that) and you're not using PHORUM_USER_ACTIVE for assigning a value to the "active" field.
Is Phorum really installed in "/Phorum" on your server?? That is the root of the filesystem, which would be highly unusual. Maybe it's better to use a relative path, if you don't know the real full filesystem path.
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
My last code example works. Go from there I would say. I see that you are using different code now. Yours should work I guess, but you include too many files (common.php will take care of that) and you're not using PHORUM_USER_ACTIVE for assigning a value to the "active" field.
Is Phorum really installed in "/Phorum" on your server?? That is the root of the filesystem, which would be highly unusual. Maybe it's better to use a relative path, if you don't know the real full filesystem path.
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
|
Re: Single log in October 08, 2008 05:23AM |
Registered: 17 years ago Posts: 14 |
|
Re: Single log in October 08, 2008 05:31AM |
Admin Registered: 21 years ago Posts: 8,532 |
So, now make the next step by fixing your code.
"/Phorum" is not the correct path.
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
"/Phorum" is not the correct path.
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
|
Re: Single log in October 08, 2008 06:39AM |
Registered: 17 years ago Posts: 14 |
[code="php"]
define('phorum_page','create_user');
include_once('./phorum/common.php');
phorum_api_user_save(array(
"user_id" => NULL, // or the user id from your main user database
"username" => $_POST['mail'],
"real_name" => $_POST['mail'],
"password" => $_POST['pwd'],
"email" => 'johndoe@site.com',
"active" => PHORUM_USER_ACTIVE
));
[/code]
am i right?
define('phorum_page','create_user');
include_once('./phorum/common.php');
phorum_api_user_save(array(
"user_id" => NULL, // or the user id from your main user database
"username" => $_POST['mail'],
"real_name" => $_POST['mail'],
"password" => $_POST['pwd'],
"email" => 'johndoe@site.com',
"active" => PHORUM_USER_ACTIVE
));
[/code]
am i right?
|
Re: Single log in October 08, 2008 06:41AM |
Admin Registered: 23 years ago Posts: 9,240 |
Sorry, only registered users may post in this forum.
