Restore --reset-admin-password flag for CLI admin password reset
This commit is contained in:
parent
1ac8c2de5a
commit
88c870ab3c
2 changed files with 53 additions and 6 deletions
|
|
@ -68,6 +68,17 @@ func (d *DB) DeleteImcUser(id uint) error {
|
|||
return d.Delete(&ImcUser{}, id).Error // Delete by primary key
|
||||
}
|
||||
|
||||
// UpsertAdminUser creates the admin user if it doesn't exist, or updates the password if it does.
|
||||
func (d *DB) UpsertAdminUser(username, passwordHash string) error {
|
||||
var user ImcUser
|
||||
err := d.Where("username = ? AND role = ?", username, "admin").First(&user).Error
|
||||
if err == nil {
|
||||
return d.Model(&ImcUser{}).Where("id = ?", user.ID).Update("password_hash", passwordHash).Error
|
||||
}
|
||||
_, err = d.CreateImcUser(username, passwordHash, "admin")
|
||||
return err
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Domain Access Control
|
||||
// These functions manage which domains users can access.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue