feat(webui): add user accounts list, admin middleware and admin restricted menu entries
This commit is contained in:
parent
fb98b4fffe
commit
e23a146490
9 changed files with 143 additions and 2 deletions
|
@ -54,6 +54,42 @@ func (db *DB) InitAdminAccount() error {
|
|||
})
|
||||
}
|
||||
|
||||
func (db *DB) LoadAccounts() ([]model.Account, error) {
|
||||
rows, err := db.Query(
|
||||
`SELECT id, username, salt, password_hash, is_admin, created, last_login, settings FROM accounts;`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load accounts from database: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
accounts := make([]model.Account, 0)
|
||||
for rows.Next() {
|
||||
var (
|
||||
account model.Account
|
||||
created int64
|
||||
lastLogin int64
|
||||
)
|
||||
err = rows.Scan(
|
||||
&account.Id,
|
||||
&account.Username,
|
||||
&account.Salt,
|
||||
&account.PasswordHash,
|
||||
&account.IsAdmin,
|
||||
&created,
|
||||
&lastLogin,
|
||||
&account.Settings)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load account from row: %w", err)
|
||||
}
|
||||
account.Created = time.Unix(created, 0)
|
||||
account.LastLogin = time.Unix(lastLogin, 0)
|
||||
accounts = append(accounts, account)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, fmt.Errorf("failed to load accounts from rows: %w", err)
|
||||
}
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
func (db *DB) LoadAccountUsernames() (map[string]string, error) {
|
||||
rows, err := db.Query(
|
||||
`SELECT id, username FROM accounts;`)
|
||||
|
|
|
@ -122,8 +122,8 @@ func (db *DB) LoadStates() ([]model.State, error) {
|
|||
defer rows.Close()
|
||||
states := make([]model.State, 0)
|
||||
for rows.Next() {
|
||||
var state model.State
|
||||
var (
|
||||
state model.State
|
||||
created int64
|
||||
updated int64
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue