@@ -20,7 +20,6 @@ import Data.Either (Either(..))
20import Data.HCaptcha (bindHCaptchToken)
20import Data.HCaptcha (bindHCaptchToken)
21import Data.JNullable (jnull, nullify)
21import Data.JNullable (jnull, nullify)
22import Data.Maybe (Maybe(..))
22import Data.Maybe (Maybe(..))
23−import Data.Newtype (wrap)
24import Data.OpenURL (openURL)
23import Data.OpenURL (openURL)
25import Data.Ord.Down (Down(..))
24import Data.Ord.Down (Down(..))
26import Data.SymmetricCryptoKey (SymmetricCryptoKey)
25import Data.SymmetricCryptoKey (SymmetricCryptoKey)
@@ -86,6 +85,7 @@ main = do
86 , crypto: services.crypto
85 , crypto: services.crypto
88 , cryptoFunctions: services.cryptoFunctions
87 , cryptoFunctions: services.cryptoFunctions
90 flip runReaderT env do
90 flip runReaderT env do
91 prelogin <- liftPromise $ unauthedApi.postPrelogin { email }
91 prelogin <- liftPromise $ unauthedApi.postPrelogin { email }
@@ -94,9 +94,7 @@ main = do
94 (Logic.getLogInRequestToken prelogin (Email email) (Password password) captchaToken)
94 (Logic.getLogInRequestToken prelogin (Email email) (Password password) captchaToken)
95 (const $ liftEffect $ Exc.throw "Could not log in. Please check your data and try again.")
95 (const $ liftEffect $ Exc.throw "Could not log in. Please check your data and try again.")
96 case toEither1 loginResponse of
96 case toEither1 loginResponse of
99− Elm.send app $ Bridge.NeedsCaptcha siteKey
97+ Left { siteKey } -> send $ Bridge.NeedsCaptcha siteKey
100 Right token -> do
98 Right token -> do
101 masterKey <- Logic.makePreloginKey prelogin (Email email) (Password password)
99 masterKey <- Logic.makePreloginKey prelogin (Email email) (Password password)
102 api <- liftPromise $ services.getApi urls (nullify token)
100 api <- liftPromise $ services.getApi urls (nullify token)
@@ -110,16 +108,15 @@ main = do
110 Storage.store storage PreloginResponseKey prelogin
108 Storage.store storage PreloginResponseKey prelogin
111 Storage.store storage SyncKey sync
109 Storage.store storage SyncKey sync
112 Storage.store storage TokenKey token
110 Storage.store storage TokenKey token
113− Elm.send app Bridge.LoginSuccessful
111+ send Bridge.LoginSuccessful
114 Bridge.NeedCiphersList ->
112 Bridge.NeedCiphersList ->
116 sync <- getOrReset SyncKey
114 sync <- getOrReset SyncKey
117 ciphers <- traverse processCipher sync.ciphers
115 ciphers <- traverse processCipher sync.ciphers
119 sortedCiphers = Array.sortWith (_.date >>> Down) ciphers
117 sortedCiphers = Array.sortWith (_.date >>> Down) ciphers
121− Elm.send app $ Bridge.LoadCiphers $ Bridge.Sub_LoadCiphers_List $ map _.cipher sortedCiphers
118+ send $ Bridge.LoadCiphers $ Bridge.Sub_LoadCiphers_List $ map _.cipher sortedCiphers
122− Storage.store storage SyncKey sync
119+ liftEffect $ Storage.store storage SyncKey sync
123 Bridge.NeedsReset -> do
120 Bridge.NeedsReset -> do
124 WebStorage.clear storage
121 WebStorage.clear storage
125 Elm.send app Bridge.Reset
122 Elm.send app Bridge.Reset
@@ -134,11 +131,10 @@ main = do
134 sync <- getOrReset SyncKey
131 sync <- getOrReset SyncKey
135 prelogin <- getOrReset PreloginResponseKey
132 prelogin <- getOrReset PreloginResponseKey
136 masterKey <- Logic.makePreloginKey prelogin (Email sync.profile.email) (Password masterPassword)
133 masterKey <- Logic.makePreloginKey prelogin (Email sync.profile.email) (Password masterPassword)
138− Ref.write (Just masterKey) masterKeyRef
134+ liftEffect $ Ref.write (Just masterKey) masterKeyRef
139− Elm.send app Bridge.LoginSuccessful
135+ send Bridge.LoginSuccessful
141− liftEffect $ Elm.send app $ Bridge.Error "The password is wrong. Please try again."
137+ send $ Bridge.Error "The password is wrong. Please try again."
142 requestMasterPassword
138 requestMasterPassword
143 Bridge.Init -> do
139 Bridge.Init -> do
144 liftEffect $ Storage.get storage TokenKey
140 liftEffect $ Storage.get storage TokenKey
@@ -254,11 +250,9 @@ getAuthedApi = do
255requestMasterPassword :: forall r. HasL "storage" Storage r => HasL "app" Elm r => Al r Unit
251requestMasterPassword :: forall r. HasL "storage" Storage r => HasL "app" Elm r => Al r Unit
256requestMasterPassword = do
252requestMasterPassword = do
257− app <- l (L :: L "app")
258 url <- getOrReset UrlsKey
253 url <- getOrReset UrlsKey
259 sync <- getOrReset SyncKey
254 sync <- getOrReset SyncKey
260− liftEffect $ Elm.send app $ Bridge.NeedsMasterPassword
261− $ Bridge.Sub_NeedsMasterPassword { server: url, login: sync.profile.email }
255+ send $ Bridge.NeedsMasterPassword $ Bridge.Sub_NeedsMasterPassword { server: url, login: sync.profile.email }
263send :: forall r. HasL "app" Elm r => Bridge.Sub -> Al r Unit
257send :: forall r. HasL "app" Elm r => Bridge.Sub -> Al r Unit
264send sub = do
258send sub = do