Prepare remember-me authentication variant

This commit is contained in:
Eike Kettner
2020-12-03 19:45:06 +01:00
parent 07f3e08f35
commit c10c1fad72
15 changed files with 294 additions and 40 deletions

View File

@ -12,6 +12,7 @@ import Page exposing (Page(..))
type alias Model =
{ username : String
, password : String
, rememberMe : Bool
, result : Maybe AuthResult
}
@ -20,6 +21,7 @@ emptyModel : Model
emptyModel =
{ username = ""
, password = ""
, rememberMe = False
, result = Nothing
}
@ -27,5 +29,6 @@ emptyModel =
type Msg
= SetUsername String
| SetPassword String
| ToggleRememberMe
| Authenticate
| AuthResp (Result Http.Error AuthResult)

View File

@ -19,8 +19,18 @@ update referrer flags msg model =
SetPassword str ->
( { model | password = str }, Cmd.none, Nothing )
ToggleRememberMe ->
( { model | rememberMe = not model.rememberMe }, Cmd.none, Nothing )
Authenticate ->
( model, Api.login flags (UserPass model.username model.password) AuthResp, Nothing )
let
userPass =
{ account = model.username
, password = model.password
, rememberMe = Just model.rememberMe
}
in
( model, Api.login flags userPass AuthResp, Nothing )
AuthResp (Ok lr) ->
let

View File

@ -3,7 +3,7 @@ module Page.Login.View exposing (view)
import Data.Flags exposing (Flags)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onInput, onSubmit)
import Html.Events exposing (onCheck, onInput, onSubmit)
import Page exposing (Page(..))
import Page.Login.Data exposing (..)
@ -59,6 +59,19 @@ view flags model =
, i [ class "lock icon" ] []
]
]
, div [ class "field" ]
[ div [ class "ui checkbox" ]
[ input
[ type_ "checkbox"
, onCheck (\_ -> ToggleRememberMe)
, checked model.rememberMe
]
[]
, label []
[ text "Remember Me"
]
]
]
, button
[ class "ui primary fluid button"
, type_ "submit"