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
authorizer := client.ClientAuthorizer()
go client.CliInteractor(authorizer)
go client.CliInteractor(authorizer, false)
// or bot authorizer
botToken := "000000000:gsVCGG5YbikxYHC7bP5vRvmBqJ7Xz6vG6td"

View file

@ -37,6 +37,8 @@ type clientAuthorizer struct {
PhoneNumber chan string
Code chan string
State chan AuthorizationState
FirstName chan string
LastName chan string
}
func ClientAuthorizer() *clientAuthorizer {
@ -45,6 +47,8 @@ func ClientAuthorizer() *clientAuthorizer {
PhoneNumber: make(chan string, 1),
Code: make(chan string, 1),
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
case TypeAuthorizationStateWaitCode:
_, err := client.CheckAuthenticationCode(<-stateHandler.Code, "", "")
_, err := client.CheckAuthenticationCode(<-stateHandler.Code, <-stateHandler.FirstName, <-stateHandler.LastName)
return err
case TypeAuthorizationStateWaitPassword:
@ -76,6 +80,8 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization
close(stateHandler.PhoneNumber)
close(stateHandler.Code)
close(stateHandler.State)
close(stateHandler.FirstName)
close(stateHandler.LastName)
return nil
@ -92,7 +98,7 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization
return ErrNotSupportedAuthorizationState
}
func CliInteractor(clientAuthorizer *clientAuthorizer) {
func CliInteractor(clientAuthorizer *clientAuthorizer, registration bool) {
for {
select {
case state := <-clientAuthorizer.State:
@ -111,6 +117,20 @@ func CliInteractor(clientAuthorizer *clientAuthorizer) {
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:
return
}