]> gitweb.factorcode.org Git - factor.git/blob - basis/furnace/auth/features/registration/registration.factor
7f73f0c4045370bde1bc16e10ccfd4eb5f23e928
[factor.git] / basis / furnace / auth / features / registration / registration.factor
1 ! Copyright (c) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs kernel namespaces validators html.forms urls
4 http.server.dispatchers
5 furnace.auth furnace.auth.providers furnace.actions
6 furnace.redirection ;
7 IN: furnace.auth.features.registration
8
9 : <register-action> ( -- action )
10     <page-action>
11         { realm "features/registration/register" } >>template
12
13         [
14             {
15                 { "username" [ v-username ] }
16                 { "realname" [ [ v-one-line ] v-optional ] }
17                 { "new-password" [ v-password ] }
18                 { "verify-password" [ v-password ] }
19                 { "email" [ [ v-email ] v-optional ] }
20                 { "captcha" [ v-captcha ] }
21             } validate-params
22
23             same-password-twice
24         ] >>validate
25
26         [
27             "username" value <user>
28                 "realname" value >>realname
29                 "new-password" value >>encoded-password
30                 "email" value >>email
31                 H{ } clone >>profile
32
33             users new-user [ user-exists ] unless*
34
35             realm get init-user-profile
36             realm get user-registered
37         ] >>submit
38     <auth-boilerplate>
39     <secure-realm-only> ;
40
41 : allow-registration ( realm -- realm )
42     <register-action> "register" add-responder ;
43
44 : allow-registration? ( -- ? )
45     realm get responders>> "register" swap key? ;