mirror of
https://github.com/bit1001/tdl.git
synced 2024-09-20 06:35:54 +08:00
refactor(login): phone input. close #5
This commit is contained in:
parent
fa3c480a28
commit
52ca0caf01
|
@ -24,11 +24,20 @@ func (c noSignUp) AcceptTermsOfService(_ context.Context, tos tg.HelpTermsOfServ
|
|||
// termAuth implements authentication via terminal.
|
||||
type termAuth struct {
|
||||
noSignUp
|
||||
phone string
|
||||
}
|
||||
|
||||
func (a termAuth) Phone(_ context.Context) (string, error) {
|
||||
return a.phone, nil
|
||||
phone, err := input.DefaultUI().Ask(color.BlueString("Enter your phone number:"), &input.Options{
|
||||
Default: color.CyanString("+86 12345678900"),
|
||||
Loop: true,
|
||||
Required: true,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
color.Blue("Sending Code...")
|
||||
return strings.TrimSpace(phone), nil
|
||||
}
|
||||
|
||||
func (a termAuth) Password(_ context.Context) (string, error) {
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"github.com/iyear/tdl/app/internal/tgc"
|
||||
"github.com/iyear/tdl/pkg/consts"
|
||||
"github.com/iyear/tdl/pkg/kv"
|
||||
"github.com/tcnksm/go-input"
|
||||
)
|
||||
|
||||
func Run(ctx context.Context, ns, proxy string) error {
|
||||
|
@ -29,17 +28,7 @@ func Run(ctx context.Context, ns, proxy string) error {
|
|||
color.Blue("Login...")
|
||||
color.Yellow("WARN: If data exists in the namespace, data will be overwritten")
|
||||
|
||||
phone, err := input.DefaultUI().Ask(color.BlueString("Enter your phone number:"), &input.Options{
|
||||
Default: color.CyanString("+86 12345678900"),
|
||||
Loop: true,
|
||||
Required: true,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
color.Blue("Send code...")
|
||||
|
||||
flow := auth.NewFlow(termAuth{phone: phone}, auth.SendCodeOptions{})
|
||||
flow := auth.NewFlow(termAuth{}, auth.SendCodeOptions{})
|
||||
if err := c.Auth().IfNecessary(ctx, flow); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue