]> gitweb.factorcode.org Git - factor.git/blob - basis/furnace/auth/features/edit-profile/edit-profile.factor
Factor source files should not be executable
[factor.git] / basis / furnace / auth / features / edit-profile / edit-profile.factor
1 ! Copyright (c) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel accessors namespaces sequences assocs
4 validators urls html.forms http.server.dispatchers
5 furnace.auth
6 furnace.asides
7 furnace.actions ;
8 IN: furnace.auth.features.edit-profile
9
10 : <edit-profile-action> ( -- action )
11     <page-action>
12         [
13             logged-in-user get
14             [ username>> "username" set-value ]
15             [ realname>> "realname" set-value ]
16             [ email>> "email" set-value ]
17             tri
18         ] >>init
19
20         { realm "features/edit-profile/edit-profile" } >>template
21
22         [
23             username "username" set-value
24
25             {
26                 { "realname" [ [ v-one-line ] v-optional ] }
27                 { "password" [ ] }
28                 { "new-password" [ [ v-password ] v-optional ] }
29                 { "verify-password" [ [ v-password ] v-optional ] } 
30                 { "email" [ [ v-email ] v-optional ] }
31             } validate-params
32
33             { "password" "new-password" "verify-password" }
34             [ value empty? not ] any? [
35                 "password" value username check-login
36                 [ "incorrect password" validation-error ] unless
37
38                 same-password-twice
39             ] when
40         ] >>validate
41
42         [
43             logged-in-user get
44
45             "new-password" value
46             [ >>encoded-password ] unless-empty
47
48             "realname" value >>realname
49             "email" value >>email
50
51             t >>changed?
52
53             drop
54
55             URL" $realm" end-aside
56         ] >>submit
57
58     <protected>
59         "edit your profile" >>description ;
60
61 : allow-edit-profile ( realm -- realm )
62     <edit-profile-action> <auth-boilerplate> "edit-profile" add-responder ;
63
64 : allow-edit-profile? ( -- ? )
65     realm get responders>> "edit-profile" swap key? ;