2022-08-07 05:09:59 +00:00
|
|
|
/*
|
|
|
|
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
|
|
|
*/
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2022-12-18 11:51:20 +00:00
|
|
|
"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()
|
2022-12-18 11:51:20 +00:00
|
|
|
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 {
|
2022-12-18 11:51:20 +00:00
|
|
|
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")
|
2023-08-06 12:47:58 +00:00
|
|
|
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")
|
|
|
|
}
|