Add adminAccount.username, decoupled from the seeded admin's hardcoded name
The seeded admin account's UserModel "name" was hardcoded to "admin". Make it a separate, overridable option (still defaulting to "admin" for compatibility) -- it's purely a display name, since HortusFox logs in by email rather than this field. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -207,14 +207,26 @@ in {
|
||||
migrate:fresh); changing it afterwards has no effect on an
|
||||
existing account.
|
||||
|
||||
Seeds a user named "admin" (email set via adminAccount.email),
|
||||
bcrypt-hashed via `password_hash(..., PASSWORD_BCRYPT)` (matching
|
||||
UserModel's own hashing) and inserted directly into the UserModel
|
||||
table with the admin flag set, bypassing the app's normal two-step
|
||||
Seeds a user (name set via adminAccount.username, email via
|
||||
adminAccount.email), bcrypt-hashed via
|
||||
`password_hash(..., PASSWORD_BCRYPT)` (matching UserModel's own
|
||||
hashing) and inserted directly into the UserModel table with the
|
||||
admin flag set, bypassing the app's normal two-step
|
||||
create-then-promote admin-panel flow.
|
||||
'';
|
||||
};
|
||||
|
||||
adminAccount.username = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "admin";
|
||||
example = "Jane Doe";
|
||||
description = ''
|
||||
Name for the seeded admin account (see adminAccount.passwordFile) --
|
||||
the UserModel table's "name" column. HortusFox logs in by email, not
|
||||
this field, so it's purely a display name shown in the app's UI.
|
||||
'';
|
||||
};
|
||||
|
||||
adminAccount.email = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "admin@${cfg.domain}";
|
||||
@@ -372,7 +384,7 @@ in {
|
||||
# this point.
|
||||
${lib.optionalString (cfg.adminAccount.passwordFile != null) ''
|
||||
admin_hash="$(php -r 'echo password_hash($argv[1], PASSWORD_BCRYPT);' "$(cat "${cfg.adminAccount.passwordFile}")")"
|
||||
mariadb "${cfg.database.name}" -e "INSERT INTO UserModel (name, email, password, admin) VALUES ('admin', '${cfg.adminAccount.email}', '$admin_hash', 1);"
|
||||
mariadb "${cfg.database.name}" -e "INSERT INTO UserModel (name, email, password, admin) VALUES ('${cfg.adminAccount.username}', '${cfg.adminAccount.email}', '$admin_hash', 1);"
|
||||
''}
|
||||
|
||||
touch "${stateDir}/.installed"
|
||||
|
||||
Reference in New Issue
Block a user