Registration support
This commit is contained in:
parent
0c71036148
commit
e9e65b6778
|
@ -290,17 +290,24 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) string
|
||||||
}
|
}
|
||||||
// set My Name
|
// set My Name
|
||||||
case "setname":
|
case "setname":
|
||||||
if !c.Online() {
|
|
||||||
return notOnline
|
|
||||||
}
|
|
||||||
|
|
||||||
var firstname string
|
var firstname string
|
||||||
var lastname string
|
var lastname string
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
firstname = args[0]
|
firstname = args[0]
|
||||||
}
|
}
|
||||||
|
if firstname == "" {
|
||||||
|
return "The name should contain at least one character"
|
||||||
|
}
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
lastname = args[1]
|
lastname = rawCmdArguments(cmdline, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.authorizer != nil && !c.authorizer.isClosed {
|
||||||
|
c.authorizer.FirstName <- firstname
|
||||||
|
c.authorizer.LastName <- lastname
|
||||||
|
} else {
|
||||||
|
if !c.Online() {
|
||||||
|
return notOnline
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := c.client.SetName(&client.SetNameRequest{
|
_, err := c.client.SetName(&client.SetNameRequest{
|
||||||
|
@ -310,6 +317,7 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) string
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Couldn't set name").Error()
|
return errors.Wrap(err, "Couldn't set name").Error()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// set About
|
// set About
|
||||||
case "setbio":
|
case "setbio":
|
||||||
if !c.Online() {
|
if !c.Online() {
|
||||||
|
|
|
@ -18,6 +18,9 @@ type clientAuthorizer struct {
|
||||||
Code chan string
|
Code chan string
|
||||||
State chan client.AuthorizationState
|
State chan client.AuthorizationState
|
||||||
Password chan string
|
Password chan string
|
||||||
|
FirstName chan string
|
||||||
|
LastName chan string
|
||||||
|
isClosed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (stateHandler *clientAuthorizer) Handle(c *client.Client, state client.AuthorizationState) error {
|
func (stateHandler *clientAuthorizer) Handle(c *client.Client, state client.AuthorizationState) error {
|
||||||
|
@ -52,7 +55,11 @@ func (stateHandler *clientAuthorizer) Handle(c *client.Client, state client.Auth
|
||||||
return err
|
return err
|
||||||
|
|
||||||
case client.TypeAuthorizationStateWaitRegistration:
|
case client.TypeAuthorizationStateWaitRegistration:
|
||||||
return client.ErrNotSupportedAuthorizationState
|
_, err := c.RegisterUser(&client.RegisterUserRequest{
|
||||||
|
FirstName: <-stateHandler.FirstName,
|
||||||
|
LastName: <-stateHandler.LastName,
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
|
||||||
case client.TypeAuthorizationStateWaitPassword:
|
case client.TypeAuthorizationStateWaitPassword:
|
||||||
_, err := c.CheckAuthenticationPassword(&client.CheckAuthenticationPasswordRequest{
|
_, err := c.CheckAuthenticationPassword(&client.CheckAuthenticationPasswordRequest{
|
||||||
|
@ -77,11 +84,14 @@ func (stateHandler *clientAuthorizer) Handle(c *client.Client, state client.Auth
|
||||||
}
|
}
|
||||||
|
|
||||||
func (stateHandler *clientAuthorizer) Close() {
|
func (stateHandler *clientAuthorizer) Close() {
|
||||||
|
stateHandler.isClosed = true
|
||||||
close(stateHandler.TdlibParameters)
|
close(stateHandler.TdlibParameters)
|
||||||
close(stateHandler.PhoneNumber)
|
close(stateHandler.PhoneNumber)
|
||||||
close(stateHandler.Code)
|
close(stateHandler.Code)
|
||||||
close(stateHandler.State)
|
close(stateHandler.State)
|
||||||
close(stateHandler.Password)
|
close(stateHandler.Password)
|
||||||
|
close(stateHandler.FirstName)
|
||||||
|
close(stateHandler.LastName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect starts TDlib connection
|
// Connect starts TDlib connection
|
||||||
|
@ -102,6 +112,8 @@ func (c *Client) Connect(resource string) error {
|
||||||
Code: make(chan string, 1),
|
Code: make(chan string, 1),
|
||||||
State: make(chan client.AuthorizationState, 10),
|
State: make(chan client.AuthorizationState, 10),
|
||||||
Password: make(chan string, 1),
|
Password: make(chan string, 1),
|
||||||
|
FirstName: make(chan string, 1),
|
||||||
|
LastName: make(chan string, 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
c.locks.authorizationReady.Add(1)
|
c.locks.authorizationReady.Add(1)
|
||||||
|
@ -212,6 +224,10 @@ func (c *Client) interactor() {
|
||||||
case client.TypeAuthorizationStateWaitCode:
|
case client.TypeAuthorizationStateWaitCode:
|
||||||
log.Warn("Waiting for authorization code...")
|
log.Warn("Waiting for authorization code...")
|
||||||
gateway.SendMessage(c.jid, "", "Please, enter authorization code via /code 12345", c.xmpp)
|
gateway.SendMessage(c.jid, "", "Please, enter authorization code via /code 12345", c.xmpp)
|
||||||
|
// stage 1b: wait for registration
|
||||||
|
case client.TypeAuthorizationStateWaitRegistration:
|
||||||
|
log.Warn("Waiting for full name...")
|
||||||
|
gateway.SendMessage(c.jid, "", "This number is not registered yet! Please, enter your name via /setname John Doe", c.xmpp)
|
||||||
// stage 2: wait for 2fa
|
// stage 2: wait for 2fa
|
||||||
case client.TypeAuthorizationStateWaitPassword:
|
case client.TypeAuthorizationStateWaitPassword:
|
||||||
log.Warn("Waiting for 2FA password...")
|
log.Warn("Waiting for 2FA password...")
|
||||||
|
|
Loading…
Reference in a new issue