on master help sign in
Keep login details on failure
commite36807dd9846ff5600e6334954a252dbf527aa25 authoriko <ilyakooo0@gmail.com> dateSat 13 Aug 2022, 14:55 (4 years ago) parentd18ee8d
5 files changed+33−16
backend/Bridge.purs+1 backend/Main.purs+10−10 bridge.yaml+1 frontend/Bridge.elm+3 frontend/Main.elm+18−6
backend/Bridge.purs+1
@@ -571,6 +571,7 @@ data Sub =
571571 | NeedsMasterPassword Sub_NeedsMasterPassword
572572 | RecieveEmail String
573573 | Reset
574+ | WrongPassword
574575
575576instance encodeJsonSub :: EncodeJson Sub where
576577 encodeJson = genericEncodeAeson Argonaut.defaultOptions
backend/Main.purs+10−10
@@ -116,17 +116,17 @@ main = do
116116 loginResponse <-
117117 liftAff
118118 $ catchError
119− ( runBaseAff' $ run $ runReaderAt (Proxy :: _ "api") unauthedApi
120− $ Logic.getLogInRequestToken prelogin (Email email) (Password password) captchaToken
119+ ( do
120+ resp <-
121+ runBaseAff' $ run $ runReaderAt (Proxy :: _ "api") unauthedApi
122+ $ Logic.getLogInRequestToken prelogin (Email email) (Password password) captchaToken
123+ pure $ Right resp
121124 )
122− ( const
123− $ liftEffect do
124− Elm.send app Bridge.NeedsLogin
125− Exc.throw "Could not log in. Please check your data and try again."
126− )
127− case toEither1 loginResponse of
128− Left { siteKey } -> send $ Bridge.NeedsCaptcha siteKey
129− Right token -> do
125+ (const $ pure $ Left unit)
126+ case map toEither1 loginResponse of
127+ Left _ -> send Bridge.WrongPassword
128+ Right (Left { siteKey }) -> send $ Bridge.NeedsCaptcha siteKey
129+ Right (Right token) -> do
130130 masterKey <- Logic.makePreloginKey prelogin (Email email) (Password password)
131131 api <- liftPromise $ services.getApi urls (nullify token)
132132 sync <- liftPromise $ api.getSync unit
bridge.yaml+1
@@ -10,6 +10,7 @@ Sub:
1010 id: String
1111 cipherType: CipherType
1212- LoginSuccessful
13+- WrongPassword
1314- NeedsMasterPassword:
1415 server: String
1516 login: String
frontend/Bridge.elm+3
@@ -710,6 +710,7 @@ type Sub =
710710 | NeedsMasterPassword Sub_NeedsMasterPassword
711711 | RecieveEmail String
712712 | Reset
713+ | WrongPassword
713714
714715jsonDecSub : Json.Decode.Decoder ( Sub )
715716jsonDecSub =
@@ -726,6 +727,7 @@ jsonDecSub =
726727 , ("NeedsMasterPassword", Json.Decode.lazy (\_ -> Json.Decode.map NeedsMasterPassword (jsonDecSub_NeedsMasterPassword)))
727728 , ("RecieveEmail", Json.Decode.lazy (\_ -> Json.Decode.map RecieveEmail (Json.Decode.string)))
728729 , ("Reset", Json.Decode.lazy (\_ -> Json.Decode.succeed Reset))
730+ , ("WrongPassword", Json.Decode.lazy (\_ -> Json.Decode.succeed WrongPassword))
729731 ]
730732 jsonDecObjectSetSub = Set.fromList []
731733 in decodeSumTaggedObject "Sub" "tag" "contents" jsonDecDictSub jsonDecObjectSetSub
@@ -745,5 +747,6 @@ jsonEncSub val =
745747 NeedsMasterPassword v1 -> ("NeedsMasterPassword", encodeValue (jsonEncSub_NeedsMasterPassword v1))
746748 RecieveEmail v1 -> ("RecieveEmail", encodeValue (Json.Encode.string v1))
747749 Reset -> ("Reset", encodeValue (Json.Encode.list identity []))
750+ WrongPassword -> ("WrongPassword", encodeValue (Json.Encode.list identity []))
748751 in encodeSumTaggedObject "tag" "contents" keyval val
749752
frontend/Main.elm+18−6
@@ -31,7 +31,7 @@ type Msg
3131 = Noop
3232 | RecieveMessage String
3333 | ShowLoginPage
34− | ShowError String
34+ | ShowError String String
3535 | ShowInfo String String
3636 | CloseNotification
3737 | SubmitLogin { email : String, password : String, server : String }
@@ -62,6 +62,7 @@ type Msg
6262 | FireGlobalEvent Event
6363 | GeneratePassword Bridge.PasswordGeneratorConfig
6464 | OpenNewCipherEditPage Bridge.CipherType
65+ | WrongPassword
6566
6667
6768type alias Model =
@@ -185,14 +186,14 @@ main =
185186subscriptions : Model -> Sub Msg
186187subscriptions model =
187188 Sub.batch
188− ([ getBridge ShowError
189+ ([ getBridge (ShowError "Something went wrong!")
189190 (\msg ->
190191 case msg of
191192 Bridge.NeedsLogin ->
192193 ShowLoginPage
193194
194195 Bridge.Error err ->
195− ShowError err
196+ ShowError "Something went wrong!" err
196197
197198 Bridge.LoadCiphers ciphers ->
198199 LoadCiphers ciphers
@@ -223,6 +224,9 @@ subscriptions model =
223224
224225 Bridge.GeneratedPassword password ->
225226 GlobalEvents.GeneratedPassword password |> FireGlobalEvent
227+
228+ Bridge.WrongPassword ->
229+ WrongPassword
226230 )
227231 ]
228232 ++ optional (List.isEmpty model.notifications |> not) (Time.every 1000 (\t -> ClearNotification { currentTime = t }))
@@ -306,9 +310,9 @@ update msg model =
306310 }
307311 model
308312
309− ShowError err ->
313+ ShowError title err ->
310314 appendNotification
311− { title = "Something went wrong"
315+ { title = title
312316 , message = err
313317 , severity = Notification.Error
314318 }
@@ -328,7 +332,7 @@ update msg model =
328332 )
329333
330334 SubmitLogin data ->
331− ( appendPageStack <| LoadingPage
335+ ( keepStackWith <| LoadingPage
332336 , FFI.sendBridge (Bridge.Login data)
333337 )
334338
@@ -589,6 +593,14 @@ update msg model =
589593 }
590594 |> Tuple.mapFirst (\pageModel -> keepStackWith <| EditCipherModel pageModel)
591595
596+ WrongPassword ->
597+ ( model
598+ , Cmd.batch
599+ [ pureCmd PopView
600+ , pureCmd (ShowError "Login failed" "The login details you provided are not valid. Please try again.")
601+ ]
602+ )
603+
592604
593605loginCallbacks : Login.Callbacks Msg
594606loginCallbacks =