I5MPORH45P3FYFJU4DINO2PW3YPIPGE2FYSSF4XUQ6WGKWWMSKZQC
I4W76IFVZEKUHNVCNK3DKETL7BMOUCSZHQJ57F4EOUZBW7NHWIBAC
DAPLYXHYFBC6C642AAQ4MHRS44TDFWHLZYM646JZ3WLEK5EMUY4AC
T2DN23M7W53UMRV46SKDP6UDMCZB7VG2J772LXKMAJNL6NA62MKAC
NJNMO72S7VIUV22JXB4IFPZMHWTJAOTP6EC6Z4QSKYIROSXT52MQC
EA5BFM5GMM7KNMDLTVOSUKVKMSIDD72TAFVHDVGEOUY5VELECU3QC
5R2Z7FSXJD7Z53QSU2NSTEBONTYK43FIJOSOMUST5XMYIWRXY2HQC
O2BZOX7MS4JCDS3C6EJQXAWUEQV6HVDCIF2FIN2BCJNRLIU6ZVKAC
U7YAT2ZK6GMS7KVFFEQTDRFX6GIN7HVHNWGKIFDGJGE2G2IXSF6QC
SAESJLLYCQJUIHKFYFV53AWHFOSGI5SKLVS7DPTQO6BKGITPYPUQC
QH4UB73NUR2XPHZQ2RGJBKKUBN43RKC7ZJBCFPP4ESUIIEDDR5XQC
QMEYU4MWLTSWPWEEOFRLK2IKE64BY3V5X73323WPLCGPP3TPDYGAC
N6FG4EW6QU7V6QV7UHHYRA3EDKPGVCAEAT7IS3QI45N3GRRV2V7AC
QU5FW67RGCWOWT2YFM4NYMJFFHWIRPQANQBBAHBKZUY7UYMCSIMQC
RB2ETNIFLQUA6OA66DAEOXZ25ENMQGNKX5CZRSKEYHTD6BQ6NTFQC
module Aftok.Navigation where
import Prelude
import Data.Either (Either)
import Data.Lens (view)
import Data.Maybe (Maybe)
import URI.URI
( HierPath
, Host
, Path
, Port
, URIOptions
, UserInfo
, parser
, _query
)
import URI.Extra.QueryPairs (QueryPairs, Key, Value)
import URI.Extra.QueryPairs as QueryPairs
import URI.Fragment (Fragment)
import URI.HostPortPair as HostPortPair
import URI.HostPortPair (HostPortPair)
import Text.Parsing.Parser (runParser, ParseError)
parseURIQuery :: String -> Either ParseError (Maybe (QueryPairs Key Value))
parseURIQuery uriStr =
view _query <$> runParser uriStr (parser options)
options ∷ Record (URIOptions UserInfo (HostPortPair Host Port) Path HierPath (QueryPairs Key Value) Fragment)
options =
{ parseUserInfo: pure
, printUserInfo: identity
, parseHosts: HostPortPair.parser pure pure
, printHosts: HostPortPair.print identity identity
, parsePath: pure
, printPath: identity
, parseHierPath: pure
, printHierPath: identity
, parseQuery: QueryPairs.parse pure pure
, printQuery: QueryPairs.print identity identity
, parseFragment: pure
, printFragment: identity
}
, HH.div
[ P.classes (ClassName <$> [ "form-group" ]) ] $
[ HH.label [ P.for "invitationCodes" ] [ HH.text "Invitation Codes" ]
, HH.input
[ P.type_ P.InputText
, P.classes (ClassName <$> [ "form-control" ])
, P.id_ "invitationCodes"
, P.placeholder "abcdefgh, ..."
, P.value (intercalate ", " st.invitationCodes)
, E.onValueInput (Just <<< SetInvitationCodes)
]
] <> signupErrors InvCodesField st
setZAddr addr = do
zres <- lift $ caps.checkZAddr addr
H.modify_ (_ { recoveryZAddr = Just addr })
case zres of
Acc.ZAddrCheckValid ->
H.modify_ (\st -> st { signupErrors = M.delete ZAddrField st.signupErrors, recoveryType = RecoveryZAddr })
Acc.ZAddrCheckInvalid ->
H.modify_ (\st -> st { signupErrors = M.insert ZAddrField ZAddrInvalid st.signupErrors })
lift $ system.log "Initializing signup page..."
loc <- lift system.href
case parseURIQuery loc of
(Right (Just (QueryPairs q))) -> do
let pairsMap = M.fromFoldable $ (bimap keyToString (map valueToString)) <$> q
traverse_ (\c -> H.modify_ (_ { invitationCodes = [c] })) (join $ M.lookup "invcode" pairsMap)
traverse_ setZAddr (join $ M.lookup "zaddr" pairsMap)
(Right Nothing) -> pure unit
(Left err) ->
lift $ system.error ("Parsing failed for location string " <> loc)
--lift $ system.log "Switching to signin..."
when (addr /= "")
$ do
zres <- lift $ caps.checkZAddr addr
H.modify_ (_ { recoveryZAddr = Just addr })
case zres of
Acc.ZAddrCheckValid ->
H.modify_ (\st -> st { signupErrors = M.delete ZAddrField st.signupErrors })
Acc.ZAddrCheckInvalid ->
H.modify_ (\st -> st { signupErrors = M.insert ZAddrField ZAddrInvalid st.signupErrors })
when (addr /= "") (setZAddr addr)
SetInvitationCodes codeStr -> do
let r = unsafePartial (fromRight $ regex "\\s*,\\s*" global)
H.modify_ (_ { invitationCodes = split r codeStr })