Improved error handling in connect/auth stage

This commit is contained in:
Christian Muehlhaeuser 2019-05-10 19:14:56 +02:00
parent fb41281f8e
commit 332c6ecdde
No known key found for this signature in database
GPG key ID: 3CF9FA45CA1EBB7E
3 changed files with 18 additions and 10 deletions

View file

@ -9,8 +9,8 @@ import (
type UIBridge struct {
core.QObject
_ func(instance string) `slot:"connectButton"`
_ func(code string, redirectURI string) `slot:"authButton"`
_ func(instance string) bool `slot:"connectButton"`
_ func(code string, redirectURI string) bool `slot:"authButton"`
_ func(replyid string, message string) `slot:"postButton"`
_ func(id string) `slot:"shareButton"`

View file

@ -68,8 +68,10 @@ Popup {
onClicked: {
var instance = instanceArea.text
connectSwipeView.currentIndex = 1
uiBridge.connectButton(instance)
var result = uiBridge.connectButton(instance)
if (result) {
connectSwipeView.currentIndex = 1
}
}
}
}
@ -115,8 +117,10 @@ Popup {
onClicked: {
var code = codeArea.text
connectDialog.close()
uiBridge.authButton(code, settings.redirectURL)
var result = uiBridge.authButton(code, settings.redirectURL)
if (result) {
connectDialog.close()
}
}
}
}

View file

@ -20,14 +20,15 @@ var (
accountMessagesModel = NewMessageModel(nil)
)
func connectToInstance(instance string) {
func connectToInstance(instance string) bool {
var authURI string
var redirectURI string
var err error
tc, authURI, redirectURI, err = mastodon.RegisterAccount(instance)
if err != nil {
fmt.Println("Error registering app:", err)
return
accountBridge.SetError(err.Error())
return false
}
configBridge.SetAuthURL(authURI)
@ -35,13 +36,15 @@ func connectToInstance(instance string) {
fmt.Println("auth uri:", authURI)
fmt.Println("redirect uri:", redirectURI)
return true
}
func authInstance(code, redirectURI string) {
func authInstance(code, redirectURI string) bool {
instance, token, clientID, clientSecret, err := tc.Authenticate(code, redirectURI)
fmt.Println("authenticate:", err)
if err != nil {
return
accountBridge.SetError(err.Error())
return false
}
config.Account[0].Instance = instance
@ -49,6 +52,7 @@ func authInstance(code, redirectURI string) {
config.Account[0].ClientSecret = clientSecret
config.Account[0].Token = token
setupMastodon(config.Account[0])
return true
}
// reply is used to post a new message