Add code to retrieve login token after login.
This commit is contained in:
@@ -9,21 +9,17 @@ type alias Password = String
|
||||
|
||||
type alias LoginInfo = (ApiToken, ApiUrl, Username)
|
||||
|
||||
encodeLoginInfo : LoginInfo -> Decode.Value
|
||||
encodeLoginInfo (t,a,u) = Encode.string (t ++ "," ++ a ++ "," ++ u)
|
||||
encodeLoginInfo : LoginInfo -> String
|
||||
encodeLoginInfo (t,a,u) = t ++ "," ++ a ++ "," ++ u
|
||||
|
||||
parseLoginInfoString : String -> Decoder LoginInfo
|
||||
parseLoginInfoString s = case String.indexes "," s of
|
||||
[ fst, snd ] -> Decode.succeed
|
||||
decodeLoginInfo : String -> Maybe LoginInfo
|
||||
decodeLoginInfo s = case String.indexes "," s of
|
||||
[ fst, snd ] -> Just
|
||||
( (String.slice 0 fst s)
|
||||
, (String.slice (fst + 1) snd s)
|
||||
, (String.dropLeft snd s)
|
||||
, (String.dropLeft (snd + 1) s)
|
||||
)
|
||||
_ -> Decode.fail "Incorrectly formatted Login Info string"
|
||||
|
||||
loginInfoDecoder : Decoder LoginInfo
|
||||
loginInfoDecoder = string
|
||||
|> Decode.andThen parseLoginInfoString
|
||||
_ -> Nothing
|
||||
|
||||
type alias LoginResponse =
|
||||
{ userId : String
|
||||
|
||||
@@ -4,10 +4,12 @@ import Scylla.Sync exposing (SyncResponse, JoinedRoom, senderName)
|
||||
import Scylla.Login exposing (LoginResponse, Username, Password)
|
||||
import Scylla.UserData exposing (UserData)
|
||||
import Scylla.Route exposing (Route(..), RoomId)
|
||||
import Scylla.Storage exposing (..)
|
||||
import Browser.Navigation as Nav
|
||||
import Browser.Dom exposing (Viewport)
|
||||
import Url.Builder
|
||||
import Dict exposing (Dict)
|
||||
import Json.Decode
|
||||
import Browser
|
||||
import Http
|
||||
import Url exposing (Url)
|
||||
@@ -44,6 +46,7 @@ type Msg =
|
||||
| ReceiveLoginResponse ApiUrl (Result Http.Error LoginResponse) -- HTTP, Login has finished
|
||||
| ReceiveUserData Username (Result Http.Error UserData)
|
||||
| ReceiveCompletedReadMarker (Result Http.Error ())
|
||||
| ReceiveStoreData StoreData
|
||||
|
||||
displayName : Model -> Username -> String
|
||||
displayName m s = Maybe.withDefault (senderName s) <| Maybe.andThen .displayName <| Dict.get s m.userData
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
port module Scylla.Storage exposing (..)
|
||||
import Json.Encode
|
||||
|
||||
type alias StoreData =
|
||||
{ key : String
|
||||
, value: String
|
||||
}
|
||||
|
||||
port setStoreValuePort : (String, Json.Encode.Value) -> Cmd msg
|
||||
port getStoreValuePort : (String) -> Cmd msg
|
||||
port receiveStoreValuePort : (Json.Encode.Value -> msg) -> Sub msg
|
||||
port receiveStoreValuePort : (StoreData -> msg) -> Sub msg
|
||||
|
||||
Reference in New Issue
Block a user