Skip to content

Commit d9c6997

Browse files
committed
Adding initial superuser
1 parent 65de483 commit d9c6997

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/WebApp/DataModel/UserDAO.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ protected function initialize() {
3131
$res = $this->database->query($sql);
3232
if ($res === FALSE) {
3333
throw new WebAppException('Cannot create user table: '.$this->database->error());
34+
} else {
35+
// Create initial superadmin
36+
$now = new \TgUtils\Date(time(), WFW_TIMEZONE);
37+
$password = \TgUtils\Utils::generateRandomString();
38+
$sql = 'INSERT INTO '.$this->database->quoteName($this->tableName).' (`created_on`, `email`, `password`, `name`, `roles`, `status`, `data`) VALUES '.
39+
'('.$this->database->quote($now->toMysql()).', \'[email protected]\', '.$this->database->quote($password).', \'Application Superadmin\', \'superadmin\', \'active\', \'{}\')';
40+
$res = $this->database->query($sql);
41+
if ($res === FALSE) {
42+
throw new WebAppException('Cannot create superadmin: '.$this->database->error());
43+
} else {
44+
error_log('===========> Superadmin Email: [email protected]');
45+
error_log('===========> Superadmin Password: '.$password);
46+
error_log('===========> YOU MUST CHANGE THIS IMMEDIATELY!');
47+
}
3448
}
3549
}
3650
}

0 commit comments

Comments
 (0)