Commit c99eb587 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[CLEAN/ERGO] Login form

parent 8d391cd0
...@@ -24,8 +24,7 @@ import Gargantext.Sessions (OpenNodes, Session, mkNodeId) ...@@ -24,8 +24,7 @@ import Gargantext.Sessions (OpenNodes, Session, mkNodeId)
import Gargantext.Types as GT import Gargantext.Types as GT
type CommonProps = type CommonProps =
( ( frontends :: Frontends
frontends :: Frontends
, mCurrentRoute :: Maybe AppRoute , mCurrentRoute :: Maybe AppRoute
, openNodes :: R.State OpenNodes , openNodes :: R.State OpenNodes
, reload :: R.State Reload , reload :: R.State Reload
...@@ -154,8 +153,7 @@ childNodes props@{ children } = ...@@ -154,8 +153,7 @@ childNodes props@{ children } =
el = R.hooksComponent "ChildNodeView" cpt el = R.hooksComponent "ChildNodeView" cpt
cpt {tree, asyncTasks} _ = do cpt {tree, asyncTasks} _ = do
tasks <- R.useState' asyncTasks tasks <- R.useState' asyncTasks
pure $ toHtml (Record.merge commonProps pure $ toHtml (Record.merge commonProps { tasks, tree })
{ tasks, tree })
type PerformActionProps = type PerformActionProps =
( openNodes :: R.State OpenNodes ( openNodes :: R.State OpenNodes
......
...@@ -3,11 +3,12 @@ ...@@ -3,11 +3,12 @@
-- Select a backend and log into it -- Select a backend and log into it
module Gargantext.Components.Login where module Gargantext.Components.Login where
import Prelude (Unit, bind, const, discard, pure, show, ($), (<>), (*>), (<$>), (>), map) import Prelude (Unit, bind, const, discard, pure, show, ($), (<>), (*>), (<$>), (>), map, (==), (/=), not, (&&))
import Data.Array (head) import Data.Array (head)
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Maybe (Maybe(..), fromMaybe) import Data.Maybe (Maybe(..), fromMaybe)
import Data.Tuple (fst, snd) import Data.Tuple (fst, snd)
import Data.Tuple.Nested ((/\))
import Data.String as DST import Data.String as DST
import DOM.Simple.Console (log) import DOM.Simple.Console (log)
import Data.Sequence as DS import Data.Sequence as DS
...@@ -32,7 +33,8 @@ import Gargantext.Utils.Reactix as R2 ...@@ -32,7 +33,8 @@ import Gargantext.Utils.Reactix as R2
type Props = type Props =
( backends :: Array Backend ( backends :: Array Backend
, sessions :: R2.Reductor Sessions Sessions.Action , sessions :: R2.Reductor Sessions Sessions.Action
, visible :: R.State Boolean ) , visible :: R.State Boolean
)
type ModalProps = ( visible :: R.State Boolean ) type ModalProps = ( visible :: R.State Boolean )
...@@ -147,7 +149,8 @@ renderBackend state backend@(Backend {name}) = ...@@ -147,7 +149,8 @@ renderBackend state backend@(Backend {name}) =
type FormProps = type FormProps =
( backend :: Backend ( backend :: Backend
, sessions :: R2.Reductor Sessions Sessions.Action , sessions :: R2.Reductor Sessions Sessions.Action
, visible :: R.State Boolean ) , visible :: R.State Boolean
)
form :: Record FormProps -> R.Element form :: Record FormProps -> R.Element
form props = R.createElement formCpt props [] form props = R.createElement formCpt props []
...@@ -159,6 +162,7 @@ formCpt = R.hooksComponent "G.C.Login.form" cpt where ...@@ -159,6 +162,7 @@ formCpt = R.hooksComponent "G.C.Login.form" cpt where
error <- R.useState' "" error <- R.useState' ""
username <- R.useState' "" username <- R.useState' ""
password <- R.useState' "" password <- R.useState' ""
setBox@(checkBox /\ setCheckBox) <- R.useState' false
pure $ R2.row pure $ R2.row
[ cardGroup [ cardGroup
[ card [ card
...@@ -175,9 +179,18 @@ formCpt = R.hooksComponent "G.C.Login.form" cpt where ...@@ -175,9 +179,18 @@ formCpt = R.hooksComponent "G.C.Login.form" cpt where
, center , center
[ H.label {} [ H.label {}
[ H.div {className: "checkbox"} [ H.div {className: "checkbox"}
[ termsCheckbox {}, H.text "I accept the terms of use ", termsLink {} ] ] [ termsCheckbox setBox , H.text "I accept the terms of use ", termsLink {} ] ]
, loginSubmit $ ]
onClick props error username password ] ] ] ] ] ] ]
, if checkBox == true
&& fst username /= ""
&& fst password /= ""
then H.div {} [center [loginSubmit $ onClick props error username password]]
else H.div {} []
]
]
]
]
onClick {backend, sessions, visible} error username password e = onClick {backend, sessions, visible} error username password e =
launchAff_ $ do launchAff_ $ do
let req = AuthRequest {username: fst username, password: fst password} let req = AuthRequest {username: fst username, password: fst password}
...@@ -194,13 +207,18 @@ csrfTokenInput _ = ...@@ -194,13 +207,18 @@ csrfTokenInput _ =
H.input { type: "hidden", name: "csrfmiddlewaretoken" H.input { type: "hidden", name: "csrfmiddlewaretoken"
, value: csrfMiddlewareToken }-- TODO hard-coded CSRF token , value: csrfMiddlewareToken }-- TODO hard-coded CSRF token
termsCheckbox :: {} -> R.Element termsCheckbox :: R.State Boolean -> R.Element
termsCheckbox _ = termsCheckbox setCheckBox =
H.input { id: "terms-accept", type: "checkbox", value: "", className: "checkbox" } H.input { id: "terms-accept"
, type: "checkbox"
, value: fst setCheckBox
, className: "checkbox"
, on: { click: \_ -> (snd setCheckBox) $ const $ not (fst setCheckBox)}
}
termsLink :: {} -> R.Element termsLink :: {} -> R.Element
termsLink _ = termsLink _ =
H.a { target: "_blank", href: termsUrl } [ H.text " [ Read the terms of use ] " ] H.a { target: "_blank", href: termsUrl } [ H.text " [Read the terms of use]" ]
where termsUrl = "http://gitlab.iscpif.fr/humanities/tofu/tree/master" where termsUrl = "http://gitlab.iscpif.fr/humanities/tofu/tree/master"
requestAccessLink :: {} -> R.Element requestAccessLink :: {} -> R.Element
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment