alist/cmd/cancel2FA.go

47 lines
1.2 KiB
Go
Raw Normal View History

2022-08-07 05:09:59 +00:00
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"github.com/alist-org/alist/v3/internal/op"
2022-08-30 08:13:01 +00:00
"github.com/alist-org/alist/v3/pkg/utils"
2022-08-07 05:09:59 +00:00
"github.com/spf13/cobra"
)
2022-12-18 11:53:39 +00:00
// Cancel2FACmd represents the delete2fa command
var Cancel2FACmd = &cobra.Command{
2022-08-07 05:09:59 +00:00
Use: "cancel2fa",
Short: "Delete 2FA of admin user",
Run: func(cmd *cobra.Command, args []string) {
Init()
2023-09-05 05:04:27 +00:00
defer Release()
admin, err := op.GetAdmin()
2022-08-07 05:09:59 +00:00
if err != nil {
2022-08-30 08:13:01 +00:00
utils.Log.Errorf("failed to get admin user: %+v", err)
2022-08-07 05:09:59 +00:00
} else {
err := op.Cancel2FAByUser(admin)
2022-08-07 05:09:59 +00:00
if err != nil {
2022-08-30 08:13:01 +00:00
utils.Log.Errorf("failed to cancel 2FA: %+v", err)
2023-03-25 10:36:13 +00:00
} else {
utils.Log.Info("2FA canceled")
DelAdminCacheOnline()
2022-08-07 05:09:59 +00:00
}
}
},
}
func init() {
2022-12-18 11:53:39 +00:00
RootCmd.AddCommand(Cancel2FACmd)
2022-08-07 05:09:59 +00:00
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// cancel2FACmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// cancel2FACmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}