user

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BanCmd = &cobra.Command{
	Use:   "ban",
	Short: "ban user with user id",
	Long:  "ban user with user id",
	PreRunE: func(cmd *cobra.Command, args []string) error {
		return bootstrap.New(bootstrap.WithContext(cmd.Context())).Add(
			bootstrap.InitDiscardLog,
			bootstrap.InitConfig,
			bootstrap.InitDatabase,
		).Run()
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return errors.New("missing user id")
		}
		u, err := db.GetUserByID(args[0])
		if err != nil {
			fmt.Printf("get user failed: %s\n", err)
			return nil
		}
		err = db.BanUser(u)
		if err != nil {
			fmt.Printf("ban user failed: %s\n", err)
			return nil
		}
		fmt.Printf("ban user success: %s\n", u.Username)
		return nil
	},
}
View Source
var DeleteCmd = &cobra.Command{
	Use:   "delete",
	Short: "delete",
	Long:  `delete user`,
	PreRunE: func(cmd *cobra.Command, args []string) error {
		return bootstrap.New(bootstrap.WithContext(cmd.Context())).Add(
			bootstrap.InitDiscardLog,
			bootstrap.InitConfig,
			bootstrap.InitDatabase,
		).Run()
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return errors.New("missing user id")
		}
		u, err := db.LoadAndDeleteUserByID(args[0])
		if err != nil {
			fmt.Printf("delete user failed: %s\n", err)
			return nil
		}
		fmt.Printf("delete user success: %s\n", u.Username)
		return nil
	},
}
View Source
var SearchCmd = &cobra.Command{
	Use:   "search",
	Short: "search user by id or username",
	Long:  `search user by id or username`,
	PreRunE: func(cmd *cobra.Command, args []string) error {
		return bootstrap.New(bootstrap.WithContext(cmd.Context())).Add(
			bootstrap.InitDiscardLog,
			bootstrap.InitConfig,
			bootstrap.InitDatabase,
		).Run()
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return errors.New("missing user id or username")
		}
		us, err := db.GetUserByIDOrUsernameLike(args[0])
		if err != nil {
			return err
		}
		if len(us) == 0 {
			fmt.Println("user not found")
			return nil
		}
		for _, u := range us {
			fmt.Printf("id: %s\tusername: %s\tcreated_at: %s\trole: %s\n", u.ID, u.Username, u.CreatedAt, u.Role)
		}
		return nil
	},
}
View Source
var UnbanCmd = &cobra.Command{
	Use:   "unban",
	Short: "unban user with user id",
	Long:  "unban user with user id",
	PreRunE: func(cmd *cobra.Command, args []string) error {
		return bootstrap.New(bootstrap.WithContext(cmd.Context())).Add(
			bootstrap.InitDiscardLog,
			bootstrap.InitConfig,
			bootstrap.InitDatabase,
		).Run()
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return errors.New("missing user id")
		}
		u, err := db.GetUserByID(args[0])
		if err != nil {
			fmt.Printf("get user failed: %s\n", err)
			return nil
		}
		err = db.UnbanUser(u)
		if err != nil {
			fmt.Printf("unban user failed: %s", err)
			return nil
		}
		fmt.Printf("unban user success: %s\n", u.Username)
		return nil
	},
}
View Source
var UserCmd = &cobra.Command{
	Use:   "user",
	Short: "user",
	Long:  `you must first shut down the server, otherwise the changes will not take effect.`,
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL