From 331d506281760ac62e8f1715ef729e1b2a91e280 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sun, 19 Jul 2015 17:28:19 +0200 Subject: Showing either error or success message at sign in page --- src/client/ServerCommunication.elm | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/client/ServerCommunication.elm') diff --git a/src/client/ServerCommunication.elm b/src/client/ServerCommunication.elm index e29b084..d581f82 100644 --- a/src/client/ServerCommunication.elm +++ b/src/client/ServerCommunication.elm @@ -8,8 +8,10 @@ import Signal import Task import Task exposing (Task) import Http +import Json.Decode exposing (..) import Update as U +import Update.SignIn exposing (..) type Communication = NoCommunication @@ -55,9 +57,29 @@ communicationToAction communication response = case communication of NoCommunication -> U.NoOp - SignIn _ -> - U.NoOp + SignIn login -> + U.UpdateSignIn (ValidLogin login) SignOut -> U.SignIn else + decodeResponse + response + (\error -> + case communication of + SignIn _ -> + U.UpdateSignIn (ErrorLogin error) + _ -> + U.NoOp + ) + +decodeResponse : Http.Response -> (String -> U.Action) -> U.Action +decodeResponse response responseToAction = + case response.value of + Http.Text text -> + case decodeString ("message" := string) text of + Ok x -> + responseToAction x + Err _ -> + U.NoOp + Http.Blob _ -> U.NoOp -- cgit v1.2.3