aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Model/View/SignIn.elm4
-rw-r--r--src/client/ServerCommunication.elm26
-rw-r--r--src/client/Update/SignIn.elm9
-rw-r--r--src/client/View/Page.elm47
4 files changed, 70 insertions, 16 deletions
diff --git a/src/client/Model/View/SignIn.elm b/src/client/Model/View/SignIn.elm
index 1c8eae7..0a973e2 100644
--- a/src/client/Model/View/SignIn.elm
+++ b/src/client/Model/View/SignIn.elm
@@ -5,11 +5,11 @@ module Model.View.SignIn
type alias SignIn =
{ login : String
- , authentication : Maybe (Result String String)
+ , result : Maybe (Result String String)
}
initSignIn : SignIn
initSignIn =
{ login = ""
- , authentication = Nothing
+ , result = Nothing
}
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
diff --git a/src/client/Update/SignIn.elm b/src/client/Update/SignIn.elm
index a962f90..0e118dc 100644
--- a/src/client/Update/SignIn.elm
+++ b/src/client/Update/SignIn.elm
@@ -7,9 +7,18 @@ import Model.View.SignIn exposing (..)
type SignInAction =
UpdateLogin String
+ | ValidLogin String
+ | ErrorLogin String
updateSignIn : SignInAction -> SignIn -> SignIn
updateSignIn action signIn =
case action of
UpdateLogin login ->
{ signIn | login <- login }
+ ValidLogin message ->
+ { signIn
+ | login <- ""
+ , result <- Just (Ok message)
+ }
+ ErrorLogin message ->
+ { signIn | result <- Just (Err message) }
diff --git a/src/client/View/Page.elm b/src/client/View/Page.elm
index eb86132..bf61dc1 100644
--- a/src/client/View/Page.elm
+++ b/src/client/View/Page.elm
@@ -18,6 +18,7 @@ import Json.Decode as Json
import Model exposing (Model)
import Model.Payment exposing (Payments, Payment)
import Model.View exposing (..)
+import Model.View.SignIn exposing (..)
import Update exposing (..)
import Update.SignIn exposing (..)
@@ -60,27 +61,33 @@ renderMain model =
case model.view of
LoadingView ->
loadingView
- SignInView { login } ->
- signInView login
+ SignInView signIn ->
+ signInView signIn
PaymentView payments ->
paymentsView payments
loadingView : Html
loadingView = text ""
-signInView : String -> Html
-signInView login =
+signInView : SignIn -> Html
+signInView signIn =
div
[ class "signIn" ]
- [ input
- [ value login
- , on "input" targetValue (Signal.message actions.address << UpdateSignIn << UpdateLogin)
- , onEnter serverCommunications.address (SC.SignIn login)
+ [ div
+ [ class "form" ]
+ [ input
+ [ value signIn.login
+ , on "input" targetValue (Signal.message actions.address << UpdateSignIn << UpdateLogin)
+ , onEnter serverCommunications.address (SC.SignIn signIn.login)
+ ]
+ []
+ , button
+ [ onClick serverCommunications.address (SC.SignIn signIn.login) ]
+ [ text "Sign in" ]
]
- []
- , button
- [ onClick serverCommunications.address (SC.SignIn login) ]
- [ text "Sign in" ]
+ , div
+ [ class "result" ]
+ [ signInResult signIn ]
]
onEnter : Signal.Address a -> a -> Attribute
@@ -89,6 +96,22 @@ onEnter address value =
(Json.customDecoder keyCode (\code -> if code == 13 then Ok () else Err ""))
(\_ -> Signal.message address value)
+signInResult : SignIn -> Html
+signInResult signIn =
+ case signIn.result of
+ Just result ->
+ case result of
+ Ok login ->
+ div
+ [ class "success" ]
+ [ text ("We send you an email, please click to the provided link in order to sign in.") ]
+ Err error ->
+ div
+ [ class "error" ]
+ [ text error ]
+ Nothing ->
+ text ""
+
paymentsView : Payments -> Html
paymentsView payments =
table