2023-07-17 03:23:26 +02:00
|
|
|
/*
|
|
|
|
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
|
|
|
|
*/
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2024-02-08 16:35:07 +01:00
|
|
|
"fmt"
|
|
|
|
|
2023-09-20 03:05:44 +02:00
|
|
|
"github.com/quexten/goldwarden/ipc/messages"
|
2023-07-17 03:23:26 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var loginCmd = &cobra.Command{
|
|
|
|
Use: "login",
|
|
|
|
Short: "Starts the login process for Bitwarden",
|
2024-03-15 16:23:11 +01:00
|
|
|
Long: `Starts the login process for Bitwarden.
|
2023-07-17 03:23:26 +02:00
|
|
|
You will be prompted to enter your password, and confirm your second factor if you have one.`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2023-09-20 03:05:44 +02:00
|
|
|
request := messages.DoLoginRequest{}
|
2023-07-17 03:23:26 +02:00
|
|
|
email, _ := cmd.Flags().GetString("email")
|
2023-09-11 22:45:01 +02:00
|
|
|
if email == "" {
|
2024-02-08 16:35:07 +01:00
|
|
|
fmt.Println("Error: No email specified")
|
2023-09-11 22:45:01 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-17 03:23:26 +02:00
|
|
|
request.Email = email
|
2023-08-21 13:52:06 +02:00
|
|
|
passwordless, _ := cmd.Flags().GetBool("passwordless")
|
|
|
|
request.Passwordless = passwordless
|
2023-07-17 03:23:26 +02:00
|
|
|
|
2023-08-21 13:52:06 +02:00
|
|
|
result, err := commandClient.SendToAgent(request)
|
2023-07-17 03:23:26 +02:00
|
|
|
if err != nil {
|
2023-09-11 22:45:01 +02:00
|
|
|
handleSendToAgentError(err)
|
2023-07-17 03:23:26 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch result.(type) {
|
2023-09-20 03:05:44 +02:00
|
|
|
case messages.ActionResponse:
|
|
|
|
if result.(messages.ActionResponse).Success {
|
2024-02-08 16:35:07 +01:00
|
|
|
fmt.Println("Logged in")
|
2023-07-17 03:23:26 +02:00
|
|
|
} else {
|
2024-02-08 16:35:07 +01:00
|
|
|
fmt.Println("Login failed: " + result.(messages.ActionResponse).Message)
|
2023-07-17 03:23:26 +02:00
|
|
|
}
|
|
|
|
default:
|
2024-02-08 16:35:07 +01:00
|
|
|
fmt.Println("Wrong IPC response type for login")
|
2023-07-17 03:23:26 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
vaultCmd.AddCommand(loginCmd)
|
|
|
|
loginCmd.PersistentFlags().String("email", "", "")
|
2024-03-15 16:23:11 +01:00
|
|
|
_ = loginCmd.MarkFlagRequired("email")
|
2023-08-21 13:52:06 +02:00
|
|
|
loginCmd.PersistentFlags().Bool("passwordless", false, "")
|
2023-07-17 03:23:26 +02:00
|
|
|
}
|