105 lines
2.7 KiB
Elm
105 lines
2.7 KiB
Elm
module Page.Token exposing
|
|
( Model
|
|
, Msg
|
|
, init
|
|
, update
|
|
, view
|
|
)
|
|
|
|
import Browser
|
|
import Html exposing (Html, h1, h2, li, p, text, ul)
|
|
import Http exposing (..)
|
|
import Mi exposing (TokenData, expectJson, request, tokenDecoder)
|
|
import Page
|
|
|
|
|
|
type alias Model =
|
|
{ token : Maybe String
|
|
, token_data : Maybe TokenData
|
|
, error : Maybe String
|
|
}
|
|
|
|
|
|
init : Model
|
|
init =
|
|
Model Nothing Nothing Nothing
|
|
|
|
|
|
type Msg
|
|
= Init
|
|
| GotTokenData (Result Http.Error TokenData)
|
|
|
|
|
|
update : Msg -> String -> Model -> ( Model, Cmd Msg )
|
|
update msg token model =
|
|
case msg of
|
|
Init ->
|
|
( { model | token = Just token }
|
|
, Mi.request
|
|
"GET"
|
|
token
|
|
"/.within/tokeninfo"
|
|
Http.emptyBody
|
|
(Mi.expectJson GotTokenData tokenDecoder)
|
|
)
|
|
|
|
GotTokenData result ->
|
|
case result of
|
|
Ok data ->
|
|
( { model | token_data = Just data }
|
|
, Cmd.none
|
|
)
|
|
|
|
Err (BadUrl val) ->
|
|
( { model | error = Just ("bad URL " ++ val) }
|
|
, Cmd.none
|
|
)
|
|
|
|
Err Timeout ->
|
|
( { model | error = Just "Timeout" }
|
|
, Cmd.none
|
|
)
|
|
|
|
Err NetworkError ->
|
|
( { model | error = Just "network error" }
|
|
, Cmd.none
|
|
)
|
|
|
|
Err (BadStatus code) ->
|
|
( { model | error = Just ("bad status code " ++ String.fromInt code) }
|
|
, Cmd.none
|
|
)
|
|
|
|
Err (BadBody err_msg) ->
|
|
( { model | error = Just err_msg }
|
|
, Cmd.none
|
|
)
|
|
|
|
|
|
view : Model -> Browser.Document msg
|
|
view model =
|
|
case model.token_data of
|
|
Nothing ->
|
|
Page.template "No token data?"
|
|
[ h1 [] [ text "No token data?" ]
|
|
, p [] [ text "this should be impossible" ]
|
|
]
|
|
|
|
Just token_data ->
|
|
Page.template "Mi"
|
|
[ h1 [] [ text "Mi" ]
|
|
, h2 [] [ text "TODO" ]
|
|
, ul []
|
|
[ li [] [ text "Switch CRUD" ]
|
|
, li [] [ text "POSSE manual announcement" ]
|
|
]
|
|
, h2 [] [ text "Token data" ]
|
|
, p []
|
|
[ text "Token sub: "
|
|
, text token_data.sub
|
|
, Html.br [] []
|
|
, text "ID: "
|
|
, text token_data.jti
|
|
]
|
|
]
|