diff --git a/config/extAuth.php.in b/config/extAuth.php.in index 5be443b9..8d951569 100644 --- a/config/extAuth.php.in +++ b/config/extAuth.php.in @@ -4,7 +4,7 @@ if (!defined('AOWOW_REVISION')) die('illegal access'); - function extAuth($user, $pass, &$userId = 0) + function extAuth($user, $pass, &$userId = 0, &$userGroup = -1) { /* insert some auth mechanism here diff --git a/includes/user.class.php b/includes/user.class.php index 48455d4c..1d4f6f18 100644 --- a/includes/user.class.php +++ b/includes/user.class.php @@ -293,11 +293,11 @@ class User return AUTH_INTERNAL_ERR; require 'config/extAuth.php'; - $result = extAuth($name, $pass, $extId); + $result = extAuth($name, $pass, $extId, $extGroup); if ($result == AUTH_OK && $extId) { - if ($_ = self::checkOrCreateInDB($extId, $name)) + if ($_ = self::checkOrCreateInDB($extId, $name, $extGroup)) $user = $_; else return AUTH_INTERNAL_ERR; @@ -320,18 +320,28 @@ class User } // 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)) - return $_; + if (!intVal($extId)) + 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, $name, Util::ucFirst($name), isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '', User::$localeId, - ACC_STATUS_OK + ACC_STATUS_OK, + $userGroup >= U_GROUP_NONE ? $userGroup : U_GROUP_NONE ); if ($newId)