Store the ApiUrl in the message, so that user can't change it midway.
This commit is contained in:
parent
6f1e3da27b
commit
471f5b301b
|
@ -3,6 +3,7 @@ import Browser.Navigation as Nav
|
||||||
import Browser.Dom exposing (Viewport, setViewportOf)
|
import Browser.Dom exposing (Viewport, setViewportOf)
|
||||||
import Scylla.Sync exposing (..)
|
import Scylla.Sync exposing (..)
|
||||||
import Scylla.Login exposing (..)
|
import Scylla.Login exposing (..)
|
||||||
|
import Scylla.Api exposing (..)
|
||||||
import Scylla.Model exposing (..)
|
import Scylla.Model exposing (..)
|
||||||
import Scylla.Http exposing (..)
|
import Scylla.Http exposing (..)
|
||||||
import Scylla.Views exposing (viewFull)
|
import Scylla.Views exposing (viewFull)
|
||||||
|
@ -67,7 +68,7 @@ update msg model = case msg of
|
||||||
ChangeRoute r -> updateChangeRoute model r
|
ChangeRoute r -> updateChangeRoute model r
|
||||||
ViewportAfterMessage v -> updateViewportAfterMessage model v
|
ViewportAfterMessage v -> updateViewportAfterMessage model v
|
||||||
ViewportChangeComplete _ -> (model, Cmd.none)
|
ViewportChangeComplete _ -> (model, Cmd.none)
|
||||||
ReceiveLoginResponse r -> updateLoginResponse model r
|
ReceiveLoginResponse a r -> updateLoginResponse model a r
|
||||||
ReceiveFirstSyncResponse r -> updateSyncResponse model r False
|
ReceiveFirstSyncResponse r -> updateSyncResponse model r False
|
||||||
ReceiveSyncResponse r -> updateSyncResponse model r True
|
ReceiveSyncResponse r -> updateSyncResponse model r True
|
||||||
ReceiveUserData s r -> updateUserData model s r
|
ReceiveUserData s r -> updateUserData model s r
|
||||||
|
@ -119,9 +120,9 @@ updateTryUrl m ur = case ur of
|
||||||
Internal u -> (m, Nav.pushUrl m.key (Url.toString u))
|
Internal u -> (m, Nav.pushUrl m.key (Url.toString u))
|
||||||
_ -> (m, Cmd.none)
|
_ -> (m, Cmd.none)
|
||||||
|
|
||||||
updateLoginResponse : Model -> Result Http.Error LoginResponse -> (Model, Cmd Msg)
|
updateLoginResponse : Model -> ApiUrl -> Result Http.Error LoginResponse -> (Model, Cmd Msg)
|
||||||
updateLoginResponse model r = case r of
|
updateLoginResponse model a r = case r of
|
||||||
Ok lr -> ( { model | token = Just lr.accessToken, loginUsername = lr.userId } , Cmd.batch
|
Ok lr -> ( { model | token = Just lr.accessToken, loginUsername = lr.userId, apiUrl = a }, Cmd.batch
|
||||||
[ firstSync model.apiUrl lr.accessToken
|
[ firstSync model.apiUrl lr.accessToken
|
||||||
, Nav.pushUrl model.key <| Url.Builder.absolute [] []
|
, Nav.pushUrl model.key <| Url.Builder.absolute [] []
|
||||||
, setStoreValuePort ("scylla.loginInfo", Json.Encode.string (lr.accessToken ++ "\n" ++ model.apiUrl))
|
, setStoreValuePort ("scylla.loginInfo", Json.Encode.string (lr.accessToken ++ "\n" ++ model.apiUrl))
|
||||||
|
|
|
@ -67,7 +67,7 @@ login apiUrl username password = request
|
||||||
] )
|
] )
|
||||||
, ("password", string password)
|
, ("password", string password)
|
||||||
]
|
]
|
||||||
, expect = expectJson ReceiveLoginResponse loginResponseDecoder
|
, expect = expectJson (ReceiveLoginResponse apiUrl) loginResponseDecoder
|
||||||
, timeout = Nothing
|
, timeout = Nothing
|
||||||
, tracker = Nothing
|
, tracker = Nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ type Msg =
|
||||||
| ViewportChangeComplete (Result Browser.Dom.Error ()) -- We're done changing the viewport.
|
| ViewportChangeComplete (Result Browser.Dom.Error ()) -- We're done changing the viewport.
|
||||||
| ReceiveFirstSyncResponse (Result Http.Error SyncResponse) -- HTTP, Sync has finished
|
| ReceiveFirstSyncResponse (Result Http.Error SyncResponse) -- HTTP, Sync has finished
|
||||||
| ReceiveSyncResponse (Result Http.Error SyncResponse) -- HTTP, Sync has finished
|
| ReceiveSyncResponse (Result Http.Error SyncResponse) -- HTTP, Sync has finished
|
||||||
| ReceiveLoginResponse (Result Http.Error LoginResponse) -- HTTP, Login has finished
|
| ReceiveLoginResponse ApiUrl (Result Http.Error LoginResponse) -- HTTP, Login has finished
|
||||||
| ReceiveUserData Username (Result Http.Error UserData)
|
| ReceiveUserData Username (Result Http.Error UserData)
|
||||||
| ReceiveCompletedReadMarker (Result Http.Error ())
|
| ReceiveCompletedReadMarker (Result Http.Error ())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user