Auto login for newly registered users

13 years 1 month ago #159455 by piggybackup
Auto login for newly registered users was created by piggybackup
Hi,

I'm working on a joomla site using CB and CBSubs. I'd like to reduce the number of clicks for my users and automatically log them into CB once they've successfully registered.

I'm fairly new to Joomla development and website development in general but have a fairly strong background in computer science and development, so please tailor your responses accordingly if possible :) .

I found a post that seems to answer half of my question here: 159073-attaching-php-scrip (how can I run a PHP script when a user successfully registers). The salient point from this exchange is:

Using incubator project CB Code you could execute your PHP file on the CB trigger after registration. This would do what you're wanting. Aside from that you'll need to develop a new integration to execute your code or place the code directly into CBs core (not recommend and can't advise you as to how).



I still need an answer to the second half of my question (and further info on the first half would help as well). Second half: I need to find the code that cblogin uses to log a user in so that I can write my PHP script. Where is it located (where in my website file tree). I have done some digging through areas that seem to make sense, but can't find it. For instance: html/modules/mod_cblogin/mod_cblogin.php doesn't seem to contain the info that I'm looking for. Perhaps the missing code is in one of the files that PHP includes within this file?

Can the community direct me to the locations and filenames containing the PHP code used by the cblogin to actually log a user into the system?

It would be great if feedback included hints or good reasons why this might be a bad idea.

Any help would be much appreciated!

Very Best,
-Dan

If it's of any consequence, here's my version info:

CB: 1.3
CBSUBS: 1.1.0

Joomla:
System Information

Setting: Value

PHP Built on: Linux n17 2.6.33.1mtv2 #1 SMP Tue Jul 20 21:31:39 PDT 2010 i686
Database Version: 4.1.25-Debian_mt1
Database Collation: utf8_general_ci
PHP Version: 5.2.14
Web Server: Apache/2.0.54
Web Server to PHP interface: cgi-fcgi
Joomla! Version: Joomla! 1.5.20 Stable [ senu takaa ] 18-July-2010 18:00 GMT
User Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16

Sorry that I forgot to post it in the original request.

Please Log in to join the conversation.

13 years 1 month ago #159484 by krileon
Replied by krileon on topic Re: Auto login for newly registered users
You can find the code responsible for triggering a login within the Facebook Connect or Twitter plugins. You could also review the below snippet which allows login without password. CBs authentication library handles the login process providing login and logout functions.
cbimport( 'cb.authentication' );

$cbAuthenticate		=	new CBAuthentication();

$messagesToUser		=	array();
$alertmessages		=	array();
$redirect_url		=	'LOGIN_REDIRECT_URL_HERE';
$resultError		=	$cbAuthenticate->login( $user->username, false, 0, 1, $redirect_url, $messagesToUser, $alertmessages, 0 );

if ( $resultError ) {
	$user->_error	=	$resultError;
} else {
	return ( count( $alertmessages ) > 0 ? stripslashes( implode( '<br />', $alertmessages ) ) : true );
}

With the above ensure you replace LOGIN_REDIRECT_URL_HERE as necessary. If "false" directly after username is replaced with $user->password it'll require password for login, but for this situation that's likely not necessary.

CB: 1.3
CBSUBS: 1.1.0

You are out of date, please upgrade. Can not guarantee API functionality in previous releases.

CB: 1.4
CBSubs: 1.1.2


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

13 years 1 month ago #159597 by piggybackup
Replied by piggybackup on topic Re: Auto login for newly registered users
Mr K,

Thank you for your quick reply! I have upgraded my CB and CB Subs to the latest version based on your feedback.

In regard to the Redirect URL: Is it possible to omit the $redirect_url from the call to $cbAuthenticate->login?

I ask because I don't want to move my user from the page they're currently/about to be viewing. I just want the system to recognize that they are logged in.

This is because CB is automatically bringing the user to the "Thank you for successfully registering" page, and I don't know where to find the URL for that, and it may be dynamically generated. It would be much easier if I could just authenticate the user behind the scenes without any redirection.

How might I best accomplish this?

Thanks again for the help.

Very Best,
-Dan

Please Log in to join the conversation.

13 years 1 month ago #159859 by krileon
Replied by krileon on topic Re: Auto login for newly registered users
You could specify index.php as the redirect URL which would send to home page, but you'll still see the messages. If you don't set $user->_error then the messages should be suppressed and likely won't display anything effectively performing a silent login.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

12 years 9 months ago #171641 by houfton
Replied by houfton on topic Re: Auto login for newly registered users
I am trying to implement auto login using an external script called by the CB Code plugin (also trying CBSubs CB URL plugin) using an onAfterUserRegistration trigger (or First Subscription Activation).

I have read this and other threads and had a look at cb.twitter.php for some clues but think I might be missing the point... Is this anywhere close to right for the external script?
<?php
global $_CB_framework, $mainframe;
 
if ( defined( 'JPATH_ADMINISTRATOR' ) ) {
	if ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) {
		echo 'CB not installed!';
		return;
	}
 
	include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' );
} else {
	if ( ! file_exists( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' ) ) {
		echo 'CB not installed!';
		return;
	}
 
	include_once( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' );
}

cbimport( 'cb.authentication' );
 
$cbAuthenticate		=	new CBAuthentication();
 
$messagesToUser		=	array();
$alertmessages		=	array();
$redirect_url		=	'index.php?option=com_comprofiler&Itemid=2&task=userDetails';
$resultError		=	$cbAuthenticate->login( $user->username, false, 0, 1, $redirect_url, $messagesToUser, $alertmessages, 0 );
 
if ( $resultError ) {
	$user->_error	=	$resultError;
} else {
	return ( count( $alertmessages ) > 0 ? stripslashes( implode( '<br />', $alertmessages ) ) : true );
}
?>

I am able to get results with simpler test scripts but I am not getting anywhere with this.

CB 1.4, Joomla 1.5.22

Please Log in to join the conversation.

12 years 9 months ago #171690 by krileon
Replied by krileon on topic Re: Auto login for newly registered users
This should be done through a new CB plugin designed to handle the login from within CB/Joomla. The external execution likely won't function as Joomla and CB APIs will not work outside of themselves. This can be done new a new trigger based plugin, you can find more on triggers as well as installable example plugin at the below tutorial.

www.allmysocials.com/directory/tutorials/item/228-event-triggers


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.246 seconds

Facebook Twitter LinkedIn