1 ! Copyright (c) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: namespaces make accessors kernel assocs arrays io.sockets
4 threads fry urls smtp validators html.forms present http
5 http.server.responses http.server.redirection
6 http.server.dispatchers furnace.actions furnace.auth
7 furnace.auth.providers furnace.redirection furnace.utilities ;
8 IN: furnace.auth.features.recover-password
10 SYMBOL: lost-password-from
12 : current-host ( -- string )
13 url get host>> host-name or ;
15 : new-password-url ( user -- url )
18 [ username>> "username" set-query-param ]
19 [ ticket>> "ticket" set-query-param ]
23 : password-email ( user -- email )
25 [ "[ " % current-host % " ] password recovery" % ] "" make >>subject
26 lost-password-from get >>from
27 over email>> 1array >>to
29 "This e-mail was sent by the application server on " % current-host % "\n" %
30 "because somebody, maybe you, clicked on a “recover password” link in the\n" %
31 "login form, and requested a new password for the user named ``" %
32 over username>> % "''.\n" %
34 "If you believe that this request was legitimate, you may click the below link in\n" %
35 "your browser to set a new password for your account:\n" %
37 swap new-password-url present %
44 : send-password-email ( user -- )
45 '[ _ password-email send-email ]
46 "E-mail send thread" spawn drop ;
48 : <recover-action-1> ( -- action )
50 { realm "features/recover-password/recover-1" } >>template
54 { "username" [ v-username ] }
55 { "email" [ v-email ] }
56 { "captcha" [ v-captcha ] }
61 "email" value "username" value
66 URL" $realm/recover-2" <redirect>
69 : <recover-action-2> ( -- action )
71 { realm "features/recover-password/recover-2" } >>template ;
73 : <recover-action-3> ( -- action )
77 { "username" [ v-username ] }
78 { "ticket" [ v-required ] }
82 { realm "features/recover-password/recover-3" } >>template
86 { "username" [ v-username ] }
87 { "ticket" [ v-required ] }
88 { "new-password" [ v-password ] }
89 { "verify-password" [ v-password ] }
99 "new-password" value >>encoded-password
102 URL" $realm/recover-4" <redirect>
108 : <recover-action-4> ( -- action )
110 { realm "features/recover-password/recover-4" } >>template ;
112 : allow-password-recovery ( realm -- realm )
113 <recover-action-1> <auth-boilerplate>
114 "recover-password" add-responder
115 <recover-action-2> <auth-boilerplate>
116 "recover-2" add-responder
117 <recover-action-3> <auth-boilerplate>
118 "recover-3" add-responder
119 <recover-action-4> <auth-boilerplate>
120 "recover-4" add-responder ;
122 : allow-password-recovery? ( -- ? )
123 realm get responders>> "recover-password" swap key? ;