Commit 315ac467 authored by Dainis Abols's avatar Dainis Abols
Browse files

Minor fixes

parent e0a112c6
......@@ -43,7 +43,7 @@ class Groups extends Model
*/
public function getUsername(): string
{
return $this->username->value;
return $this->username->toString();
}
/**
......@@ -53,7 +53,7 @@ class Groups extends Model
*/
public function getType(): string
{
return $this->type->value;
return $this->type->toString();
}
/**
......@@ -85,10 +85,10 @@ class Groups extends Model
$arrGroups = [];
// Read and load groups
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->value);
$queryBuilder->select('uid', 'title')->from($this->table->value)->where('deleted = 0 AND hidden = 0');
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->toString());
$queryBuilder->select('uid', 'title')->from($this->table->toString())->where('deleted = 0 AND hidden = 0');
$result = $queryBuilder->execute();
foreach ($result->fetchAllAssociative() as $row) {
foreach ($result->fetchAssociative() as $row) {
echo '<pre>';
print_r($row);
//die;
......@@ -128,10 +128,10 @@ class Groups extends Model
foreach ($affiliation as $title) {
// Fetch existing
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->value);
$queryBuilder->select('uid', 'title', 'tx_luauth_synced_group')->from($this->table->value)
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->toString());
$queryBuilder->select('uid', 'title', 'tx_luauth_synced_group')->from($this->table->toString())
->where("deleted = 0 AND pid = " . $this->conf['extraStoragePid'] . " AND title = '$title'");
$row = $queryBuilder->execute()->fetchAllAssociative();
$row = $queryBuilder->execute()->fetchAssociative();
// Check if any found
if ($row) {
......@@ -139,8 +139,8 @@ class Groups extends Model
// Update synced status if not set yet
if (!$row['tx_luauth_synced_group']) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->value);
$queryBuilder->update($this->table->value)
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->toString());
$queryBuilder->update($this->table->toString())
->where('uid', $row['uid'])
->set('tx_luauth_synced_group', 1)
->execute();
......@@ -153,8 +153,8 @@ class Groups extends Model
];
// Insert new one if none found
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->value);
$feGroups[] = $queryBuilder->insert($this->table->value)->values($group)->execute();
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->toString());
$feGroups[] = $queryBuilder->insert($this->table->toString())->values($group)->execute();
}
}
}
......@@ -173,9 +173,9 @@ class Groups extends Model
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('fe_users');
$queryBuilder->select('usergroup')
->from('fe_users')
->where("deleted = 0 AND disable = 0 AND pid = " . $this->conf['extraStoragePid'] . " AND username = '{$this->username->value}'");
->where("deleted = 0 AND disable = 0 AND pid = " . $this->conf['extraStoragePid'] . " AND username = '{$this->username->toString()}'");
$row = $queryBuilder->execute()->fetchAllAssociative();
$row = $queryBuilder->execute()->fetchAssociative();
if ($row) {
$currentGroups = $row['usergroup'];
}
......@@ -195,14 +195,14 @@ class Groups extends Model
// Fill in user gourps
$feGroups = [];
foreach ($result->fetchAllAssociative() as $row) {
foreach ($result->fetchAssociative() as $row) {
$feGroups[] = $row['uid'];
}
// Select groups without sync mention
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('usergroup');
$queryBuilder->select('usergroup')->from('fe_users')->where("username = '{$this->username->value}'");
$row = $queryBuilder->execute()->fetchAllAssociative();
$queryBuilder->select('usergroup')->from('fe_users')->where("username = '{$this->username->toString()}'");
$row = $queryBuilder->execute()->fetchAssociative();
if ($row['usergroup']) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('fe_users');
......@@ -210,7 +210,7 @@ class Groups extends Model
->where("uid IN ({$row['usergroup']}) AND (tx_luauth_synced_group IS NULL OR tx_luauth_synced_group <> 1)");
$result = $queryBuilder->execute();
foreach ($result->fetchAllAssociative() as $row2) {
foreach ($result->fetchAssociative() as $row2) {
$feGroups[] = $row2['uid'];
}
}
......
......@@ -8,6 +8,7 @@ use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
......@@ -69,6 +70,9 @@ abstract class Model
*/
public function __construct(string $type)
{
// Load logger
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
// Set config value
try {
$this->conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('lu_auth');
......
......@@ -6,6 +6,7 @@ use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
......@@ -73,6 +74,9 @@ class Server
*/
public function __construct()
{
// Load logger
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
// Set config value
try {
$this->conf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('lu_auth');
......@@ -81,9 +85,9 @@ class Server
}
// Set server variables
$this->remoteIdentityProvider = $_SERVER[$this->conf['remoteIdentityProvider']];
$this->remoteSessionId = $_SERVER[$this->conf['remoteSessionId']];
$this->remoteUser = $_SERVER[$this->conf['remoteUser']];
$this->remoteIdentityProvider = $_SERVER[$this->conf['remoteIdentityProvider']] ?: "";
$this->remoteSessionId = $_SERVER[$this->conf['remoteSessionId']] ?: "";
$this->remoteUser = $_SERVER[$this->conf['remoteUser']] ?: "";
}
/**
......
......@@ -41,8 +41,8 @@ class Sessions extends Model
public function destroy()
{
// Delete user session
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->value);
$queryBuilder->delete($this->table->value)->where(
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->toString());
$queryBuilder->delete($this->table->toString())->where(
$queryBuilder->expr()->eq('ses_id', $queryBuilder->createNamedParameter($_COOKIE['fe_typo_user']))
);
$queryBuilder->execute();
......
......@@ -3,10 +3,7 @@
namespace Lu\LuAuth\Models;
use Lu\LuApi\Generators\Randomizer;
use Lu\LuApi\Types\RequestType;
use Lu\LuApi\Types\Table;
use Lu\LuApi\Types\Username;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -37,11 +34,23 @@ class Users extends Model
$this->username = new Username($username);
}
public function __construct(string $type)
{
parent::__construct($type);
// Set used group
if ($type === 'fe') {
$this->setTable('fe_users');
} else {
$this->setTable('be_users');
}
}
/**
* Retrieve valid username
*
* @param Username $username
*
* @param string|null $options
* @return array
*/
public function getUserData(Username $username, string $options = NULL): array
......@@ -50,10 +59,10 @@ class Users extends Model
$this->username = $username;
// Request user data from DB
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->value);
$queryBuilder->select('*')->from($this->table->value)->where('disable = 0 AND deleted = 0')
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->toString());
$queryBuilder->select('*')->from($this->table->toString())->where('disable = 0 AND deleted = 0')
->andWhere($queryBuilder->expr()->eq('username', $queryBuilder->createNamedParameter($this->username)));
$user = $queryBuilder->execute()->fetchAllAssociative();
$user = $queryBuilder->execute()->fetchAssociative();
// Check if options
if (empty($user) && $options == 'activate') {
......@@ -81,8 +90,8 @@ class Users extends Model
}
// Update user data in DB
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->value);
$queryBuilder->update($this->table->value)
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->toString());
$queryBuilder->update($this->table->toString())
->where($queryBuilder->expr()->eq('username', $queryBuilder->createNamedParameter($this->username)))
->set('disable', '0')
->set('deleted', '0');
......@@ -101,7 +110,7 @@ class Users extends Model
public function updateUser($user)
{
// Pre-set used models
$GroupsModel = new Groups($this->type->value);
$GroupsModel = new Groups($this->type->toString());
// Log event here
$this->logger->info("Importing user `%s`", $user['username']);
......@@ -122,9 +131,9 @@ class Users extends Model
];
// Update database
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->value);
$queryBuilder->update($this->table->value);
$queryBuilder->where($queryBuilder->expr()->eq('username', $queryBuilder->createNamedParameter($this->username->value)));
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->toString());
$queryBuilder->update($this->table->toString());
$queryBuilder->where($queryBuilder->expr()->eq('username', $queryBuilder->createNamedParameter($this->username->toString())));
// Set user fields. There's got to be a better way >.<
foreach ($user as $key => $value) {
......@@ -148,7 +157,7 @@ class Users extends Model
{
// Pre-set used models
$ApiRand = new Randomizer();
$GroupsModel = new Groups($this->type->value);
$GroupsModel = new Groups($this->type->toString());
// Log event
$this->logger->info("Importing user `%s`", $user['username']);
......@@ -183,8 +192,8 @@ class Users extends Model
}
// Save to database
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->value);
$queryBuilder->insert($this->table->value)->values($user)->execute();
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table->toString());
$queryBuilder->insert($this->table->toString())->values($user)->execute();
// Request new user and return
return $this->getUserData($user['username']);
......
......@@ -89,6 +89,7 @@ class LUBEAuthService extends AbstractAuthenticationService
'authenticated' => false,
];
// Check if login request
$server = new Server();
if ($this->loginData['status'] == 'login' && !$this->username->empty()) {
......@@ -96,10 +97,8 @@ class LUBEAuthService extends AbstractAuthenticationService
$ldap = new LDAP($server->conf['ldapServer'], $server->conf['ldapDC']);
// Bind and get user data
$ldapres = $ldap->authorize($this->username->value, $this->password);
// Check if data received
if ($ldapres) {
$ldapuser = $ldap->authorize($this->username->toString(), $this->password);// Check if data received
if ($ldapuser) {
// Fetch user data
$UserModel = new Users(RequestType::BE);
$user = $UserModel->getUserData($this->username);
......@@ -125,9 +124,6 @@ class LUBEAuthService extends AbstractAuthenticationService
*/
public function authUser(array $user): int
{
// Pre-set used models
$LuisLib = new LuisLibrary();
// Sets initial to 100
$OK = 100;
......@@ -173,6 +169,7 @@ class LUBEAuthService extends AbstractAuthenticationService
// Sync user image, if authenticated
if ($OK == 200) {
$LuisLib = new LuisLibrary();
$LuisLib->syncUserImage($this->username);
}
......
......@@ -156,7 +156,7 @@ class LUFEAuthService extends AbstractAuthenticationService
$this->logger->info(sprintf("Login-attempt from %s (%s), username '%s', password not accepted!",
$this->info['REMOTE_ADDR'],
$this->info['REMOTE_HOST'],
$this->username->value
$this->username->toString()
));
}
}
......
{
"name": "luitd/lu-auth",
"version": "5.0.0",
"version": "5.0.1",
"description": "TYPO3 Authentication for University of Latvia",
"type": "typo3-cms-extension",
"keywords": [
......
......@@ -14,7 +14,7 @@ $EM_CONF[$_EXTKEY] = [
'title' => 'LU Authentication',
'description' => 'TYPO3 Authentication for University of Latvia',
'category' => 'misc',
'version' => '5.0.0',
'version' => 'v5.0.1',
'dependencies' => 'typo3,lu_api',
'state' => 'stable',
'clearCacheOnLoad' => 1,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment