add password authorization
This commit is contained in:
parent
4fbb5dd875
commit
a14f99bad2
|
@ -39,6 +39,7 @@ type clientAuthorizer struct {
|
||||||
State chan AuthorizationState
|
State chan AuthorizationState
|
||||||
FirstName chan string
|
FirstName chan string
|
||||||
LastName chan string
|
LastName chan string
|
||||||
|
Password chan string
|
||||||
}
|
}
|
||||||
|
|
||||||
func ClientAuthorizer() *clientAuthorizer {
|
func ClientAuthorizer() *clientAuthorizer {
|
||||||
|
@ -49,6 +50,7 @@ func ClientAuthorizer() *clientAuthorizer {
|
||||||
State: make(chan AuthorizationState, 10),
|
State: make(chan AuthorizationState, 10),
|
||||||
FirstName: make(chan string, 1),
|
FirstName: make(chan string, 1),
|
||||||
LastName: make(chan string, 1),
|
LastName: make(chan string, 1),
|
||||||
|
Password: make(chan string, 1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +85,10 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization
|
||||||
return err
|
return err
|
||||||
|
|
||||||
case TypeAuthorizationStateWaitPassword:
|
case TypeAuthorizationStateWaitPassword:
|
||||||
return ErrNotSupportedAuthorizationState
|
_, err := client.CheckAuthenticationPassword(&CheckAuthenticationPasswordRequest{
|
||||||
|
Password: <-stateHandler.Password,
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
|
||||||
case TypeAuthorizationStateReady:
|
case TypeAuthorizationStateReady:
|
||||||
close(stateHandler.TdlibParameters)
|
close(stateHandler.TdlibParameters)
|
||||||
|
@ -92,6 +97,7 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization
|
||||||
close(stateHandler.State)
|
close(stateHandler.State)
|
||||||
close(stateHandler.FirstName)
|
close(stateHandler.FirstName)
|
||||||
close(stateHandler.LastName)
|
close(stateHandler.LastName)
|
||||||
|
close(stateHandler.Password)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
|
@ -142,6 +148,13 @@ func CliInteractor(clientAuthorizer *clientAuthorizer) {
|
||||||
clientAuthorizer.FirstName <- firstName
|
clientAuthorizer.FirstName <- firstName
|
||||||
clientAuthorizer.LastName <- lastName
|
clientAuthorizer.LastName <- lastName
|
||||||
|
|
||||||
|
case TypeAuthorizationStateWaitPassword:
|
||||||
|
fmt.Println("Enter password: ")
|
||||||
|
var password string
|
||||||
|
fmt.Scanln(&password)
|
||||||
|
|
||||||
|
clientAuthorizer.Password <- password
|
||||||
|
|
||||||
case TypeAuthorizationStateReady:
|
case TypeAuthorizationStateReady:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue