GODT-1210: "free user" banner

This commit is contained in:
Alexander Bilyak
2021-10-07 09:28:20 +00:00
committed by Jakub
parent 1141ea27e2
commit c5699700b3
7 changed files with 17 additions and 5 deletions

View File

@ -40,6 +40,8 @@ Popup {
shouldShow: notification ? (notification.active && !notification.dismissed) : false
modal: false
Action {
id: defaultDismissAction

View File

@ -129,7 +129,7 @@ ColumnLayout {
text: "free user error"
enabled: user !== undefined //&& user.isLoginRequested
onClicked: {
root.backend.loginFreeUserError("")
root.backend.loginFreeUserError()
user.resetLoginRequests()
}
}

View File

@ -634,7 +634,7 @@ Window {
// this signals are used only when trying to login with new user (i.e. not in users model)
signal loginUsernamePasswordError(string errorMsg)
signal loginFreeUserError(string errorMsg)
signal loginFreeUserError()
signal loginConnectionError(string errorMsg)
signal login2FARequested()
signal login2FAError(string errorMsg)

View File

@ -22,6 +22,7 @@ package qt
import (
"context"
"encoding/base64"
"github.com/ProtonMail/proton-bridge/internal/users"
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
)
@ -38,7 +39,11 @@ func (f *FrontendQt) login(username, password string) {
f.authClient, f.auth, err = f.bridge.Login(username, f.password)
if err != nil {
// TODO login free user error
if err == pmapi.ErrPaidPlanRequired {
f.qml.LoginFreeUserError()
f.loginClean()
return
}
f.qml.LoginUsernamePasswordError(err.Error())
f.loginClean()
return

View File

@ -55,7 +55,7 @@ type QMLBackend struct {
_ func(username, password string) `slot:"login2Password"`
_ func(username string) `slot:"loginAbort"`
_ func(errorMsg string) `signal:"loginUsernamePasswordError"`
_ func(errorMsg string) `signal:"loginFreeUserError"`
_ func() `signal:"loginFreeUserError"`
_ func(errorMsg string) `signal:"loginConnectionError"`
_ func() `signal:"login2FARequested"`
_ func(errorMsg string) `signal:"login2FAError"`

View File

@ -26,6 +26,8 @@ var (
ErrBad2FACode = errors.New("incorrect 2FA code")
ErrBad2FACodeTryAgain = errors.New("incorrect 2FA code: please try again")
ErrPaidPlanRequired = errors.New("paid subscription plan is required")
)
type ErrUnprocessableEntity struct {

View File

@ -31,6 +31,7 @@ import (
const (
errCodeUpgradeApplication = 5003
errCodeAuthPaidPlanRequired = 10004
)
type Error struct {
@ -60,6 +61,8 @@ func (m *manager) catchAPIError(_ *resty.Client, res *resty.Response) error {
if m.cfg.UpgradeApplicationHandler != nil {
m.cfg.UpgradeApplicationHandler()
}
case apiErr.Code == errCodeAuthPaidPlanRequired:
err = ErrPaidPlanRequired
case res.StatusCode() == http.StatusUnprocessableEntity:
err = ErrUnprocessableEntity{apiErr}
default: