1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
module User.PassReset exposing (main)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Json.Encode as JE
import Browser
import Lib.Api as Api
import Gen.Api as GApi
import Gen.UserEdit as GUE
import Lib.Html exposing (..)
main : Program () Model Msg
main = Browser.element
{ init = always (init, Cmd.none)
, subscriptions = always Sub.none
, view = view
, update = update
}
type alias Model =
{ email : String
, state : Api.State
, success : Bool
}
init : Model
init =
{ email = ""
, state = Api.Normal
, success = False
}
encodeForm : Model -> JE.Value
encodeForm o = JE.object
[ ("email", JE.string o.email) ]
type Msg
= EMail String
| Submit
| Submitted GApi.Response
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
EMail n -> ({ model | email = n }, Cmd.none)
Submit -> ( { model | state = Api.Loading }
, Api.post "/u/newpass" (encodeForm model) Submitted )
Submitted GApi.Success -> ({ model | success = True }, Cmd.none)
Submitted e -> ({ model | state = Api.Error e }, Cmd.none)
view : Model -> Html Msg
view model =
if model.success
then
div [ class "mainbox" ]
[ h1 [] [ text "New password" ]
, div [ class "notice" ]
[ p [] [ text "Your password has been reset and instructions to set a new one should reach your mailbox in a few minutes." ] ]
]
else
form_ Submit (model.state == Api.Loading)
[ div [ class "mainbox" ]
[ h1 [] [ text "Forgot Password" ]
, p []
[ text "Forgot your password and can't login to VNDB anymore? "
, text "Don't worry! Just give us the email address you used to register on VNDB "
, text " and we'll send you instructions to set a new password within a few minutes!"
]
, table [ class "formtable" ]
[ formField "email::E-Mail" [ inputText "email" model.email EMail GUE.valEmail ]
]
]
, div [ class "mainbox" ]
[ fieldset [ class "submit" ] [ submitButton "Submit" model.state True ]
]
]
|