mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
5a83d6736b
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
Former-commit-id: 856c18bc9cf98a27b6cbea923b231e0aaf279190 [formerly 201c1a0294947930a7d0706af72ce719a8cc3b98] [formerly 0253e57e2994023e798f6fb0ae76f9c21d18fd69 [formerly 33a58c999a
]]
Former-commit-id: e7d88b22207125c29ea85a5a539653a54584999c [formerly 77cb1e0172cdf7195cc25d557e5028a9250d655c]
Former-commit-id: 64288f5a475a82d5f88c91347a09aea67ebb169d
70 lines
1.7 KiB
Go
70 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)
|
|
}
|
|
|
|
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])
|
|
password := mustGetString(cmd, "password")
|
|
newUsername := mustGetString(cmd, "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(cmd, &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(cmd, "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{}),
|
|
}
|