February 2020 -  Joomla-TNG joint login development project.

From this page you can access the test/development version of 'A Country Squire; Jan Squire's Family History Pages'. Click the link below to go to the home page, from where you can search for a family name, a full name, or explore some of the other links. You don't need to log in; you will have full access to my ancestors born before 1920, and those not marked as living. If you use your login credentials, you will be able to see details of all persons listed. I have not included images nor maps here. You can be as creative as you like with the content on this page . . .

{source}
<?php 
$user = JFactory::getUser(); 
$usertng = $user->username;
   if ($usertng == "") 
      {
      $usertng = "nouser";
      }
// set a cookie with the Joomla User Name, to be able to use the variable later
setcookie ('joomlatotng', $usertng, time() + 5000, '/');
echo "<A href='../../../devtng/joomlatotng.php?tnguser=". $usertng." '>Go to Jan's Family History home page (Test version) </A> ";
echo "<br>User (temp entry only); ".$usertng;
?>
{/source} 

Some TNG users want to integrate Joomla and TNG to have only a single login. This mod allows for all users to login in Joomla, and the TNG login is disabled. There are some shortcomings;

  • TNG and Joomla have different user password algorithms, and I have not attempted to merge TNG and Joomla users. Everyone has to login through Joomla
  • I don't want to re-write Darrin's TNG login script so that TNG users can login in TNG, but have their credentials validated in the Joomla database
  • I have not attempted to merge the templates of Joomla and TNG, so styles are what they are
  • This mod in TNG uses a admin defined user password that is not known to TNG users, so this system will not work for existing TNG users. I as developer do not have access to TNG user passwords, so I cannot transfer them to Joomla. They will all need Joomla login credentials

This Joomla site is essentially my 'playground', to explore coding ideas, and to facilitate the recording of all sorts of stuff. Once this project works, I will get serious about developing this 'Family History Village' site further. This TNG is a copy of my main site at https://jansquire.com/tng

How the joint login works

Joomla has a login 'widget' that is easily accessable, and is used according to the Joomla site owner's choices. This Joomla page (the one you are currently reading), has some hidden php code that gets the user name, if logged in. When this page is opened, the hidden script is executed, and sets up the URL to TNG, with the username as a parameter. If the user clicks the TNG link above, you/they are redirected to the TNG file 'Joomlatotng.php', which retrieves the user name (if logged in). The username variable defaults to 'nouser' if not logged in. It is desirable that you do not share this URL, because it does include your (actually the logged in user's) Joomla user name.

This link calls joomlatotng.php, which the mod installed, and the script extracts the user name. If the user is nouser, you still get passed to the login page, but the login fails because the fields are blank. You won't see the error message though, and you will be re-directed to the TNG home page. If there is a user name of at least three characters, the script checks the TNG user table. If the user is in the table, the login is processed. If the user is not in the user table, the name is added to the user table, with basic guest rights, and the login is processed. You then are re-directed to the home page. Remember, if the user is in your Joomla user list, they will get automatic TNG guest access. Which ever option occurs, the user arrives at the TNG home page to do their thing.

That essentially is all I have done. You might think about the following issues and decisions/assumptions I have made, and suggest possible features you would like, or (heaven forbid) issues I have not foreseen: 

  • A user has to be in your Joomla user list to get registered access to TNG. Depending on user rights set in TNG, users do not have to log in.
  • The URL into TNG will show your username, if logged in. I do not see that as an issue, but do not share this link. I save the username as a cookie, but some users may have a cookie policy or cookies may be disabled.
  • To avoid possible parameter abuse, I test to ensure the submitted user name is already in the Joomla user data table.
  • I use a common password of my choosing for all automated TNG logins, so pre-existing users will not be able to login with my current script. I cannot process the Joomla encrypted password within TNG, because the encoding is different.
  • If you have a lot of current TNG users you want to keep, please let me know, and I should be able to copy them into Joomla, but would have to force those users to change their password.
  • Once a user has been added to TNG, you can easily change/upgrade any user's access permissions, even to be an Admin if you want.
  • I have so far only tested this on Template 4, but don't think it will be a problem on any Template.
  • The login page has a small time delay built in, currently a couple of seconds, but that will be reduced to less that a second, once I finish testing.
  • I still need to find a way to easily get back to Joomla from each page, but adding a link to the main menu is probably the way to go - to be thought about.
  • I need to disable the new registrations page, and add a note about how registration works.
  • I will list the guest permissions that are given to newly created users.
  • I still need to ensure that Joomla and TNG share the same session expiry time, and will enable/test that soon. Complex but working on it . . .
  • Google was my friend to get code ideas to make this work.

I need to change my hard coded variables and text into defined variables, and some of them need to be user selected. I will include them here once tested in my WAMP server. I am currently setting up the mod zip file for my testing.