93 lines
2.9 KiB
PHP
93 lines
2.9 KiB
PHP
<?php
|
|
if (version_compare(PHP_VERSION, '5.3.1', '<')) { die('Your host needs to use PHP 5.3.1 or higher to run this version of Joomla!'); }
|
|
|
|
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';
|
|
|
|
$app = JFactory::getApplication('site'); // Instantiate the application.
|
|
|
|
jimport('joomla.plugin.helper');
|
|
|
|
require_once (JPATH_BASE .'/libraries/joomla/factory.php'); // JFactory
|
|
|
|
$credentials['username'] = trim($_POST['username']);
|
|
$credentials['password'] = trim($_POST['password']);
|
|
$credentials['serial'] = (int)$_POST['serial'];
|
|
|
|
$db = JFactory::getDbo();
|
|
$query = $db->getQuery(true);
|
|
$query
|
|
->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)
|
|
{
|
|
$user = JUser::getInstance($result->id); // Bring this in line with the rest of the system
|
|
$error = $app->login($credentials); //perform the login action
|
|
$logged_user = JFactory::getUser();
|
|
$expire = time()+86400;
|
|
|
|
$db->setQuery('SELECT * FROM `panorama`.`user` WHERE serial='.$credentials['serial'].';');
|
|
$res = $db->loadObjectList();
|
|
|
|
$tomb=array(
|
|
'serial'=>$db->quote($credentials['serial']),
|
|
'nUserID'=>$db->quote($logged_user->nUserID),
|
|
'strName'=>$db->quote($logged_user->name),
|
|
'expire'=>$db->quote(date("Y-m-d H:i:s", $expire)),
|
|
);
|
|
|
|
if (empty($res)) // ha még egyáltalán nincs benne a széria szám
|
|
{
|
|
$query=$db->getQuery(true);
|
|
$query
|
|
->insert("`panorama`.`user`")
|
|
->columns($db->quoteName(array_keys($tomb)))
|
|
->values(implode(',', $tomb));
|
|
$db->setQuery($query);
|
|
$db->execute();
|
|
$result=$db->insertid();
|
|
}
|
|
else if ((int)$res[0]->nUserID==0) // ha facebook-al már be van jelentkezve
|
|
{
|
|
foreach ($tomb as $k=>$v) $values[]=$db->quoteName($k)."=".$v;
|
|
|
|
$query=$db->getQuery(true);
|
|
$query
|
|
->update("`panorama`.`user`")
|
|
->set($values)
|
|
->where(array('`id`='.$res[0]->id));
|
|
$db->setQuery($query);
|
|
$result=$db->execute();
|
|
}
|
|
|
|
setcookie("serial",$credentials['serial'],$expire,"/",".archlinexp.com");
|
|
//print_r($_COOKIE); die();
|
|
$app->redirect('http://panorama.archlinexp.com/auth/'.$credentials['serial']); //redirect logged in user
|
|
}
|
|
else
|
|
{
|
|
$app->redirect('http://panorama.archlinexp.com/auth/'.$credentials['serial'].'/invalid'); //redirect logged in user
|
|
}
|
|
}
|
|
else
|
|
{
|
|
die('Cound not find user in the database'); // Invalid user - Primitive error handling
|
|
}
|
|
?>
|