• Payment Plugins Poll

    We need your feedback on the need for updated payment plugins. Please go here and give us your feedback.

  • Joomla 5.1

    For running J!5.1 you must install Fabrik 4.1
    See also Announcements

  • Subscription and download (Fabrik 4.1 for J!4.2+ and J!5.1) are working now

    See Announcement
    Please post subscription questions and issues here

    We have resolved the issue with the J! updater and this will be fixed in the next release.

  • Update & Changlog URL Fixer

    At the present time the update site URL for Fabrik is incorrect in all installations up to and including 4.1. This will be corrected in 4.2, however, if you wish to update Fabrik via the J! Updater you can download and install this plugin.

    This file is installed just like any other extension through the J! Extension Installation panel. It will not however actually install anything. Its sole purpose is to fix the Update Site and Changlog URL's. Once done it will simply exit.

    As always, we recommend you perform a site backup priot to installation.

joomla login script for fabrik custom login

Hello,

I have a stand-alone form form with 2 elements (username/password). Form will not save to database and therefore no db table is set. The Form is an ajax form.

Upon submit, I would like to validate and login joomla user. There is an external script, which looks good, but does not work: https://gist.github.com/AdamMadrzejewski/020c4fa4b1d0e7af78b8

PHP:
define('_JEXEC', 1);

  if (file_exists(__DIR__ . '/defines.php'))
  {
      include_once __DIR__ . '/defines.php';
  }

  if (!defined('_JDEFINES'))
  {
      define('JPATH_BASE', __DIR__);
      require_once JPATH_BASE . '/includes/defines.php';
  }

  require_once JPATH_BASE . '/includes/framework.php';

  // Instantiate the application.
  $app = JFactory::getApplication('site');

  // JFactory
  require_once (JPATH_BASE .'/libraries/joomla/factory.php');


$credentials['username'] = $formModel->_formData['___username'];
$credentials['password'] = $formModel->_formData['___password'];

  /**
   * Code adapted from plugins/authentication/joomla/joomla.php
   *
   * @package     Joomla.Plugin
   * @subpackage  Authentication.joomla
   *
   * @copyright   Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   */

  // Get a database object
  $db    = JFactory::getDbo();
  $query = $db->getQuery(true)
      ->select('id, password')
      ->from('#__users')
      ->where('username=' . $db->quote($credentials['username']));

  $db->setQuery($query);
  $result = $db->loadObject();

  if ($result)
  {
      $match = JUserHelper::verifyPassword($credentials['password'], $result->password, $result->id);

      if ($match === true)
      {
          // Bring this in line with the rest of the system
          $user = JUser::getInstance($result->id);
          echo 'Joomla! Authentication was successful!';
      }
      else
      {
          // Invalid password
          // Prmitive error handling
          die('Invalid password');
      }
  } else {
      // Invalid user
      // Prmitive error handling
      die('Cound not find user in the database');
  }

Placed the code OnAfterProcess with my form. When I submit, I get:

HTML:
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

I used to have a working script, but I have lost it.
Any help appreciated.

I could use the Joomla login script, but this will redirect to a component page when login failed. I would like to be more flexible with a custom fabrik form and define my own redirects and login behaviour.
 
Good point. Already read and thought about it.

The reason why I am not using JUser is simple: how do I set it up?

I have a register form with JUser and it is working. Not sure how to use with a login validation.
 
Thank you Troester.

I have seen the docs. I will try "Auto Login - if set to yes we will try to log in the user as soon as the form is submitted.".

I wasn't really sure, if JUser will actually act as a password/email validation only with existing users in db.
 
I have tried to use email(field)/password(field) and username(field)/password(field) with JUser and Auto-Login. Actually I want to login an existing user.

Ajax Form that does not save to database and does bypass all joomla stuff.

When I try to login, email/username field are flagged as error.

Not sure yet, what I am doing wrong here.
 
Last edited:
I haven't used much juser plugin, but this option seems only for logging user in after initial registering.

About your code, at least remove the following row as this file does not exist in newer versions of Joomla:
// JFactory
require_once (JPATH_BASE .'/libraries/joomla/factory.php');
 
but this option seems only for logging user in after initial registering
Yup (+ I think JUsers plugin doesn't make much sense without database)

For your code: I would look how Joomla is doing it in components\com_users\controllers\user.php
 
PHP OnBeforeProcess

Module / No Ajax / not saving to database / 2 fields: username/password

PHP:
defined('_JEXEC') or die;

jimport('joomla.plugin.plugin');

jimport('joomla.plugin.helper');
$app = JFactory::getApplication('site');
$JInput = $app->input;

$username = '{___username}';
$password = '{___password}';

$credentials = array();
$credentials['username'] = $username;
$credentials['password'] = $password;

$db = JFactory::getDbo();
$query = $db->getQuery(true)
  ->select('id, password')
   ->from('#__users')
   ->where('username=' . $db->quote($credentials['username']). ' OR email = '.$db->quote($credentials['username']));
$db->setQuery($query);
$result = $db->loadObject();

if ($result) {

   if (JUserHelper::verifyPassword($credentials['password'], $result->password, $result->id)) {
       //GET USER INSTANCE FROM DATABASE ID
       $user = JUser::getInstance($result->id);
       //LOGIN THE USER
       $app->login($credentials, $options = array());
    JFactory::getApplication()->enqueueMessage(JText::_('FABRIKL_SYSTEM_MESSAGE_LOGIN_SUCCESS'));
   }
   else
   {
       //HANDLE INCORRECT PASSWORD
    JFactory::getApplication()->enqueueMessage(JText::_('FABRIKL_SYSTEM_MESSAGE_LOGIN_ERROR'), 'error');
   }
}
else
{
   //HANDLE INVALID USERNAME
  JFactory::getApplication()->enqueueMessage(JText::_('FABRIKL_SYSTEM_MESSAGE_LOGIN_ERROR'), 'error');
}
 
Last edited:

Members online

No members online now.
Back
Top