]> gitweb.factorcode.org Git - factor.git/blob - extra/furnace/auth/features/edit-profile/edit-profile.factor
Debugging web framework and cleaning things up
[factor.git] / extra / 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
5 html.forms
6 http.server.dispatchers
7 furnace.auth
8 furnace.asides
9 furnace.actions ;
10 IN: furnace.auth.features.edit-profile
11
12 : <edit-profile-action> ( -- action )
13     <page-action>
14         [
15             logged-in-user get
16             [ username>> "username" set-value ]
17             [ realname>> "realname" set-value ]
18             [ email>> "email" set-value ]
19             tri
20         ] >>init
21
22         { realm "features/edit-profile/edit-profile" } >>template
23
24         [
25             username "username" set-value
26
27             {
28                 { "realname" [ [ v-one-line ] v-optional ] }
29                 { "password" [ ] }
30                 { "new-password" [ [ v-password ] v-optional ] }
31                 { "verify-password" [ [ v-password ] v-optional ] } 
32                 { "email" [ [ v-email ] v-optional ] }
33             } validate-params
34
35             { "password" "new-password" "verify-password" }
36             [ value empty? not ] contains? [
37                 "password" value username check-login
38                 [ "incorrect password" validation-error ] unless
39
40                 same-password-twice
41             ] when
42         ] >>validate
43
44         [
45             logged-in-user get
46
47             "new-password" value dup empty?
48             [ drop ] [ >>encoded-password ] if
49
50             "realname" value >>realname
51             "email" value >>email
52
53             t >>changed?
54
55             drop
56
57             URL" $login" end-aside
58         ] >>submit
59
60     <protected>
61         "edit your profile" >>description ;
62
63 : allow-edit-profile ( login -- login )
64     <edit-profile-action> <auth-boilerplate> "edit-profile" add-responder ;
65
66 : allow-edit-profile? ( -- ? )
67     realm get responders>> "edit-profile" swap key? ;