logintest

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package logintest provide a command for testing the login.

Index

Constants

This section is empty.

Variables

View Source
var Command = &cli.Command{
	Name:  "login-test",
	Usage: "Test the login.",
	Action: func(cCtx *cli.Context) error {
		ctx, cancel := context.WithCancel(cCtx.Context)

		cleanChan := make(chan os.Signal, 1)
		signal.Notify(cleanChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
		go func() {
			<-cleanChan
			cancel()
		}()

		jar, err := cookiejar.New(&cookiejar.Options{})
		if err != nil {
			log.Panic().Err(err).Msg("failed to create cookie jar")
		}
		hclient := &http.Client{Jar: jar, Timeout: time.Minute}

		usernameInput := textinput.New("Username/Email:")
		username, err := usernameInput.RunPrompt()
		if err != nil {
			return err
		}

		passwordInput := textinput.New("Password:")
		passwordInput.Hidden = true
		password, err := passwordInput.RunPrompt()
		if err != nil {
			return err
		}

		client := api.NewClient(hclient, &secret.Static{
			SavedCredentials: api.SavedCredentials{
				Username: username,
				Password: password,
			},
		})
		if err := client.Login(ctx); err != nil {
			log.Err(err).
				Msg("failed to login to withny")
			return err
		}

		log.Info().Msg("Login successful")
		return nil
	},
}

Command is the command for logging in and testing the login.

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