diff --git a/includes/ajaxHandler/admin.class.php b/includes/ajaxHandler/admin.class.php index 7992ead2..78af780d 100644 --- a/includes/ajaxHandler/admin.class.php +++ b/includes/ajaxHandler/admin.class.php @@ -123,7 +123,7 @@ class AjaxAdmin extends AjaxHandler if ($this->_get['type'] && $this->_get['type'] && $this->_get['typeid'] && $this->_get['typeid']) $res = CommunityContent::getScreenshotsForManager($this->_get['type'], $this->_get['typeid']); else if ($this->_get['user']) - if ($uId = DB::Aowow()->selectCell('SELECT id FROM ?_account WHERE displayName = ?', $this->_get['user'])) + if ($uId = DB::Aowow()->selectCell('SELECT `id` FROM ?_account WHERE LOWER(`username`) = LOWER(?)', $this->_get['user'])) $res = CommunityContent::getScreenshotsForManager(0, 0, $uId); return 'ssm_screenshotData = '.Util::toJSON($res); diff --git a/includes/ajaxHandler/edit.class.php b/includes/ajaxHandler/edit.class.php index fc5c753d..1275b7c4 100644 --- a/includes/ajaxHandler/edit.class.php +++ b/includes/ajaxHandler/edit.class.php @@ -41,7 +41,7 @@ class AjaxEdit extends AjaxHandler $targetPath = 'static/uploads/guide/images/'; $tmpPath = 'static/uploads/temp/'; - $tmpFile = User::$displayName.'-'.Type::GUIDE.'-0-'.Util::createHash(16); + $tmpFile = User::$username.'-'.Type::GUIDE.'-0-'.Util::createHash(16); $uploader = new \qqFileUploader(['jpg', 'jpeg', 'png'], 10 * 1024 * 1024); $result = $uploader->handleUpload($tmpPath, $tmpFile, true); diff --git a/includes/ajaxHandler/profile.class.php b/includes/ajaxHandler/profile.class.php index 382b37e2..86e668a9 100644 --- a/includes/ajaxHandler/profile.class.php +++ b/includes/ajaxHandler/profile.class.php @@ -112,7 +112,7 @@ class AjaxProfile extends AjaxHandler $uid = User::$id; if ($this->_get['user'] && User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU)) { - if (!($uid = DB::Aowow()->selectCell('SELECT id FROM ?_account WHERE user = ?', $this->_get['user']))) + if (!($uid = DB::Aowow()->selectCell('SELECT `id` FROM ?_account WHERE LOWER(`username`) = LOWER(?)', $this->_get['user']))) { trigger_error('AjaxProfile::handleLink - user "'.$this->_get['user'].'" does not exist', E_USER_ERROR); return; @@ -120,12 +120,12 @@ class AjaxProfile extends AjaxHandler } if ($this->undo) - DB::Aowow()->query('DELETE FROM ?_account_profiles WHERE accountId = ?d AND profileId IN (?a)', $uid, $this->_get['id']); + DB::Aowow()->query('DELETE FROM ?_account_profiles WHERE `accountId` = ?d AND `profileId` IN (?a)', $uid, $this->_get['id']); else { foreach ($this->_get['id'] as $prId) // only link characters, not custom profiles { - if ($prId = DB::Aowow()->selectCell('SELECT id FROM ?_profiler_profiles WHERE id = ?d AND realm IS NOT NULL', $prId)) + if ($prId = DB::Aowow()->selectCell('SELECT `id` FROM ?_profiler_profiles WHERE `id` = ?d AND `realm` IS NOT NULL', $prId)) DB::Aowow()->query('INSERT IGNORE INTO ?_account_profiles VALUES (?d, ?d, 0)', $uid, $prId); else { @@ -152,7 +152,7 @@ class AjaxProfile extends AjaxHandler $uid = User::$id; if ($this->_get['user'] && User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU)) { - if (!($uid = DB::Aowow()->selectCell('SELECT id FROM ?_account WHERE user = ?', $this->_get['user']))) + if (!($uid = DB::Aowow()->selectCell('SELECT `id` FROM ?_account WHERE LOWER(`username`) = LOWER(?)', $this->_get['user']))) { trigger_error('AjaxProfile::handlePin - user "'.$this->_get['user'].'" does not exist', E_USER_ERROR); return; @@ -160,10 +160,10 @@ class AjaxProfile extends AjaxHandler } // since only one character can be pinned at a time we can reset everything - DB::Aowow()->query('UPDATE ?_account_profiles SET extraFlags = extraFlags & ?d WHERE accountId = ?d', ~PROFILER_CU_PINNED, $uid); + DB::Aowow()->query('UPDATE ?_account_profiles SET `extraFlags` = `extraFlags` & ?d WHERE `accountId` = ?d', ~PROFILER_CU_PINNED, $uid); // and set a single char if necessary if (!$this->undo) - DB::Aowow()->query('UPDATE ?_account_profiles SET extraFlags = extraFlags | ?d WHERE profileId = ?d AND accountId = ?d', PROFILER_CU_PINNED, $this->_get['id'][0], $uid); + DB::Aowow()->query('UPDATE ?_account_profiles SET `extraFlags` = `extraFlags` | ?d WHERE `profileId` = ?d AND `accountId` = ?d', PROFILER_CU_PINNED, $this->_get['id'][0], $uid); } /* params @@ -182,7 +182,7 @@ class AjaxProfile extends AjaxHandler $uid = User::$id; if ($this->_get['user'] && User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU)) { - if (!($uid = DB::Aowow()->selectCell('SELECT id FROM ?_account WHERE user = ?', $this->_get['user']))) + if (!($uid = DB::Aowow()->selectCell('SELECT `id` FROM ?_account WHERE LOWER(`username`) = LOWER(?)', $this->_get['user']))) { trigger_error('AjaxProfile::handlePrivacy - user "'.$this->_get['user'].'" does not exist', E_USER_ERROR); return; @@ -191,13 +191,13 @@ class AjaxProfile extends AjaxHandler if ($this->undo) { - DB::Aowow()->query('UPDATE ?_account_profiles SET extraFlags = extraFlags & ?d WHERE profileId IN (?a) AND accountId = ?d', ~PROFILER_CU_PUBLISHED, $this->_get['id'], $uid); - DB::Aowow()->query('UPDATE ?_profiler_profiles SET cuFlags = cuFlags & ?d WHERE id IN (?a) AND user = ?d', ~PROFILER_CU_PUBLISHED, $this->_get['id'], $uid); + DB::Aowow()->query('UPDATE ?_account_profiles SET `extraFlags` = `extraFlags` & ?d WHERE `profileId` IN (?a) AND `accountId` = ?d', ~PROFILER_CU_PUBLISHED, $this->_get['id'], $uid); + DB::Aowow()->query('UPDATE ?_profiler_profiles SET `cuFlags` = `cuFlags` & ?d WHERE `id` IN (?a) AND `user` = ?d', ~PROFILER_CU_PUBLISHED, $this->_get['id'], $uid); } else { - DB::Aowow()->query('UPDATE ?_account_profiles SET extraFlags = extraFlags | ?d WHERE profileId IN (?a) AND accountId = ?d', PROFILER_CU_PUBLISHED, $this->_get['id'], $uid); - DB::Aowow()->query('UPDATE ?_profiler_profiles SET cuFlags = cuFlags | ?d WHERE id IN (?a) AND user = ?d', PROFILER_CU_PUBLISHED, $this->_get['id'], $uid); + DB::Aowow()->query('UPDATE ?_account_profiles SET `extraFlags` = `extraFlags` | ?d WHERE `profileId` IN (?a) AND `accountId` = ?d', PROFILER_CU_PUBLISHED, $this->_get['id'], $uid); + DB::Aowow()->query('UPDATE ?_profiler_profiles SET `cuFlags` = `cuFlags` | ?d WHERE `id` IN (?a) AND `user` = ?d', PROFILER_CU_PUBLISHED, $this->_get['id'], $uid); } } @@ -323,7 +323,7 @@ class AjaxProfile extends AjaxHandler // todo (med): detail check this post-data $cuProfile = array( 'user' => User::$id, - // 'userName' => User::$displayName, + // 'userName' => User::$username, 'name' => $this->_post['name'], 'level' => $this->_post['level'], 'class' => $this->_post['class'], @@ -557,7 +557,7 @@ class AjaxProfile extends AjaxHandler $profile['sourcename'] = $pBase['sourceName']; $profile['description'] = $pBase['description']; $profile['user'] = $pBase['user']; - $profile['username'] = DB::Aowow()->selectCell('SELECT displayName FROM ?_account WHERE id = ?d', $pBase['user']); + $profile['username'] = DB::Aowow()->selectCell('SELECT `username` FROM ?_account WHERE `id` = ?d', $pBase['user']); } // custom profiles inherit this when copied from real char :( @@ -572,7 +572,7 @@ class AjaxProfile extends AjaxHandler if ($_ = DB::Aowow()->selectCol('SELECT accountId FROM ?_account_profiles WHERE profileId = ?d', $pBase['id'])) $profile['bookmarks'] = $_; - // arena teams - [size(2|3|5) => DisplayName]; DisplayName gets urlized to use as link + // arena teams - [size(2|3|5) => name]; name gets urlized to use as link if ($at = DB::Aowow()->selectCol('SELECT type AS ARRAY_KEY, name FROM ?_profiler_arena_team at JOIN ?_profiler_arena_team_member atm ON atm.arenaTeamId = at.id WHERE atm.profileId = ?d', $pBase['id'])) $profile['arenateams'] = $at; diff --git a/includes/components/communitycontent.class.php b/includes/components/communitycontent.class.php index 3cd88627..8655d4f9 100644 --- a/includes/components/communitycontent.class.php +++ b/includes/components/communitycontent.class.php @@ -31,13 +31,13 @@ class CommunityContent private static string $coQuery = 'SELECT c.*, - a1.`displayName` AS `user`, - a2.`displayName` AS `editUser`, - a3.`displayName` AS `deleteUser`, - a4.`displayName` AS `responseUser`, - IFNULL(SUM(ur.`value`), 0) AS `rating`, - SUM(IF(ur.`userId` > 0 AND ur.`userId` = ?d, ur.`value`, 0)) AS `userRating`, - IF(r.`id` IS NULL, 0, 1) AS `userReported` + a1.`username` AS "user", + a2.`username` AS "editUser", + a3.`username` AS "deleteUser", + a4.`username` AS "responseUser", + IFNULL(SUM(ur.`value`), 0) AS "rating", + SUM(IF(ur.`userId` > 0 AND ur.`userId` = ?d, ur.`value`, 0)) AS "userRating", + IF(r.`id` IS NULL, 0, 1) AS "userReported" FROM ?_comments c JOIN ?_account a1 ON c.`userId` = a1.`id` LEFT JOIN ?_account a2 ON c.`editUserId` = a2.`id` @@ -51,7 +51,7 @@ class CommunityContent ORDER BY c.`date` ASC'; private static string $ssQuery = - 'SELECT s.`id` AS ARRAY_KEY, s.`id`, a.`displayName` AS `user`, s.`date`, s.`width`, s.`height`, s.`caption`, IF(s.`status` & ?d, 1, 0) AS "sticky", s.`type`, s.`typeId` + 'SELECT s.`id` AS ARRAY_KEY, s.`id`, a.`username` AS "user", s.`date`, s.`width`, s.`height`, s.`caption`, IF(s.`status` & ?d, 1, 0) AS "sticky", s.`type`, s.`typeId` FROM ?_screenshots s LEFT JOIN ?_account a ON s.`userIdOwner` = a.`id` WHERE { s.`userIdOwner` = ?d AND }{ s.`type` = ? AND }{ s.`typeId` = ? AND } s.`status` & ?d AND (s.`status` & ?d) = 0 @@ -59,7 +59,7 @@ class CommunityContent { LIMIT ?d }'; private static string $viQuery = - 'SELECT v.`id` AS ARRAY_KEY, v.`id`, a.`displayName` AS `user`, v.`date`, v.`videoId`, v.`caption`, IF(v.`status` & ?d, 1, 0) AS "sticky", v.`type`, v.`typeId` + 'SELECT v.`id` AS ARRAY_KEY, v.`id`, a.`username` AS "user", v.`date`, v.`videoId`, v.`caption`, IF(v.`status` & ?d, 1, 0) AS "sticky", v.`type`, v.`typeId` FROM ?_videos v LEFT JOIN ?_account a ON v.`userIdOwner` = a.`id` WHERE { v.`userIdOwner` = ?d AND }{ v.`type` = ? AND }{ v.`typeId` = ? AND } v.`status` & ?d AND (v.`status` & ?d) = 0 @@ -68,14 +68,14 @@ class CommunityContent private static string $previewQuery = 'SELECT c.`id`, - c.`body` AS `preview`, + c.`body` AS "preview", c.`date`, - c.`replyTo` AS `commentid`, - IF(c.`flags` & ?d, 1, 0) AS `deleted`, - IF(c.`type` <> 0, c.`type`, c2.`type`) AS `type`, - IF(c.`typeId` <> 0, c.`typeId`, c2.`typeId`) AS `typeId`, - IFNULL(SUM(ur.`value`), 0) AS `rating`, - a.`displayName` AS `user` + c.`replyTo` AS "commentid", + IF(c.`flags` & ?d, 1, 0) AS "deleted", + IF(c.`type` <> 0, c.`type`, c2.`type`) AS "type", + IF(c.`typeId` <> 0, c.`typeId`, c2.`typeId`) AS "typeId", + IFNULL(SUM(ur.`value`), 0) AS "rating", + a.`username` AS "user" FROM ?_comments c JOIN ?_account a ON c.`userId` = a.`id` LEFT JOIN ?_user_ratings ur ON ur.`entry` = c.`id` AND ur.`userId` <> 0 AND ur.`type` = 1 @@ -228,14 +228,14 @@ class CommunityContent public static function getScreenshotsForManager($type, $typeId, $userId = 0) { - $screenshots = DB::Aowow()->select(' - SELECT s.id, a.displayName AS user, s.date, s.width, s.height, s.type, s.typeId, s.caption, s.status, s.status AS "flags" + $screenshots = DB::Aowow()->select( + 'SELECT s.`id`, a.`username` AS "user", s.`date`, s.`width`, s.`height`, s.`type`, s.`typeId`, s.`caption`, s.`status`, s.`status` AS "flags" FROM ?_screenshots s - LEFT JOIN ?_account a ON s.userIdOwner = a.id + LEFT JOIN ?_account a ON s.`userIdOwner` = a.`id` WHERE - { s.type = ?d} - { AND s.typeId = ?d} - { s.userIdOwner = ?d} + { s.`type` = ?d} + { AND s.`typeId` = ?d} + { s.`userIdOwner` = ?d} LIMIT 100', $userId ? DBSIMPLE_SKIP : $type, $userId ? DBSIMPLE_SKIP : $typeId, @@ -300,11 +300,11 @@ class CommunityContent { // i GUESS .. ss_getALL ? everything : pending $nFound = 0; - $pages = DB::Aowow()->select(' - SELECT s.`type`, s.`typeId`, count(1) AS "count", MIN(s.`date`) AS "date" - FROM ?_screenshots s - {WHERE (s.status & ?d) = 0} - GROUP BY s.`type`, s.`typeId`', + $pages = DB::Aowow()->select( + 'SELECT s.`type`, s.`typeId`, COUNT(1) AS "count", MIN(s.`date`) AS "date" + FROM ?_screenshots s + { WHERE (s.`status` & ?d) = 0 } + GROUP BY s.`type`, s.`typeId`', $all ? DBSIMPLE_SKIP : CC_FLAG_APPROVED | CC_FLAG_DELETED ); diff --git a/includes/types/guide.class.php b/includes/types/guide.class.php index dc980582..4fc7942a 100644 --- a/includes/types/guide.class.php +++ b/includes/types/guide.class.php @@ -29,8 +29,8 @@ class GuideList extends BaseType protected $queryBase = 'SELECT g.*, g.id AS ARRAY_KEY FROM ?_guides g'; protected $queryOpts = array( 'g' => [['a', 'c'], 'g' => 'g.`id`'], - 'a' => ['j' => ['?_account a ON a.id = g.userId', true], 's' => ', IFNULL(a.displayName, "") AS author'], - 'c' => ['j' => ['?_comments c ON c.`type` = '.Type::GUIDE.' AND c.`typeId` = g.`id` AND (c.`flags` & '.CC_FLAG_DELETED.') = 0', true], 's' => ', COUNT(c.`id`) AS `comments`'] + 'a' => ['j' => ['?_account a ON a.`id` = g.`userId`', true], 's' => ', IFNULL(a.`username`, "") AS "author"'], + 'c' => ['j' => ['?_comments c ON c.`type` = '.Type::GUIDE.' AND c.`typeId` = g.`id` AND (c.`flags` & '.CC_FLAG_DELETED.') = 0', true], 's' => ', COUNT(c.`id`) AS "comments"'] ); public function __construct(array $conditions = [], array $miscData = []) diff --git a/includes/types/user.class.php b/includes/types/user.class.php index f547ef8d..0373c5bb 100644 --- a/includes/types/user.class.php +++ b/includes/types/user.class.php @@ -18,7 +18,7 @@ class UserList extends BaseType protected $queryBase = 'SELECT *, a.id AS ARRAY_KEY FROM ?_account a'; protected $queryOpts = array( 'a' => [['r']], - 'r' => ['j' => ['?_account_reputation r ON r.userId = a.id', true], 's' => ', IFNULL(SUM(r.amount), 0) AS reputation', 'g' => 'a.id'] + 'r' => ['j' => ['?_account_reputation r ON r.`userId` = a.`id`', true], 's' => ', IFNULL(SUM(r.`amount`), 0) AS "reputation"', 'g' => 'a.`id`'] ); public function getListviewData() { } @@ -29,7 +29,7 @@ class UserList extends BaseType foreach ($this->iterate() as $__) { - $data[$this->curTpl['displayName']] = array( + $data[$this->curTpl['username']] = array( 'border' => 0, // border around avatar (rarityColors) 'roles' => $this->curTpl['userGroups'], 'joined' => date(Util::$dateFormatInternal, $this->curTpl['joinDate']), @@ -40,14 +40,14 @@ class UserList extends BaseType 'reputation' => $this->curTpl['reputation'] ); - // custom titles (only ssen on user page..?) + // custom titles (only seen on user page..?) if ($_ = $this->curTpl['title']) - $data[$this->curTpl['displayName']]['title'] = $_; + $data[$this->curTpl['username']]['title'] = $_; if ($_ = $this->curTpl['avatar']) { - $data[$this->curTpl['displayName']]['avatar'] = is_numeric($_) ? 2 : 1; - $data[$this->curTpl['displayName']]['avatarmore'] = $_; + $data[$this->curTpl['username']]['avatar'] = is_numeric($_) ? 2 : 1; + $data[$this->curTpl['username']]['avatarmore'] = $_; } // more optional data diff --git a/includes/user.class.php b/includes/user.class.php index 739c8a9c..48a8c14b 100644 --- a/includes/user.class.php +++ b/includes/user.class.php @@ -8,23 +8,22 @@ if (!defined('AOWOW_REVISION')) class User { - public static int $id = 0; - public static string $displayName = ''; - public static int $banStatus = 0x0; // see ACC_BAN_* defines - public static int $groups = 0x0; - public static int $perms = 0; - public static string $avatar = 'inv_misc_questionmark'; - public static int $dailyVotes = 0; - public static $ip = null; + public static int $id = 0; + public static string $username = ''; + public static int $banStatus = 0x0; // see ACC_BAN_* defines + public static int $groups = 0x0; + public static int $perms = 0; + public static ?string $email = null; + public static int $dailyVotes = 0; + public static ?string $ip = null; + public static Locale $preferedLoc; - private static int $reputation = 0; - private static string $dataKey = ''; - private static bool $expires = false; - private static string $passHash = ''; - private static int $excludeGroups = 1; - - public static Locale $preferedLoc; - private static ?LocalProfileList $profiles = null; + private static int $reputation = 0; + private static string $dataKey = ''; + private static bool $expires = false; + private static string $passHash = ''; + private static int $excludeGroups = 1; + private static ?LocalProfileList $profiles = null; public static function init() { @@ -64,7 +63,7 @@ class User return false; $uData = DB::Aowow()->SelectRow( - 'SELECT a.`id`, a.`passHash`, a.`displayName`, a.`locale`, a.`userGroups`, a.`userPerms`, a.`allowExpire`, BIT_OR(ab.`typeMask`) AS "bans", IFNULL(SUM(r.`amount`), 0) AS "reputation", a.`avatar`, a.`dailyVotes`, a.`excludeGroups` + 'SELECT a.`id`, a.`passHash`, a.`username`, a.`locale`, a.`userGroups`, a.`userPerms`, a.`allowExpire`, BIT_OR(ab.`typeMask`) AS "bans", IFNULL(SUM(r.`amount`), 0) AS "reputation", a.`dailyVotes`, a.`excludeGroups` FROM ?_account a LEFT JOIN ?_account_banned ab ON a.`id` = ab.`userId` AND ab.`end` > UNIX_TIMESTAMP() LEFT JOIN ?_account_reputation r ON a.`id` = r.`userId` @@ -87,7 +86,7 @@ class User } self::$id = intVal($uData['id']); - self::$displayName = $uData['displayName']; + self::$username = $uData['username']; self::$passHash = $uData['passHash']; self::$expires = (bool)$uData['allowExpire']; self::$reputation = $uData['reputation']; @@ -103,9 +102,6 @@ class User self::$profiles = (new LocalProfileList($conditions)); - if ($uData['avatar']) - self::$avatar = $uData['avatar']; - // stuff, that updates on a daily basis goes here (if you keep you session alive indefinitly, the signin-handler doesn't do very much) // - conscutive visits @@ -190,10 +186,10 @@ class User $_SESSION['locale'] = self::$preferedLoc; // keep locale $_SESSION['dataKey'] = self::$dataKey; // keep dataKey - self::$id = 0; - self::$displayName = ''; - self::$perms = 0; - self::$groups = U_GROUP_NONE; + self::$id = 0; + self::$username = ''; + self::$perms = 0; + self::$groups = U_GROUP_NONE; } @@ -201,16 +197,16 @@ class User /* auth mechanisms */ /*******************/ - public static function authenticate(string $name, string $password) : int + public static function authenticate(string $login, string $password) : int { $userId = 0; $hash = ''; $result = match (Cfg::get('ACC_AUTH_MODE')) { - AUTH_MODE_SELF => self::authSelf($name, $password, $userId, $hash), - AUTH_MODE_REALM => self::authRealm($name, $password, $userId, $hash), - AUTH_MODE_EXTERNAL => self::authExtern($name, $password, $userId, $hash), + AUTH_MODE_SELF => self::authSelf($login, $password, $userId, $hash), + AUTH_MODE_REALM => self::authRealm($login, $password, $userId, $hash), + AUTH_MODE_EXTERNAL => self::authExtern($login, $password, $userId, $hash), default => AUTH_INTERNAL_ERR }; @@ -224,7 +220,7 @@ class User return $result; } - private static function authSelf(string $name, string $password, int &$userId, string &$hash) : int + private static function authSelf(string $nameOrEmail, string $password, int &$userId, string &$hash) : int { if (!self::$ip) return AUTH_INTERNAL_ERR; @@ -239,13 +235,16 @@ class User if ($ipBan && $ipBan['count'] >= Cfg::get('ACC_FAILED_AUTH_COUNT') && $ipBan['active']) return AUTH_IPBANNED; + $email = filter_var($nameOrEmail, FILTER_VALIDATE_EMAIL); + $query = DB::Aowow()->SelectRow( 'SELECT a.`id`, a.`passHash`, BIT_OR(ab.`typeMask`) AS "bans", a.`status` FROM ?_account a LEFT JOIN ?_account_banned ab ON a.`id` = ab.`userId` AND ab.`end` > UNIX_TIMESTAMP() - WHERE a.`user` = ? + WHERE { a.`email` = ? } { a.`login` = ? } GROUP BY a.`id`', - $name + $email ?: DBSIMPLE_SKIP, + !$email ? $nameOrEmail : DBSIMPLE_SKIP ); if (!$query) @@ -290,7 +289,7 @@ class User return AUTH_OK; } - private static function authExtern(string $name, string $password, int &$userId, string &$hash) : int + private static function authExtern(string $nameOrEmail, string $password, int &$userId, string &$hash) : int { if (!file_exists('config/extAuth.php')) { @@ -308,11 +307,15 @@ class User $extGroup = -1; $extId = 0; - $result = \extAuth($name, $password, $extId, $extGroup); + $result = \extAuth($nameOrEmail, $password, $extId, $extGroup); + + // assert we don't have an email passed back from extAuth + if (filter_var($nameOrEmail, FILTER_VALIDATE_EMAIL)) + return AUTH_WRONGUSER; if ($result == AUTH_OK && $extId) { - if ($_ = self::checkOrCreateInDB($extId, $name, $extGroup)) + if ($_ = self::checkOrCreateInDB($extId, $nameOrEmail, $extGroup)) $userId = $_; else return AUTH_INTERNAL_ERR; @@ -331,10 +334,9 @@ class User return $_; } - $newId = DB::Aowow()->query('INSERT IGNORE INTO ?_account (`extId`, `user`, `passHash`, `displayName`, `email`, `joinDate`, `allowExpire`, `prevIP`, `prevLogin`, `locale`, `status`, `userGroups`) VALUES (?d, ?, "", ?, "", UNIX_TIMESTAMP(), 0, ?, UNIX_TIMESTAMP(), ?d, ?d, ?d)', + $newId = DB::Aowow()->query('INSERT IGNORE INTO ?_account (`extId`, `login`, `passHash`, `username`, `email`, `joinDate`, `allowExpire`, `prevIP`, `prevLogin`, `locale`, `status`, `userGroups`) VALUES (?d, "", "", ?, "", UNIX_TIMESTAMP(), 0, ?, UNIX_TIMESTAMP(), ?d, ?d, ?d)', $extId, $name, - Util::ucFirst($name), $_SERVER["REMOTE_ADDR"] ?? '', self::$preferedLoc->value, ACC_STATUS_OK, @@ -555,7 +557,7 @@ class User { $gUser = array( 'id' => self::$id, - 'name' => self::$displayName, + 'name' => self::$username, 'roles' => self::$groups, 'permissions' => self::$perms, 'cookies' => [] @@ -573,11 +575,18 @@ class User $gUser['upvoteRep'] = Cfg::get('REP_REQ_UPVOTE'); $gUser['characters'] = self::getCharacters(); $gUser['excludegroups'] = self::$excludeGroups; - $gUser['settings'] = (new \StdClass); // existence is checked in Profiler.js before g_user.excludegroups is applied; has property premiumborder (NYI) if (Cfg::get('DEBUG') && User::isInGroup(U_GROUP_DEV | U_GROUP_ADMIN | U_GROUP_TESTER)) $gUser['debug'] = true; // csv id-list output option on listviews; todo - set on per user basis + if (self::getPremiumBorder()) + $gUser['settings'] = ['premiumborder' => 1]; + else + $gUser['settings'] = (new \StdClass); // existence is checked in Profiler.js before g_user.excludegroups is applied + + if (self::isPremium()) + $gUser['premium'] = 1; + if ($_ = self::getProfilerExclusions()) $gUser = array_merge($gUser, $_); @@ -716,6 +725,12 @@ class User return $data; } + + // not sure what to set .. user selected? + public static function getPremiumBorder() : bool + { + return self::isInGroup(U_GROUP_PREMIUM); + } } ?> diff --git a/pages/account.php b/pages/account.php index 4d856ef1..a1391810 100644 --- a/pages/account.php +++ b/pages/account.php @@ -142,7 +142,7 @@ class AccountPage extends GenericPage header('Location: '.$this->getNext(true), true, 302); } } - else if ($this->_get['token'] && ($_ = DB::Aowow()->selectCell('SELECT user FROM ?_account WHERE status IN (?a) AND token = ? AND statusTimer > UNIX_TIMESTAMP()', [ACC_STATUS_RECOVER_USER, ACC_STATUS_OK], $this->_get['token']))) + else if ($this->_get['token'] && ($_ = DB::Aowow()->selectCell('SELECT `username` FROM ?_account WHERE `status` IN (?a) AND `token` = ? AND `statusTimer` > UNIX_TIMESTAMP()', [ACC_STATUS_RECOVER_USER, ACC_STATUS_OK], $this->_get['token']))) $this->user = $_; break; @@ -203,8 +203,8 @@ class AccountPage extends GenericPage if (!User::isLoggedIn()) $this->forwardToSignIn('account'); - $user = DB::Aowow()->selectRow('SELECT * FROM ?_account WHERE id = ?d', User::$id); - $bans = DB::Aowow()->select('SELECT ab.*, a.displayName, ab.id AS ARRAY_KEY FROM ?_account_banned ab LEFT JOIN ?_account a ON a.id = ab.staffId WHERE ab.userId = ?d', User::$id); + $user = DB::Aowow()->selectRow('SELECT * FROM ?_account WHERE `id` = ?d', User::$id); + $bans = DB::Aowow()->select('SELECT ab.*, a.`username`, ab.`id` AS ARRAY_KEY FROM ?_account_banned ab LEFT JOIN ?_account a ON a.`id` = ab.`staffId` WHERE ab.`userId` = ?d', User::$id); /***********/ /* Infobox */ @@ -236,7 +236,7 @@ class AccountPage extends GenericPage continue; $this->banned = array( - 'by' => [$b['staffId'], $b['displayName']], + 'by' => [$b['staffId'], $b['username']], 'end' => $b['end'], 'reason' => $b['reason'] ); @@ -365,7 +365,7 @@ Markup.printHtml("description text here", "description-generic", { allow: Markup return Lang::main('intError'); // reset account status, update expiration - DB::Aowow()->query('UPDATE ?_account SET prevIP = IF(curIp = ?, prevIP, curIP), curIP = IF(curIp = ?, curIP, ?), allowExpire = ?d, status = IF(status = ?d, status, 0), statusTimer = IF(status = ?d, statusTimer, 0), token = IF(status = ?d, token, "") WHERE user = ?', + DB::Aowow()->query('UPDATE ?_account SET `prevIP` = IF(`curIp` = ?, `prevIP`, `curIP`), `curIP` = IF(`curIp` = ?, `curIP`, ?), `allowExpire` = ?d, `status` = IF(`status` = ?d, `status`, 0), `statusTimer` = IF(`status` = ?d, `statusTimer`, 0), `token` = IF(`status` = ?d, `token`, "") WHERE LOWER(`username`) = LOWER(?)', User::$ip, User::$ip, User::$ip, $this->_post['remember_me'] != 'yes', ACC_STATUS_NEW, ACC_STATUS_NEW, ACC_STATUS_NEW, @@ -419,23 +419,23 @@ Markup.printHtml("description text here", "description-generic", { allow: Markup return Lang::main('intError'); // limit account creation - $ip = DB::Aowow()->selectRow('SELECT ip, count, unbanDate FROM ?_account_bannedips WHERE type = 1 AND ip = ?', User::$ip); + $ip = DB::Aowow()->selectRow('SELECT `ip`, `count`, `unbanDate` FROM ?_account_bannedips WHERE `type` = 1 AND `ip` = ?', User::$ip); if ($ip && $ip['count'] >= Cfg::get('ACC_FAILED_AUTH_COUNT') && $ip['unbanDate'] >= time()) { - DB::Aowow()->query('UPDATE ?_account_bannedips SET count = count + 1, unbanDate = UNIX_TIMESTAMP() + ?d WHERE ip = ? AND type = 1', Cfg::get('ACC_FAILED_AUTH_BLOCK'), User::$ip); + DB::Aowow()->query('UPDATE ?_account_bannedips SET `count` = `count` + 1, `unbanDate` = UNIX_TIMESTAMP() + ?d WHERE `ip` = ? AND `type` = 1', Cfg::get('ACC_FAILED_AUTH_BLOCK'), User::$ip); return sprintf(Lang::account('signupExceeded'), Util::formatTime(Cfg::get('ACC_FAILED_AUTH_BLOCK') * 1000)); } // username taken - if ($_ = DB::Aowow()->SelectCell('SELECT user FROM ?_account WHERE (user = ? OR email = ?) AND (status <> ?d OR (status = ?d AND statusTimer > UNIX_TIMESTAMP()))', $this->_post['username'], $this->_post['email'], ACC_STATUS_NEW, ACC_STATUS_NEW)) + if ($_ = DB::Aowow()->SelectCell('SELECT `username` FROM ?_account WHERE (`username` = ? OR `email` = ?) AND (`status` <> ?d OR (`status` = ?d AND `statusTimer` > UNIX_TIMESTAMP()))', $this->_post['username'], $this->_post['email'], ACC_STATUS_NEW, ACC_STATUS_NEW)) return $_ == $this->_post['username'] ? Lang::account('nameInUse') : Lang::account('mailInUse'); // create.. $token = Util::createHash(); - $ok = DB::Aowow()->query('REPLACE INTO ?_account (user, passHash, displayName, email, joindate, curIP, allowExpire, locale, userGroups, status, statusTimer, token) VALUES (?, ?, ?, ?, UNIX_TIMESTAMP(), ?, ?d, ?d, ?d, ?d, UNIX_TIMESTAMP() + ?d, ?)', + $ok = DB::Aowow()->query('REPLACE INTO ?_account (`login`, `passHash`, `username`, `email`, `joindate`, `curIP`, `allowExpire`, `locale`, `userGroups`, `status`, `statusTimer`, `token`) VALUES (?, ?, ?, ?, UNIX_TIMESTAMP(), ?, ?d, ?d, ?d, ?d, UNIX_TIMESTAMP() + ?d, ?)', $this->_post['username'], User::hashCrypt($this->_post['password']), - Util::ucFirst($this->_post['username']), + $this->_post['username'], $this->_post['email'], User::$ip, $this->_post['remember_me'] != 'yes', diff --git a/pages/admin.php b/pages/admin.php index 3e665095..e6627efc 100644 --- a/pages/admin.php +++ b/pages/admin.php @@ -224,7 +224,7 @@ class AdminPage extends GenericPage { if (mb_strlen($this->_get['user']) >= 3) { - if ($uId = DB::Aowow()->selectCell('SELECT id FROM ?_account WHERE displayName = ?', ucFirst($this->_get['user']))) + if ($uId = DB::Aowow()->selectCell('SELECT `id` FROM ?_account WHERE LOWER(`username`) = LOWER(?)', $this->_get['user'])) { $ssData = CommunityContent::getScreenshotsForManager(0, 0, $uId); $nMatches = count($ssData); diff --git a/pages/guide.php b/pages/guide.php index f48d0374..a371694f 100644 --- a/pages/guide.php +++ b/pages/guide.php @@ -378,7 +378,7 @@ class GuidePage extends GenericPage $buff = '