Code for linking a redirect to a field in the jo_user table

Your code modifications and patches you want to share with others.
Locked
sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Code for linking a redirect to a field in the jo_user table

Post by sraj49 » Tue Jul 14, 2009 4:33 am

I have created a field column by name " url " and For each user and Pasword there is a corresponding url. As soon as the user is authenticated I would like them to be redirected to the url specified in te same table. Can ayone help me how to accomplish this?

I used user meta and created a firld for url on the uer menu itself. I also created a table called jo_usermeta and it automaticall is linked to the user ID.

I am not a programmer and very liitle knowledge of codes. can ayone help me please..

Raj

guru12
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Mon Jun 29, 2009 11:53 am
Location: Bangalore
Contact:

Re: Code for linking a redirect to a field in the jo_user table

Post by guru12 » Tue Jul 14, 2009 5:41 am

For that you need to modify the file components/com_user/controller.php line number 153

above that line you can write the code to get the corresponedent user redirect url from db and assign to $retrun

Code: Select all

$mainframe->redirect( $return );
http://www.joomla-web-developer.com Joomla Development
http://www.joomla-web-designer.com Joomla template customization

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: User Specific Login Redirect

Post by sraj49 » Wed Jul 15, 2009 12:28 am

Hey Guys,

I had a similar problem where I have to redirect users to userspecific urls. I tried the folloing...

1 Downloaded usermeta plugin which alloed me to create an additional field in the user menu. I created an url field in the user menu.

2 The process involved creating a link table called jos_usermeta. As soon we created a new user with the ul field it automatically populates the jos_usermeta with the uer ID for the specified url.

3 Now once the user logins he has to be directed to the specified url.

4 I am using joomla 1.5.12 and I am advised that I have to add code before line 153 of components/com_users/controller.php. Since I am new to coding can anyone help....

Thanks

Raj

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11393
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Code for linking a redirect to a field in the jo_user table

Post by ooffick » Wed Jul 15, 2009 4:04 pm

Mod Note: Duplicate post merged, please do not post your question twice. Bump post deleted, please do not bump your posts.


If you must change a core file then try the following

Code: Select all

		if(!JError::isError($error))
		{
			// Redirect if the return url is not registration or login
			if ( ! $return ) {
				$return	= 'index.php?option=com_user';
			}

			$mainframe->redirect( $return );
		}
and replace it with this:

Code: Select all

		if(!JError::isError($error))
		{

                        $return = 'your-path.php';

			// Redirect if the return url is not registration or login
			if ( ! $return ) {
				$return	= 'index.php?option=com_user';
			}

			$mainframe->redirect( $return );
		}
Please note that you will need to change your-path.php to the redirect path your are looking for.

Olaf
Olaf Offick - Global Moderator
learnskills.org

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: Code for linking a redirect to a field in the jo_user table

Post by sraj49 » Thu Jul 16, 2009 4:05 am

Thanks Olaf. I really appreciate. My problem is that

1 the url for redirect is available in the databse in table ljo_usermeta linked to the user ID.

2 On successful login the redirect should be to the url in jo_user meta table.

I tried my best to write the code but not able to.

Alternately I can enter the ulr for redirect in the jo_user table itslef and I have already created a column.

Whichever is better I need help in wirting the code and specifying the path. I would really appreciate your help.

Thank you

Raj

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11393
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Code for linking a redirect to a field in the jo_user table

Post by ooffick » Thu Jul 16, 2009 9:44 am

well, then replace in the code above this

Code: Select all

$return = 'your-path.php';
by the following:

Code: Select all

$user = JFactory::getUser();
$return = $user->your_column;
Please make sure you replace your_column with the column name you are using.

Olaf
Olaf Offick - Global Moderator
learnskills.org

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: Code for linking a redirect to a field in the jo_user table

Post by sraj49 » Thu Jul 16, 2009 5:09 pm

Wow...It works beautifully. I haveseen in may forums people discssing about redirect of login. This is a very good solution. I am able to specify user specific redirect. Once again I really appreciate your kind help and than you very much.

Take care and have a wonderful day

Raj

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: Code for linking a redirect to a field in the jo_user table

Post by sraj49 » Fri Jul 24, 2009 4:18 pm

Olaf,

Is there an email I can reach you? While upgrading to 1.5.13 the redirect is not working. It was working beautifully earlier. Earlier after I made the changes as suggested by you once the user logs in the user was directed to the url in the user meta table. but now it is getting redirected to the registered user login page. The code is exactly the same . I do not kno where the error is. Unfortunately the backup of the php file was corrupted.

if(!JError::isError($error))
{

$user = JFactory::getUser();
$return = $user->usermeta_url;


// Redirect if the return url is not registration or login
if ( ! $return ) {
$return = 'index.php?option=com_user';
}

I have seen that when the user is created and the url is specified in the url meta field, it gets posted in the usermeta table in the database under the column url.

I would really appreciate your help. I can send you the screen shots.

Thanks and have a wonderful day

Raj

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11393
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Code for linking a redirect to a field in the jo_user table

Post by ooffick » Fri Jul 24, 2009 4:53 pm

Hi Raj,

did you check if the field usermeta_url is set in the database?

Olaf
Olaf Offick - Global Moderator
learnskills.org

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: Code for linking a redirect to a field in the jo_user table

Post by sraj49 » Fri Jul 24, 2009 5:16 pm

Thanks for your prompt response.

Yes. When I update the user data with url through the user menu, the url filed in the usermeta table also gets updated. Can I give you access to my data base and cpanel?

Raj

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: Code for linking a redirect to a field in the jo_user table

Post by sraj49 » Fri Jul 24, 2009 7:07 pm

the field usermeta_url is set in the database and it gets updated

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11393
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Code for linking a redirect to a field in the jo_user table

Post by ooffick » Fri Jul 24, 2009 7:24 pm

sraj49 wrote:Yes. When I update the user data with url through the user menu, the url filed in the usermeta table also gets updated. Can I give you access to my data base and cpanel?
I would not recommend to give anybody access to your database.

Olaf
Olaf Offick - Global Moderator
learnskills.org

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: Code for linking a redirect to a field in the jo_user table

Post by sraj49 » Fri Jul 24, 2009 7:31 pm

I appreciate. It is only because you did help me and this will be one to one with you only. I am trying to do a parallel install and see. In the meantime can you please advice me how to proceed?

Thank

Raj

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: Code for linking a redirect to a field in the jo_user table

Post by sraj49 » Fri Jul 24, 2009 9:38 pm

Olaf,

Any help please. I am confused. When I create a ne user and fill in the meta (url) filed it gets posted in the user_meta table against the respective user id. But when we call the user through the components/com_user/controller.php itsi not able to redirect the user to the usermeta_url field. I checked all the details.

1 user meta enabled

2 when the url is filled in the admin/user details it gets posted in the usermeta table in the database in the url table along with the respective user id.

3 What worked earlier when the controller.php was modified doesn't work for me now.

I am intrigued...any ideas please....

Thanks

Raj

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11393
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Code for linking a redirect to a field in the jo_user table

Post by ooffick » Sat Jul 25, 2009 8:24 am

Didn't you say that this usermeta_url field was in the jos_user table?

Olaf
Olaf Offick - Global Moderator
learnskills.org

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: Code for linking a redirect to a field in the jo_user table

Post by sraj49 » Sat Jul 25, 2009 2:25 pm

Olaf,

No. The 'url' field is in the jo_usermeta table which I have created additionally.

While installing usermeta extension the follwing procedure has to be followed:

1 Instll usermea extension

2 Enable it

3 Create a jo_usermeta table

4 Create an 'ur'column

When I did this and through admin/user manager I clicked on the new user, the url field appears . I fill it up with the 'url' required then it automatically is saved in the jo_usermeta table in the database and also gts linked to the user id which it fetches from the jo_user table.

So specific answer to your question is that the 'url' field is in the jo_usermeta table.

Raj

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11393
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Code for linking a redirect to a field in the jo_user table

Post by ooffick » Sat Jul 25, 2009 8:26 pm

well, I don't that much about this extension.
But my guess would be that this jos_usermeta table is not included in the user object.

Olaf
Olaf Offick - Global Moderator
learnskills.org

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: Code for linking a redirect to a field in the jo_user table

Post by sraj49 » Sat Jul 25, 2009 11:07 pm

Olaf,

Thanks for your response. I am amazed because it worked beautifully before I upgraded to 1.5.13. How did it work earlier.; Iused the sdame code modifcation suggested by you.

I have also created a column for the url in the jo_user table. I can even redirect it to the the user tableand drop the jo_usermeta table altogether. I did try that also. what I did was I changed the code as:

{
$user = JFactory::getUser();

$return = $user-> user_url;

// Redirect if the return url is not registration or login
if ( ! $return ) {
$return = 'index.php?option=com_user';
}

This also does not work.


Raj

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11393
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Code for linking a redirect to a field in the jo_user table

Post by ooffick » Sun Jul 26, 2009 8:45 am

hi Raj,

there was a space between $user-> and user_url.

Can you try to remove it?

Code: Select all

$user = JFactory::getUser();

$return = $user->user_url;

// Redirect if the return url is not registration or login
if ( ! $return ) {
$return = 'index.php?option=com_user';
}
Olaf
Olaf Offick - Global Moderator
learnskills.org

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: Code for linking a redirect to a field in the jo_user table

Post by sraj49 » Sun Jul 26, 2009 2:55 pm

Thanks Olaf. I removed the space before user and this is the code I have...

$user = JFactory::getUser();

$return = $user->user_url;

// Redirect if the return url is not registration or login
if ( ! $return ) {
$return = 'index.php?option=com_user';
}

It still goes back to Registered Area with a Welcome Message " Welcome to the Registered Area.

This is the complete code at components/com_user/contoller.php

<?php
/**
* @version $Id: controller.php 12538 2009-07-22 17:26:51Z ian $
* @package Joomla
* @subpackage Content
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant to the
* GNU General Public License, and as distributed it includes or is derivative
* of works licensed under the GNU General Public License or other free or open
* source software licenses. See COPYRIGHT.php for copyright notices and
* details.
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );

jimport('joomla.application.component.controller');

/**
* User Component Controller
*
* @package Joomla
* @subpackage Weblinks
* @since 1.5
*/
class UserController extends JController
{
/**
* Method to display a view
*
* @access public
* @since 1.5
*/
function display()
{
parent::display();
}

function edit()
{
global $mainframe, $option;

$db =& JFactory::getDBO();
$user =& JFactory::getUser();

if ( $user->get('guest')) {
JError::raiseError( 403, JText::_('Access Forbidden') );
return;
}

JRequest::setVar('layout', 'form');

parent::display();
}

function save()
{
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );

$user =& JFactory::getUser();
$userid = JRequest::getVar( 'id', 0, 'post', 'int' );

// preform security checks
if ($user->get('id') == 0 || $userid == 0 || $userid <> $user->get('id')) {
JError::raiseError( 403, JText::_('Access Forbidden') );
return;
}

//clean request
$post = JRequest::get( 'post' );
$post['username'] = JRequest::getVar('username', '', 'post', 'username');
$post['password'] = JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW);
$post['password2'] = JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW);

// get the redirect
$return = JURI::base();

// do a password safety check
if(strlen($post['password']) || strlen($post['password2'])) { // so that "0" can be used as password e.g.
if($post['password'] != $post['password2']) {
$msg = JText::_('PASSWORDS_DO_NOT_MATCH');
// something is wrong. we are redirecting back to edit form.
// TODO: HTTP_REFERER should be replaced with a base64 encoded form field in a later release
$return = str_replace(array('"', '<', '>', "'"), '', @$_SERVER['HTTP_REFERER']);
if (empty($return) || !JURI::isInternal($return)) {
$return = JURI::base();
}
$this->setRedirect($return, $msg, 'error');
return false;
}
}

// we don't want users to edit certain fields so we will unset them
unset($post['gid']);
unset($post['block']);
unset($post['usertype']);
unset($post['registerDate']);
unset($post['activation']);

// store data
$model = $this->getModel('user');

if ($model->store($post)) {
$msg = JText::_( 'Your settings have been saved.' );
} else {
//$msg = JText::_( 'Error saving your settings.' );
$msg = $model->getError();
}


$this->setRedirect( $return, $msg );
}

function cancel()
{
$this->setRedirect( 'index.php' );
}

function login()
{
// Check for request forgeries
JRequest::checkToken('request') or jexit( 'Invalid Token' );

global $mainframe;

if ($return = JRequest::getVar('return', '', 'method', 'base64')) {
$return = base64_decode($return);
if (!JURI::isInternal($return)) {
$return = '';
}
}

$options = array();
$options['remember'] = JRequest::getBool('remember', false);
$options['return'] = $return;

$credentials = array();
$credentials['username'] = JRequest::getVar('username', '', 'method', 'username');
$credentials['password'] = JRequest::getString('passwd', '', 'post', JREQUEST_ALLOWRAW);

//preform the login action
$error = $mainframe->login($credentials, $options);

if(!JError::isError($error))
{
$user = JFactory::getUser();

$return = $user->user_url;

// Redirect if the return url is not registration or login
if ( ! $return ) {
$return = 'index.php?option=com_user';
}

$mainframe->redirect( $return );
}
else
{
// Facilitate third party login forms
if ( ! $return ) {
$return = 'index.php?option=com_user&view=login';
}

// Redirect to a login form
$mainframe->redirect( $return );
}
}

function logout()
{
global $mainframe;

//preform the logout action
$error = $mainframe->logout();

if(!JError::isError($error))
{
if ($return = JRequest::getVar('return', '', 'method', 'base64')) {
$return = base64_decode($return);
if (!JURI::isInternal($return)) {
$return = '';
}
}

// Redirect if the return url is not registration or login
if ( $return && !( strpos( $return, 'com_user' )) ) {
$mainframe->redirect( $return );
}
} else {
parent::display();
}
}

/**
* Prepares the registration form
* @return void
*/
function register()
{
$usersConfig = &JComponentHelper::getParams( 'com_users' );
if (!$usersConfig->get( 'allowUserRegistration' )) {
JError::raiseError( 403, JText::_( 'Access Forbidden' ));
return;
}

$user =& JFactory::getUser();

if ( $user->get('guest')) {
JRequest::setVar('view', 'register');
} else {
$this->setredirect('index.php?option=com_user&task=edit',JText::_('You are already registered.'));
}

parent::display();
}

/**
* Save user registration and notify users and admins if required
* @return void
*/
function register_save()
{
global $mainframe;

// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );

// Get required system objects
$user = clone(JFactory::getUser());
$pathway =& $mainframe->getPathway();
$config =& JFactory::getConfig();
$authorize =& JFactory::getACL();
$document =& JFactory::getDocument();

// If user registration is not allowed, show 403 not authorized.
$usersConfig = &JComponentHelper::getParams( 'com_users' );
if ($usersConfig->get('allowUserRegistration') == '0') {
JError::raiseError( 403, JText::_( 'Access Forbidden' ));
return;
}

// Initialize new usertype setting
$newUsertype = $usersConfig->get( 'new_usertype' );
if (!$newUsertype) {
$newUsertype = 'Registered';
}

// Bind the post array to the user object
if (!$user->bind( JRequest::get('post'), 'usertype' )) {
JError::raiseError( 500, $user->getError());
}

// Set some initial user values
$user->set('id', 0);
$user->set('usertype', $newUsertype);
$user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));

$date =& JFactory::getDate();
$user->set('registerDate', $date->toMySQL());

// If user activation is turned on, we need to set the activation information
$useractivation = $usersConfig->get( 'useractivation' );
if ($useractivation == '1')
{
jimport('joomla.user.helper');
$user->set('activation', JUtility::getHash( JUserHelper::genRandomPassword()) );
$user->set('block', '1');
}

// If there was an error with registration, set the message and display form
if ( !$user->save() )
{
JError::raiseWarning('', JText::_( $user->getError()));
$this->register();
return false;
}

// Send registration confirmation mail
$password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW);
$password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); //Disallow control chars in the email
UserController::_sendMail($user, $password);

// Everything went fine, set relevant message depending upon user activation state and display message
if ( $useractivation == 1 ) {
$message = JText::_( 'REG_COMPLETE_ACTIVATE' );
} else {
$message = JText::_( 'REG_COMPLETE' );
}

$this->setRedirect('index.php', $message);
}

function activate()
{
global $mainframe;

// Initialize some variables
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$document =& JFactory::getDocument();
$pathway =& $mainframe->getPathWay();

$usersConfig = &JComponentHelper::getParams( 'com_users' );
$userActivation = $usersConfig->get('useractivation');
$allowUserRegistration = $usersConfig->get('allowUserRegistration');

// Check to see if they're logged in, because they don't need activating!
if ($user->get('id')) {
// They're already logged in, so redirect them to the home page
$mainframe->redirect( 'index.php' );
}

if ($allowUserRegistration == '0' || $userActivation == '0') {
JError::raiseError( 403, JText::_( 'Access Forbidden' ));
return;
}

// create the view
require_once (JPATH_COMPONENT.DS.'views'.DS.'register'.DS.'view.html.php');
$view = new UserViewRegister();

$message = new stdClass();

// Do we even have an activation string?
$activation = JRequest::getVar('activation', '', '', 'alnum' );
$activation = $db->getEscaped( $activation );

if (empty( $activation ))
{
// Page Title
$document->setTitle( JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' ) );
// Breadcrumb
$pathway->addItem( JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' ));

$message->title = JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' );
$message->text = JText::_( 'REG_ACTIVATE_NOT_FOUND' );
$view->assign('message', $message);
$view->display('message');
return;
}

// Lets activate this user
jimport('joomla.user.helper');
if (JUserHelper::activateUser($activation))
{
// Page Title
$document->setTitle( JText::_( 'REG_ACTIVATE_COMPLETE_TITLE' ) );
// Breadcrumb
$pathway->addItem( JText::_( 'REG_ACTIVATE_COMPLETE_TITLE' ));

$message->title = JText::_( 'REG_ACTIVATE_COMPLETE_TITLE' );
$message->text = JText::_( 'REG_ACTIVATE_COMPLETE' );
}
else
{
// Page Title
$document->setTitle( JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' ) );
// Breadcrumb
$pathway->addItem( JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' ));

$message->title = JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' );
$message->text = JText::_( 'REG_ACTIVATE_NOT_FOUND' );
}

$view->assign('message', $message);
$view->display('message');
}

/**
* Password Reset Request Method
*
* @access public
*/
function requestreset()
{
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );

// Get the input
$email = JRequest::getVar('email', null, 'post', 'string');

// Get the model
$model = &$this->getModel('Reset');

// Request a reset
if ($model->requestReset($email) === false)
{
$message = JText::sprintf('PASSWORD_RESET_REQUEST_FAILED', $model->getError());
$this->setRedirect('index.php?option=com_user&view=reset', $message);
return false;
}

$this->setRedirect('index.php?option=com_user&view=reset&layout=confirm');
}

/**
* Password Reset Confirmation Method
*
* @access public
*/
function confirmreset()
{
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );

// Get the input
$token = JRequest::getVar('token', null, 'post', 'alnum');

// Get the model
$model = &$this->getModel('Reset');

// Verify the token
if ($model->confirmReset($token) === false)
{
$message = JText::sprintf('PASSWORD_RESET_CONFIRMATION_FAILED', $model->getError());
$this->setRedirect('index.php?option=com_user&view=reset&layout=confirm', $message);
return false;
}

$this->setRedirect('index.php?option=com_user&view=reset&layout=complete');
}

/**
* Password Reset Completion Method
*
* @access public
*/
function completereset()
{
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );

// Get the input
$password1 = JRequest::getVar('password1', null, 'post', 'string', JREQUEST_ALLOWRAW);
$password2 = JRequest::getVar('password2', null, 'post', 'string', JREQUEST_ALLOWRAW);

// Get the model
$model = &$this->getModel('Reset');

// Reset the password
if ($model->completeReset($password1, $password2) === false)
{
$message = JText::sprintf('PASSWORD_RESET_FAILED', $model->getError());
$this->setRedirect('index.php?option=com_user&view=reset&layout=complete', $message);
return false;
}

$message = JText::_('PASSWORD_RESET_SUCCESS');
$this->setRedirect('index.php?option=com_user&view=login', $message);
}

/**
* Username Reminder Method
*
* @access public
*/
function remindusername()
{
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );

// Get the input
$email = JRequest::getVar('email', null, 'post', 'string');

// Get the model
$model = &$this->getModel('Remind');

// Send the reminder
if ($model->remindUsername($email) === false)
{
$message = JText::sprintf('USERNAME_REMINDER_FAILED', $model->getError());
$this->setRedirect('index.php?option=com_user&view=remind', $message);
return false;
}

$message = JText::sprintf('USERNAME_REMINDER_SUCCESS', $email);
$this->setRedirect('index.php?option=com_user&view=login', $message);
}

function _sendMail(&$user, $password)
{
global $mainframe;

$db =& JFactory::getDBO();

$name = $user->get('name');
$email = $user->get('email');
$username = $user->get('username');

$usersConfig = &JComponentHelper::getParams( 'com_users' );
$sitename = $mainframe->getCfg( 'sitename' );
$useractivation = $usersConfig->get( 'useractivation' );
$mailfrom = $mainframe->getCfg( 'mailfrom' );
$fromname = $mainframe->getCfg( 'fromname' );
$siteURL = JURI::base();

$subject = sprintf ( JText::_( 'Account details for' ), $name, $sitename);
$subject = html_entity_decode($subject, ENT_QUOTES);

if ( $useractivation == 1 ){
$message = sprintf ( JText::_( 'SEND_MSG_ACTIVATE' ), $name, $sitename, $siteURL."index.php?option=com_user&task=activate&activation=".$user->get('activation'), $siteURL, $username, $password);
} else {
$message = sprintf ( JText::_( 'SEND_MSG' ), $name, $sitename, $siteURL);
}

$message = html_entity_decode($message, ENT_QUOTES);

//get all super administrator
$query = 'SELECT name, email, sendEmail' .
' FROM #__users' .
' WHERE LOWER( usertype ) = "super administrator"';
$db->setQuery( $query );
$rows = $db->loadObjectList();

// Send email to user
if ( ! $mailfrom || ! $fromname ) {
$fromname = $rows[0]->name;
$mailfrom = $rows[0]->email;
}

JUtility::sendMail($mailfrom, $fromname, $email, $subject, $message);

// Send notification to all administrators
$subject2 = sprintf ( JText::_( 'Account details for' ), $name, $sitename);
$subject2 = html_entity_decode($subject2, ENT_QUOTES);

// get superadministrators id
foreach ( $rows as $row )
{
if ($row->sendEmail)
{
$message2 = sprintf ( JText::_( 'SEND_MSG_ADMIN' ), $row->name, $sitename, $name, $email, $username);
$message2 = html_entity_decode($message2, ENT_QUOTES);
JUtility::sendMail($mailfrom, $fromname, $row->email, $subject2, $message2);
}
}
}
}
?>

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: Code for linking a redirect to a field in the jo_user table

Post by sraj49 » Sun Jul 26, 2009 2:57 pm

Hey Olaf,

Just to add to me message above.....In the data base I added a column for url as Text and filled in the url where I want the redirect to go.

Thank your for you rkind help..

Raj

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11393
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Code for linking a redirect to a field in the jo_user table

Post by ooffick » Sun Jul 26, 2009 6:57 pm

Hi Raj,

ok try the following:
/administrator/components/com_users/models/user.xml

Open the file and add this parameter:

Code: Select all

		<param name="url" type="text" default="" label="URL" description="URL" />
And change the controller components/com_user/contoller.php:

Code: Select all

			$user =& JFactory::getUser();
			$user->getParameters();
			$return = $user->getParam('url');
You can add the url to a user in the User Manager.

Olaf
Olaf Offick - Global Moderator
learnskills.org

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: Code for linking a redirect to a field in the jo_user table

Post by sraj49 » Sun Jul 26, 2009 8:46 pm

Olaf,

wow..this is a simple solution and what a lovely solution. Works beautifully now. I have the following issues.

1 The url is actuallay an application and for different cusomers we have different applications. When you login at the front ene jommla browser, it goes to the 'url' and when they logout of the apllication in the url it does not logout of the front end joomla. So when they type the webaddress the joomla once again the frontend shows them as still logged in . So you have to logout and login again to go to the specific `url'.

2 When I click on a new user in the user meny I can see the `url1 field. But after I create the new user and go back and tr to edit the user, the `url' filed is not visible. Which means that when I save `url` gets saved but does not appear in the userdetails saved in the frontend.

Can you help me fix this.

Hey Olaf, I sincerely wish too thank you for all your efforts. God bless you

Raj

2

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: Code for linking a redirect to a field in the jo_user table

Post by sraj49 » Sun Jul 26, 2009 8:55 pm

Olaf,

I checked the data base just now. In the jo_user table the url is not getting saved though the url colum exists. The url column i showing `NULL`. But the login gets redirected. Where does the `url` is getting saved then?

Raj

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11393
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Code for linking a redirect to a field in the jo_user table

Post by ooffick » Sun Jul 26, 2009 9:03 pm

Raj,

the new solution would use the param column in the jos_user table.

Olaf
Olaf Offick - Global Moderator
learnskills.org

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: Code for linking a redirect to a field in the jo_user table

Post by sraj49 » Sun Jul 26, 2009 9:33 pm

Tanks Olaf, I now see the l1url' under the param. How do we make it appear in the user dtails so that I can edit the same.

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11393
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Code for linking a redirect to a field in the jo_user table

Post by ooffick » Sun Jul 26, 2009 9:51 pm

Where do you want to see it? Can you explain what you mean?

Olaf
Olaf Offick - Global Moderator
learnskills.org

sraj49
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Jul 06, 2009 8:45 pm

Re: Code for linking a redirect to a field in the jo_user table

Post by sraj49 » Mon Jul 27, 2009 1:03 am

I go to user Manager and click on new I see the url field. But after I save I dont see the url field against each user. I onlt want to see it in admin area under user manager/user details. the user should not see the url.....

Also after the user is redirected to the url when he lgs out of there he should logout of joomla also.No what happens is that he logs in through the front login and gets redirected to the url login. He logs in and uses the appplication. But when he loges out of the application and he opens the browser again he is still logged in at the front page of Joomla.

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11393
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Code for linking a redirect to a field in the jo_user table

Post by ooffick » Mon Jul 27, 2009 8:59 am

How do you "logout"? If you click on the logout button then the user is not logged in anymore.

Try to add this to your template.css file:

Code: Select all

#paramsurl-lbl, #paramsurl {display:none;}
Olaf
Olaf Offick - Global Moderator
learnskills.org


Locked

Return to “Core Hacks and Patches”