π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Improve email verification flow
Neeraj Guptab01c0cecaeec
diff --git a/pkg/account.go b/pkg/account.goindex 8c80609104..ebff57e5d5 100644--- a/pkg/account.go+++ b/pkg/account.go@@ -4,7 +4,6 @@ import ("cli-go/internal/api""context""encoding/json"- "fmt""log"bolt "go.etcd.io/bbolt"@@ -38,21 +37,16 @@ func (c *ClICtrl) AddAccount(cxt context.Context) {var authResponse *api.AuthorizationResponsesrpAttr, flowErr := c.Client.GetSRPAttributes(cxt, email)if flowErr != nil {- return- }- if verifyEmail || srpAttr.IsEmailMFAEnabled {- flowErr = c.Client.SendEmailOTP(cxt, email)- if flowErr != nil {- return- }- ott, otpErr := GetCode(- fmt.Sprintf("Enter OTP sent to email %s (or 'c' to cancel)", email),- 6)- if otpErr != nil {- flowErr = otpErr+ // if flowErr type is ApiError and status code is 404, then set verifyEmail to true and continue+ // else return+ if apiErr, ok := flowErr.(*api.ApiError); ok && apiErr.StatusCode == 404 {+ verifyEmail = true+ } else {return}- authResponse, flowErr = c.Client.VerifyEmail(cxt, email, ott)+ }+ if verifyEmail || srpAttr.IsEmailMFAEnabled {+ authResponse, flowErr = c.validateEmail(cxt, email)} else {authResponse, keyEncKey, flowErr = c.signInViaPassword(cxt, email, srpAttr)}@@ -62,6 +56,10 @@ func (c *ClICtrl) AddAccount(cxt context.Context) {if authResponse.IsMFARequired() {authResponse, flowErr = c.validateTOTP(cxt, authResponse)}+ if authResponse.EncryptedToken == "" || authResponse.KeyAttributes == nil {+ log.Fatal("no encrypted token or keyAttributes")+ return+ }if keyEncKey == nil {pass, flowErr := GetSensitiveField("Enter password")if flowErr != nil {diff --git a/pkg/sign_in.go b/pkg/sign_in.goindex 7507e8cebf..29b0e5f0d6 100644--- a/pkg/sign_in.go+++ b/pkg/sign_in.go@@ -66,3 +66,23 @@ func (c *ClICtrl) validateTOTP(ctx context.Context, authResp *api.AuthorizationRreturn totpResp, nil}}++func (c *ClICtrl) validateEmail(ctx context.Context, email string) (*api.AuthorizationResponse, error) {+ err := c.Client.SendEmailOTP(ctx, email)+ if err != nil {+ return nil, err+ }+ for {+ // CLI prompt for OTP+ ott, flowErr := GetCode("Enter OTP", 6)+ if flowErr != nil {+ return nil, flowErr+ }+ authResponse, err := c.Client.VerifyEmail(ctx, email, ott)+ if err != nil {+ log.Printf("failed to verify %v", err)+ continue+ }+ return authResponse, nil+ }+}