mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
User/Cleanup
* the great unfuckening of user and displayName
* `login` is purely used as login with AUTH_MODE_SELF
* `email` may now also be used to log in (if the system knows it)
* `username` is purely used for display around the site, and lookups from web context
* both must exist because of external logins
a) that may be not unique
b) you may not want to share with the rest of the world
* todo: implement rename ( because of b) )
This commit is contained in:
@@ -25,10 +25,10 @@ DROP TABLE IF EXISTS `aowow_account`;
|
||||
CREATE TABLE `aowow_account` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`extId` int unsigned DEFAULT NULL COMMENT 'external user id',
|
||||
`user` varchar(64) NOT NULL COMMENT 'login',
|
||||
`login` varchar(64) NOT NULL DEFAULT '' COMMENT 'only used for login',
|
||||
`passHash` varchar(128) NOT NULL,
|
||||
`displayName` varchar(64) NOT NULL COMMENT 'nickname',
|
||||
`email` varchar(64) NOT NULL,
|
||||
`username` varchar(64) NOT NULL COMMENT 'unique; used for for links and display',
|
||||
`email` varchar(64) DEFAULT NULL COMMENT 'unique; can be used for login if AUTH_SELF and can be NULL if not',
|
||||
`joinDate` int unsigned NOT NULL COMMENT 'unixtime',
|
||||
`allowExpire` tinyint unsigned NOT NULL,
|
||||
`dailyVotes` smallint unsigned NOT NULL DEFAULT 0,
|
||||
@@ -48,7 +48,8 @@ CREATE TABLE `aowow_account` (
|
||||
`statusTimer` int unsigned NOT NULL DEFAULT 0,
|
||||
`token` varchar(40) DEFAULT NULL COMMENT 'creation & recovery',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `user` (`user`)
|
||||
UNIQUE KEY `username` (`username`),
|
||||
UNIQUE KEY `email` (`email`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=COMPACT;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
@@ -3322,7 +3323,7 @@ UNLOCK TABLES;
|
||||
|
||||
LOCK TABLES `aowow_dbversion` WRITE;
|
||||
/*!40000 ALTER TABLE `aowow_dbversion` DISABLE KEYS */;
|
||||
INSERT INTO `aowow_dbversion` VALUES (1753563162,0,NULL,NULL);
|
||||
INSERT INTO `aowow_dbversion` VALUES (1753572320,0,NULL,NULL);
|
||||
/*!40000 ALTER TABLE `aowow_dbversion` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ CLISetup::registerUtility(new class extends UtilityScript
|
||||
return true;
|
||||
}
|
||||
|
||||
if (DB::Aowow()->SelectCell('SELECT 1 FROM ?_account WHERE `user` = ? AND (`status` <> ?d OR (`status` = ?d AND `statusTimer` > UNIX_TIMESTAMP()))', $name, ACC_STATUS_NEW, ACC_STATUS_NEW))
|
||||
if (DB::Aowow()->SelectCell('SELECT 1 FROM ?_account WHERE `username` = ? AND (`status` <> ?d OR (`status` = ?d AND `statusTimer` > UNIX_TIMESTAMP()))', $name, ACC_STATUS_NEW, ACC_STATUS_NEW))
|
||||
{
|
||||
CLI::write('[account] ' . Lang::account('nameInUse'), CLI::LOG_ERROR);
|
||||
CLI::write();
|
||||
@@ -103,10 +103,10 @@ CLISetup::registerUtility(new class extends UtilityScript
|
||||
if (!$name || !$passw)
|
||||
return false;
|
||||
|
||||
if (DB::Aowow()->query('REPLACE INTO ?_account (`user`, `passHash`, `displayName`, `joindate`, `email`, `allowExpire`, `userGroups`, `userPerms`) VALUES (?, ?, ?, UNIX_TIMESTAMP(), ?, 0, ?d, 1)',
|
||||
$name, User::hashCrypt($passw), Util::ucFirst($name), $email ?: Cfg::get('CONTACT_EMAIL'), U_GROUP_ADMIN))
|
||||
if (DB::Aowow()->query('REPLACE INTO ?_account (`login`, `passHash`, `username`, `joindate`, `email`, `allowExpire`, `userGroups`, `userPerms`) VALUES (?, ?, ?, UNIX_TIMESTAMP(), ?, 0, ?d, 1)',
|
||||
$name, User::hashCrypt($passw), $name, $email ?: Cfg::get('CONTACT_EMAIL'), U_GROUP_ADMIN))
|
||||
{
|
||||
$newId = DB::Aowow()->selectCell('SELECT `id` FROM ?_account WHERE `user` = ?', $name);
|
||||
$newId = DB::Aowow()->selectCell('SELECT `id` FROM ?_account WHERE `username` = ?', $name);
|
||||
Util::gainSiteReputation($newId, SITEREP_ACTION_REGISTER);
|
||||
|
||||
CLI::write("[account] admin ".$name." created successfully", CLI::LOG_OK);
|
||||
|
||||
12
setup/updates/1753572319_01.sql
Normal file
12
setup/updates/1753572319_01.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
ALTER TABLE `aowow_account`
|
||||
DROP INDEX `user`,
|
||||
CHANGE COLUMN `user` `login` varchar(64) NOT NULL DEFAULT '' COMMENT 'only used for login',
|
||||
CHANGE COLUMN `displayName` `username` varchar(64) NOT NULL COMMENT 'unique; used for for links and display',
|
||||
MODIFY COLUMN `email` varchar(64) DEFAULT NULL COMMENT 'unique; can be used for login if AUTH_SELF and can be NULL if not',
|
||||
ADD CONSTRAINT `username` UNIQUE (`username`);
|
||||
|
||||
UPDATE `aowow_account`
|
||||
SET `email` = NULL WHERE `email` = '';
|
||||
|
||||
ALTER TABLE `aowow_account`
|
||||
ADD CONSTRAINT `email` UNIQUE (`email`);
|
||||
Reference in New Issue
Block a user