ARX7SHY5UXL5ZZDY4BJ6LVQSC2XCI5M6FFXQ35MBWDRUHNJNICHQC /dist/aftok.js
Client Project Setup====================This is the very minimal set of steps that is necessary to build theJavaScript artifact for the client site:```sudo npm install -g purescript pulp bowernpm install virtual-dompulp dep installpulp browserify --optimise --to dist/aftok.js```
import Preludeimport Control.Alt ((<|>))import Control.Monad.Aff (Aff(), runAff)import Control.Monad.Eff (Eff())import Control.Monad.Eff.Exception (throwException)import Data.Either (Either(..))--import Data.Foldable (foldMap)import Data.Foreign.Class (readProp)import Data.Functor (($>))--import Data.Maybe (Maybe(..))import Halogenimport Halogen.Util (appendToBody, onLoad)import Halogen.HTML.Core (className)import qualified Halogen.HTML.Indexed as Himport qualified Halogen.HTML.Events.Indexed as Eimport qualified Halogen.HTML.Properties.Indexed as Pimport Network.HTTP.Affjax (AJAX(), post)-- | The state of the component.type LoginState = { username :: String, password :: String }initialState :: LoginStateinitialState = { username: "", password: "" }-- | The component query algebra.data LoginAction a= SetUsername String a| SetPassword String a| Login String String a-- | The effects used in the app.type AppEffects eff = HalogenEffects (ajax :: AJAX | eff)-- | The definition for the app's main UI component.ui :: forall eff. Component LoginState LoginAction (Aff (AppEffects eff))ui = component render evalwhere
import Control.Monad.Eff.Console
render :: LoginState -> ComponentHTML LoginActionrender st =H.div[ P.classes (className <$> ["panel", "panel-primary"]) ][ H.div[ P.classes [ className "panel-heading" ] ][ H.h3 [ P.classes [ className "panel-title" ]] [ H.text "Aftok Login" ] ], H.div[ P.classes [ className "panel-body" ] ][H.h2_[ H.text "username:" ], H.p_[ H.input[ P.value st.username, P.inputType P.InputText, E.onValueInput (E.input SetUsername)]], H.h2_[ H.text "password:" ], H.p_[ H.input[ P.value st.password, P.inputType P.InputPassword, E.onValueInput (E.input SetPassword)]], H.p_[ H.button[ P.classes (className <$> ["btn", "btn-primary"]), E.onClick (E.input_ (Login st.username st.password))][ H.text "Login" ]]]]eval :: Natural LoginAction (ComponentDSL LoginState LoginAction (Aff (AppEffects eff)))eval (SetUsername user next) = modify (_ { username = user }) $> nexteval (SetPassword pass next) = modify (_ { password = pass }) $> nexteval (Login user pass next) = do_ <- liftAff' (fetchJS user pass)pure next-- | Post some PureScript code to the trypurescript API and fetch the JS result.fetchJS :: forall eff. String -> String -> Aff (ajax :: AJAX | eff) StringfetchJS user pass = doresult <- post "https://aftok.com/login" userlet response = result.responsereturn case readProp "js" response <|> readProp "error" response ofRight js -> jsLeft _ -> "Invalid response"