User/Auth

* import user access from external auth source if available
This commit is contained in:
Sarjuuk
2017-08-30 17:08:33 +02:00
parent 858e5a0492
commit 889f14a64f
2 changed files with 18 additions and 8 deletions

View File

@@ -4,7 +4,7 @@ if (!defined('AOWOW_REVISION'))
die('illegal access'); die('illegal access');
function extAuth($user, $pass, &$userId = 0) function extAuth($user, $pass, &$userId = 0, &$userGroup = -1)
{ {
/* /*
insert some auth mechanism here insert some auth mechanism here

View File

@@ -293,11 +293,11 @@ class User
return AUTH_INTERNAL_ERR; return AUTH_INTERNAL_ERR;
require 'config/extAuth.php'; require 'config/extAuth.php';
$result = extAuth($name, $pass, $extId); $result = extAuth($name, $pass, $extId, $extGroup);
if ($result == AUTH_OK && $extId) if ($result == AUTH_OK && $extId)
{ {
if ($_ = self::checkOrCreateInDB($extId, $name)) if ($_ = self::checkOrCreateInDB($extId, $name, $extGroup))
$user = $_; $user = $_;
else else
return AUTH_INTERNAL_ERR; return AUTH_INTERNAL_ERR;
@@ -320,18 +320,28 @@ class User
} }
// create a linked account for our settings if nessecary // create a linked account for our settings if nessecary
private static function checkOrCreateInDB($extId, $name) private static function checkOrCreateInDB($extId, $name, $userGroup = -1)
{ {
if ($_ = DB::Aowow()->selectCell('SELECT id FROM ?_account WHERE extId = ?d', $extId)) if (!intVal($extId))
return $_; return 0;
$newId = DB::Aowow()->query('INSERT IGNORE INTO ?_account (extId, user, displayName, joinDate, prevIP, prevLogin, locale, status) VALUES (?d, ?, ?, UNIX_TIMESTAMP(), ?, UNIX_TIMESTAMP(), ?d, ?d)', $userGroup = intVal($userGroup);
if ($_ = DB::Aowow()->selectCell('SELECT id FROM ?_account WHERE extId = ?d', $extId))
{
if ($userGroup >= U_GROUP_NONE)
DB::Aowow()->query('UPDATE ?_account SET userGroups = ?d WHERE extId = ?d', $userGroup, $extId);
return $_;
}
$newId = DB::Aowow()->query('INSERT IGNORE INTO ?_account (extId, user, displayName, joinDate, prevIP, prevLogin, locale, status, userGroups) VALUES (?d, ?, ?, UNIX_TIMESTAMP(), ?, UNIX_TIMESTAMP(), ?d, ?d, ?d)',
$extId, $extId,
$name, $name,
Util::ucFirst($name), Util::ucFirst($name),
isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '', isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '',
User::$localeId, User::$localeId,
ACC_STATUS_OK ACC_STATUS_OK,
$userGroup >= U_GROUP_NONE ? $userGroup : U_GROUP_NONE
); );
if ($newId) if ($newId)