mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
870b5b4079
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
Former-commit-id: bb60ec81f56f5d761ef76b2c1e26bbe83210f434 [formerly b28f83c65e0934e138a1710549f52e0f66a158e0] [formerly 7138a3215ceb144afa0ea45be2315f30b052109f [formerly 72069207c6
]]
Former-commit-id: 0fb7ae6353f786edd93a9166141bfa446dd3dbf9 [formerly 5cb07e8c96a7cfca1aec5843123e1abc4ca8578a]
Former-commit-id: 914c0348516f072a9ccce4e105327feaaddb4cc0
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"github.com/filebrowser/filebrowser/v2/settings"
|
|
"github.com/filebrowser/filebrowser/v2/users"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func init() {
|
|
usersCmd.AddCommand(usersUpdateCmd)
|
|
|
|
usersUpdateCmd.Flags().StringP("password", "p", "", "new password")
|
|
usersUpdateCmd.Flags().StringP("username", "u", "", "new username")
|
|
addUserFlags(usersUpdateCmd.Flags())
|
|
}
|
|
|
|
var usersUpdateCmd = &cobra.Command{
|
|
Use: "update <id|username>",
|
|
Short: "Updates an existing user",
|
|
Long: `Updates an existing user. Set the flags for the
|
|
options you want to change.`,
|
|
Args: cobra.ExactArgs(1),
|
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
|
username, id := parseUsernameOrID(args[0])
|
|
flags := cmd.Flags()
|
|
password := mustGetString(flags, "password")
|
|
newUsername := mustGetString(flags, "username")
|
|
|
|
var err error
|
|
var user *users.User
|
|
|
|
if id != 0 {
|
|
user, err = d.store.Users.Get("", id)
|
|
} else {
|
|
user, err = d.store.Users.Get("", username)
|
|
}
|
|
|
|
checkErr(err)
|
|
|
|
defaults := settings.UserDefaults{
|
|
Scope: user.Scope,
|
|
Locale: user.Locale,
|
|
ViewMode: user.ViewMode,
|
|
Perm: user.Perm,
|
|
Sorting: user.Sorting,
|
|
Commands: user.Commands,
|
|
}
|
|
getUserDefaults(flags, &defaults, false)
|
|
user.Scope = defaults.Scope
|
|
user.Locale = defaults.Locale
|
|
user.ViewMode = defaults.ViewMode
|
|
user.Perm = defaults.Perm
|
|
user.Commands = defaults.Commands
|
|
user.Sorting = defaults.Sorting
|
|
user.LockPassword = mustGetBool(flags, "lockPassword")
|
|
|
|
if newUsername != "" {
|
|
user.Username = newUsername
|
|
}
|
|
|
|
if password != "" {
|
|
user.Password, err = users.HashPwd(password)
|
|
checkErr(err)
|
|
}
|
|
|
|
err = d.store.Users.Update(user)
|
|
checkErr(err)
|
|
printUsers([]*users.User{user})
|
|
}, pythonConfig{}),
|
|
}
|