add registration scenario

This commit is contained in:
Aleksandr Zelenin 2018-10-04 13:05:40 +03:00
parent e4a9f57780
commit d74e676cd7
2 changed files with 23 additions and 3 deletions

View file

@ -59,7 +59,7 @@ func main() {
// client authorizer // client authorizer
authorizer := client.ClientAuthorizer() authorizer := client.ClientAuthorizer()
go client.CliInteractor(authorizer) go client.CliInteractor(authorizer, false)
// or bot authorizer // or bot authorizer
botToken := "000000000:gsVCGG5YbikxYHC7bP5vRvmBqJ7Xz6vG6td" botToken := "000000000:gsVCGG5YbikxYHC7bP5vRvmBqJ7Xz6vG6td"

View file

@ -37,6 +37,8 @@ type clientAuthorizer struct {
PhoneNumber chan string PhoneNumber chan string
Code chan string Code chan string
State chan AuthorizationState State chan AuthorizationState
FirstName chan string
LastName chan string
} }
func ClientAuthorizer() *clientAuthorizer { func ClientAuthorizer() *clientAuthorizer {
@ -45,6 +47,8 @@ func ClientAuthorizer() *clientAuthorizer {
PhoneNumber: make(chan string, 1), PhoneNumber: make(chan string, 1),
Code: make(chan string, 1), Code: make(chan string, 1),
State: make(chan AuthorizationState, 10), State: make(chan AuthorizationState, 10),
FirstName: make(chan string, 1),
LastName: make(chan string, 1),
} }
} }
@ -65,7 +69,7 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization
return err return err
case TypeAuthorizationStateWaitCode: case TypeAuthorizationStateWaitCode:
_, err := client.CheckAuthenticationCode(<-stateHandler.Code, "", "") _, err := client.CheckAuthenticationCode(<-stateHandler.Code, <-stateHandler.FirstName, <-stateHandler.LastName)
return err return err
case TypeAuthorizationStateWaitPassword: case TypeAuthorizationStateWaitPassword:
@ -76,6 +80,8 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization
close(stateHandler.PhoneNumber) close(stateHandler.PhoneNumber)
close(stateHandler.Code) close(stateHandler.Code)
close(stateHandler.State) close(stateHandler.State)
close(stateHandler.FirstName)
close(stateHandler.LastName)
return nil return nil
@ -92,7 +98,7 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization
return ErrNotSupportedAuthorizationState return ErrNotSupportedAuthorizationState
} }
func CliInteractor(clientAuthorizer *clientAuthorizer) { func CliInteractor(clientAuthorizer *clientAuthorizer, registration bool) {
for { for {
select { select {
case state := <-clientAuthorizer.State: case state := <-clientAuthorizer.State:
@ -111,6 +117,20 @@ func CliInteractor(clientAuthorizer *clientAuthorizer) {
clientAuthorizer.Code <- code clientAuthorizer.Code <- code
if registration {
fmt.Println("Enter first name: ")
var firstName string
fmt.Scanln(&firstName)
clientAuthorizer.FirstName <- firstName
fmt.Println("Enter last name: ")
var lastName string
fmt.Scanln(&lastName)
clientAuthorizer.LastName <- lastName
}
case TypeAuthorizationStateReady: case TypeAuthorizationStateReady:
return return
} }