From 47104f0b3965cd1dfba0f466afdb5e8983dc7bec Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 12 Mar 2016 00:21:41 +0100 Subject: Do not try to init data after login mail was sent --- src/client/elm/Model/Action/SignInAction.elm | 2 +- src/client/elm/Server.elm | 4 ++-- src/client/elm/Update.elm | 4 ++-- src/client/elm/Update/SignIn.elm | 9 +++++---- src/server/Controller/SignIn.hs | 6 +++--- 5 files changed, 13 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/client/elm/Model/Action/SignInAction.elm b/src/client/elm/Model/Action/SignInAction.elm index 619dbda..bead018 100644 --- a/src/client/elm/Model/Action/SignInAction.elm +++ b/src/client/elm/Model/Action/SignInAction.elm @@ -5,5 +5,5 @@ module Model.Action.SignInAction type SignInAction = UpdateLogin String | WaitingServer - | ValidLogin String + | ValidLogin | ErrorLogin String diff --git a/src/client/elm/Server.elm b/src/client/elm/Server.elm index 9478f2a..c1fb445 100644 --- a/src/client/elm/Server.elm +++ b/src/client/elm/Server.elm @@ -30,10 +30,10 @@ init = `Task.andMap` (Http.get ("number" := Json.int) "/payments/count") `Task.andMap` (Http.get payersDecoder "/payers") -signIn : String -> Task Http.Error Init +signIn : String -> Task Http.Error () signIn email = post ("/signIn?email=" ++ email) - |> flip Task.andThen (always init) + |> Task.map (always ()) addPayment : String -> String -> PaymentFrequency -> Task Http.Error PaymentId addPayment name cost frequency = diff --git a/src/client/elm/Update.elm b/src/client/elm/Update.elm index 948ab1f..adb90ab 100644 --- a/src/client/elm/Update.elm +++ b/src/client/elm/Update.elm @@ -32,7 +32,7 @@ update action model = SignIn email -> ( applySignIn model (SignInAction.WaitingServer) , Server.signIn email - |> Task.map GoLoggedInView + |> Task.map (always (UpdateSignIn SignInAction.ValidLogin)) |> flip Task.onError (\error -> let errorMessage = getMessage (errorKey error) model.translations in Task.succeed (UpdateSignIn (SignInAction.ErrorLogin errorMessage)) @@ -69,7 +69,7 @@ applySignIn : Model -> SignInAction -> Model applySignIn model signInAction = case model.view of V.SignInView signInView -> - { model | view = V.SignInView (updateSignIn signInAction signInView) } + { model | view = V.SignInView (updateSignIn model.translations signInAction signInView) } _ -> model diff --git a/src/client/elm/Update/SignIn.elm b/src/client/elm/Update/SignIn.elm index f55ce6d..ade5761 100644 --- a/src/client/elm/Update/SignIn.elm +++ b/src/client/elm/Update/SignIn.elm @@ -4,9 +4,10 @@ module Update.SignIn import Model.View.SignInView exposing (..) import Model.Action.SignInAction exposing (..) +import Model.Translations exposing (getMessage, Translations) -updateSignIn : SignInAction -> SignInView -> SignInView -updateSignIn action signInView = +updateSignIn : Translations -> SignInAction -> SignInView -> SignInView +updateSignIn translations action signInView = case action of UpdateLogin login -> { signInView | @@ -16,10 +17,10 @@ updateSignIn action signInView = { signInView | waitingServer = True } - ValidLogin message -> + ValidLogin -> { signInView | login = "" - , result = Just (Ok message) + , result = Just (Ok (getMessage "SignInEmailSent" translations)) , waitingServer = False } ErrorLogin message -> diff --git a/src/server/Controller/SignIn.hs b/src/server/Controller/SignIn.hs index 1fb62ec..d4a1e25 100644 --- a/src/server/Controller/SignIn.hs +++ b/src/server/Controller/SignIn.hs @@ -53,13 +53,13 @@ signIn config login = status ok200 Left _ -> do status badRequest400 - text (TL.pack $ show SendEmailFail) + text . TL.pack . show $ SendEmailFail Nothing -> do status badRequest400 - text (TL.pack $ show UnauthorizedSignIn) + text . TL.pack . show $ UnauthorizedSignIn else do status badRequest400 - text (TL.pack $ show EnterValidEmail) + text . TL.pack . show $ EnterValidEmail validateSignIn :: Config -> Text -> ActionM () validateSignIn config textToken = do -- cgit v1.2.3