MeAppBuilder
Member
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
Placed the code OnAfterProcess with my form. When I submit, I get:
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.
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.