Add OpenID support to webapp

This commit is contained in:
eikek
2021-09-05 23:43:07 +02:00
parent f8362329a9
commit 984dda9da0
13 changed files with 138 additions and 32 deletions

View File

@ -11,9 +11,12 @@ module Page.Login.Data exposing
, Model
, Msg(..)
, emptyModel
, init
)
import Api
import Api.Model.AuthResult exposing (AuthResult)
import Data.Flags exposing (Flags)
import Http
import Page exposing (Page(..))
@ -51,6 +54,19 @@ emptyModel =
}
init : Flags -> Bool -> ( Model, Cmd Msg )
init flags oauth =
let
cmd =
if oauth then
Api.loginSession flags AuthResp
else
Cmd.none
in
( emptyModel, cmd )
type Msg
= SetUsername String
| SetPassword String

View File

@ -15,8 +15,8 @@ import Page.Login.Data exposing (..)
import Ports
update : Maybe Page -> Flags -> Msg -> Model -> ( Model, Cmd Msg, Maybe AuthResult )
update referrer flags msg model =
update : ( Maybe Page, Bool ) -> Flags -> Msg -> Model -> ( Model, Cmd Msg, Maybe AuthResult )
update ( referrer, oauth ) flags msg model =
case msg of
SetUsername str ->
( { model | username = str }, Cmd.none, Nothing )

View File

@ -7,8 +7,10 @@
module Page.Login.View2 exposing (viewContent, viewSidebar)
import Api
import Api.Model.AuthResult exposing (AuthResult)
import Api.Model.VersionInfo exposing (VersionInfo)
import Comp.Basic as B
import Data.Flags exposing (Flags)
import Data.UiSettings exposing (UiSettings)
import Html exposing (..)
@ -53,6 +55,7 @@ viewContent texts flags versionInfo _ model =
StepLogin ->
loginForm texts flags model
, openIdLinks texts flags
]
, a
[ class "inline-flex items-center mt-4 text-xs opacity-50 hover:opacity-90"
@ -72,6 +75,35 @@ viewContent texts flags versionInfo _ model =
]
openIdLinks : Texts -> Flags -> Html Msg
openIdLinks texts flags =
let
renderLink prov =
a
[ href (Api.openIdAuthLink flags prov.provider)
, class S.link
]
[ i [ class "fab fa-openid mr-1" ] []
, text prov.name
]
in
case flags.config.openIdAuth of
[] ->
span [ class "hidden" ] []
provs ->
div [ class "mt-3" ]
[ B.horizontalDivider
{ label = texts.or
, topCss = "w-2/3 mb-4 hidden md:inline-flex w-full"
, labelCss = "px-4 bg-gray-200 bg-opacity-50"
, lineColor = "bg-gray-300 dark:bg-bluegray-600"
}
, div [ class "flex flex-row space-x-4 items-center justify-center" ]
(List.map renderLink provs)
]
otpForm : Texts -> Flags -> Model -> AuthResult -> Html Msg
otpForm texts flags model acc =
Html.form

View File

@ -97,7 +97,7 @@ update flags msg model =
cmd =
if r.success then
Page.goto (LoginPage Nothing)
Page.goto (LoginPage ( Nothing, False ))
else
Cmd.none

View File

@ -232,7 +232,7 @@ viewContent texts flags _ model =
[ text texts.alreadySignedUp
]
, a
[ Page.href (LoginPage Nothing)
[ Page.href (LoginPage ( Nothing, False ))
, class ("ml-2" ++ S.link)
]
[ i [ class "fa fa-user-plus mr-1" ] []