Directly inserting into smf_members table, registerMember and more

Started by ibookdb, June 16, 2009, 04:52:12 PM

Previous topic - Next topic

ibookdb

I have some questions about the login and registration part of SMF:

1. What are the side effects of directly inserting a row into the smf user table? What must be done after the insertion? Are there some functions that I can call to do some housekeeping?

OR

1. Alternatively, I see a function called registerMember($regOptions)
What should the regoptions array have if I want to silently register a member that is already activated?

2. Also, how do I silently login a member. e.g. Member comes to site, does some actions which help me figure out the id of the member. Once the ID is known, is there some function which I can use to directly login the member without entering a username and password? (this is for developing a facebook connect utility that will not mess with any SMF Code/database at all)
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

ibookdb

Quote from: Arantor on June 16, 2009, 05:51:36 PM
1. If you insert a row you need to be generating the salt, and hashed salted password yourself. Otherwise it shouldn't be an issue IIRC. Have a look at what Sources/Register.php does to be sure.

OR

1. Try looking through the Function DB for more information. It's in the Support area linked above.

2. Use the SSI.php functions to check the cookie presented by the user. Just by including SSI.php it will attempt to log in the user for you based on the presented cookie. More information in the SSI Readme

I looked in the functionDB but there are not enough details about the RegisterMember function.

I can't use SSI.php because the Login function from SSI requires regular login. I need something that will help login a user who is not logged in without having them enter a password. Something link LoginUser(Id)
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

ibookdb

What does setLoginCookie do if I call it without a password? (it is not required according to the documentation.
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

ibookdb

If I call SetLoginCookie, will it automatically login that user? What should cookie length be if I want to login someone forever?
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

Orstio

Quote from: ibookdb on June 16, 2009, 04:52:12 PM
I have some questions about the login and registration part of SMF:

1. What are the side effects of directly inserting a row into the smf user table? What must be done after the insertion? Are there some functions that I can call to do some housekeeping?

OR

1. Alternatively, I see a function called registerMember($regOptions)
What should the regoptions array have if I want to silently register a member that is already activated?

2. Also, how do I silently login a member. e.g. Member comes to site, does some actions which help me figure out the id of the member. Once the ID is known, is there some function which I can use to directly login the member without entering a username and password? (this is for developing a facebook connect utility that will not mess with any SMF Code/database at all)

1)  Check here: http://www.simplemachines.org/community/index.php?topic=48220.0

2)  To silently login a member, use the integrate_verify_user hook.  Information on how to use the integration hooks is here:  http://www.simplemachines.org/community/index.php?topic=173483.0


ibookdb

Quote from: Orstio on June 18, 2009, 07:41:40 AM

1)  Check here: http://www.simplemachines.org/community/index.php?topic=48220.0

2)  To silently login a member, use the integrate_verify_user hook.  Information on how to use the integration hooks is here:  http://www.simplemachines.org/community/index.php?topic=173483.0


Thanks, I'm looking at the integration hooks but I can't figure out how to use them.



require_once('forums/SSI.php');

define('SMF_INTEGRATION_SETTINGS', serialize(array(
'integrate_verify_user' => 'integrate_verify_user',
)));

integrate_verify_user();


function integrate_verify_user() {
/*
Do some stuff to get id_member
*/
echo $result[0]['id_member']; //this works because it does echo the id of the member
return $result[0]['id_member'];
}





What else do I need to do to actually login the user? because the above did not do it.

Thanks!!
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

Orstio

Your code is backwards.  The integration hooks need to be defined before calling SSI.  You also don't need to call the hook function, because it is done automatically internally in SMF.

define('SMF_INTEGRATION_SETTINGS', serialize(array(
'integrate_verify_user' => 'integrate_verify_user',
)));

require_once('forums/SSI.php');


function integrate_verify_user() {
/*
Do some stuff to get id_member
*/
echo $result[0]['id_member']; //this works because it does echo the id of the member
return $result[0]['id_member'];
}

ibookdb

Something more has to be required here.

How will SMF know to login the user? Just by including SSI.php?

This code is not in any SMF file. It is just in a separate file, lets call it autolog.php

Here is what needs to happen:
1. User goes to autolog.php
2. User enters some info
3. If info is correct -> login silently to SMF, otherwise echo error


define('SMF_INTEGRATION_SETTINGS', serialize(array(
'integrate_verify_user' => 'integrate_verify_user',
)));

require_once('forums/SSI.php');

function integrate_verify_user() {
/*
Verify User
*/

if($result) {
return $result[0]['id_member'];
} else {
echo 'Error Message';
exit();
}

}



Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

Orstio

Add this to your SMF index.php (near the beginning, right after Settings.php should be fine):

include_once('autolog.php');

Then you can also change it to this:

define('SMF_INTEGRATION_SETTINGS', serialize(array(
'integrate_verify_user' => 'integrate_verify_user',
)));

function integrate_verify_user() {
/*
Verify User (make sure to global your database vars)
*/

if($result) {
return $result[0]['id_member'];
} else {
echo 'Error Message';
exit();
}

}

ibookdb

ok, now when I go to the page and login, I see myself logged in but if I click anywhere else, I'm logged out :( How do I keep the user logged in?
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

Orstio

Make sure that subdomain independent cookies are on.  Make sure your cookie is readable from SMF.  The integrate_verify_user hook is intended for reading external cookies, looking up the user id in SMF, and returning that.

ibookdb

What if there are no external cookies and I'm only relying on SMF? How do I get SMF to create the cookies so that the user remains logged in?

Thanks
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

Orstio

Ah, now I see exactly what you're after.

On a positive result, you'll need to set the cookie:


include_once('Sources/LoginOut.php');
DoLogin();

ibookdb

Thanks, now where exactly would I put the code to set the cookie? in index.php or autolog.php? Also DoLogin doesn't seem to be a funcion. (still running SMF 1.1). Maybe SetLoginCookie instead?
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

Orstio

Ah, OK, I was looking at 2.0.

Yes, setLoginCookie should work.  You put the code in the integrate_verify_user function, after you confirm the user has a valid id.

ibookdb

Doesn't work. I added:


define('SMF_INTEGRATION_SETTINGS', serialize(array(
'integrate_verify_user' => 'integrate_verify_user',
)));

function integrate_verify_user() {
/*
Verify User (make sure to global your database vars)
*/

if($result) {
require_once('Sources/Subs-Auth.php');
setLoginCookie(-1, $result[0]['id_member'], $result[0]['passwd']);
return $result[0]['id_member'];
} else {
return false;
}

}


The user gets logged in but no cookies are created (verified in browser that there are no SMF cookies) so the user doesn't stay logged in.
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

Orstio


ibookdb

It is coming from a join query between a new table and an smf table.
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

ibookdb

It returns id_member correctly. Even if $result is of global scope that doesnt do anything to set the smf cookie. It is declared in the part that says /* verify user */. I didn't post the code for that because it is internal ibookdb stuff. (I will post a version of the code in the facebook connect thread once I get everything working)

What I need now is a way to set SMFs cookie and setLoginCookie is not working. My application has no cookies or any login mechanism of its own. It completely relies on SMF for that.

I'm now creating a new login mechanism (still no cookies or anything) that will verify who the user is and I want to silently login the user to smf. integrate_verify _user does that but it does not set the smf login cookie so the user does not stay logged in away from that page.

So after doing integrate_verify_user, how do I go about setting the cookie?
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

ibookdb

I also tried this now calling Login2() after setting all the $_REQUEST parameters


define('SMF_INTEGRATION_SETTINGS', serialize(array(
'integrate_verify_user' => 'integrate_verify_user',
)));

function integrate_verify_user() {
/*
Verify User (make sure to global your database vars)
*/

if($result) {
require_once('Sources/LogInOut.php');

$_REQUEST['user']=$result[0]['memberName'];
$_REQUEST['passwrd']=$result[0]['passwd'];
$_REQUEST['cookielength']=-1;
require_once('Sources/LogInOut.php');
Login2();

//require_once('Sources/Subs-Auth.php');
//setLoginCookie(-1, $result[0]['id_member'], $result[0]['passwd']);


return $result[0]['id_member'];
} else {
return false;
}

}


but that didn't work either :(

I also tried using smf_1-1_api.php but that gave me lots of errors so I gave up on that.
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

ibookdb

Quote from: Arantor on June 19, 2009, 09:13:43 PM
So... there is some code where you have placed:

/*
Verify User (make sure to global your database vars)
*/



What does that do?


checks that the user is logged into facebook. Then it looks through my table to find the userid and then through smf tables to find other info for that userid.
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

Orstio

Here's the line you need to set a proper SMF cookie:

setLoginCookie($cookie_length, $ID_MEMBER, sha1($password.$salt));

You'll need to change the variables to match yours.

ibookdb

Quote from: Orstio on June 20, 2009, 11:09:27 AM
Here's the line you need to set a proper SMF cookie:

setLoginCookie($cookie_length, $ID_MEMBER, sha1($password.$salt));

You'll need to change the variables to match yours.

That is exactly what I am doing but no cookie is set :(
See code in this post - http://www.simplemachines.org/community/index.php?topic=318112.msg2116815#msg2116815
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

ibookdb

Here is some incentive to help on this one

Free copy of one of these books (your choice) shipped to you from iBookDB if you help solve my login problem
- Quantico - Greg Bear - signed
- Love Lies and Texas Dips - Susan Mcbride - signed
- Night Gardner - George Pelecanos
- Bad Luck and Trouble - Lee Child
- Breathless - Lurlene McDaniel
- Havah: The Story of Eve/A Novel - Tosca Lee - (i think this one is signed)
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

ibookdb

I discovered that cookielength -1 doesn't work. When I set that to 80000 it seems to have set the cookie but the user is still not logged in :(

When the user goes to another page, the cookie remains but the user is logged out. Any ideas what more needs to be done?
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

ibookdb

Ok problem solved. For those wanting updated code - here goes:


define('SMF_INTEGRATION_SETTINGS', serialize(array(
'integrate_verify_user' => 'integrate_verify_user',
)));

function integrate_verify_user() {
/*
Verify User (make sure to global your database vars)
*/

if($result) {
require_once('Sources/LogInOut.php');

require_once('Sources/Subs-Auth.php');
setLoginCookie(-1, $result[0]['id_member'], sha1($result[0]['passwd'].$result[0]['passwordSalt']));

return $result[0]['id_member'];
} else {
return false;
}

}
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

Nao 尚

So... All you needed was to encrypt the password, eh?
Sorry I wasn't there to help ;) I also kinda lost my time reading through the two pages until I realized it was too late, lol.
I will not make any deals with you. I've resigned. I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.

Aeva Media rocks your life.

ibookdb

yeah I didn't realize that the encrypted password is encrypted again with the salt :)
Manage Your Book Collection Online at The Internet Book Database

Random Books from My Bookshelf

iBookDB

Nao 尚

I will not make any deals with you. I've resigned. I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.

Aeva Media rocks your life.

Advertisement: