factor/basis/furnace/auth/features/edit-profile/edit-profile.factor

66 lines
1.8 KiB
Factor
Raw Normal View History

2008-06-16 04:34:17 -04:00
! Copyright (c) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel accessors namespaces sequences assocs
2008-07-10 00:41:45 -04:00
validators urls html.forms http.server.dispatchers
2008-06-16 04:34:17 -04:00
furnace.auth
furnace.asides
furnace.actions ;
2008-06-16 04:34:17 -04:00
IN: furnace.auth.features.edit-profile
: <edit-profile-action> ( -- action )
<page-action>
[
logged-in-user get
[ username>> "username" set-value ]
[ realname>> "realname" set-value ]
[ email>> "email" set-value ]
tri
] >>init
{ realm "features/edit-profile/edit-profile" } >>template
[
username "username" set-value
2008-06-16 04:34:17 -04:00
{
{ "realname" [ [ v-one-line ] v-optional ] }
{ "password" [ ] }
{ "new-password" [ [ v-password ] v-optional ] }
{ "verify-password" [ [ v-password ] v-optional ] }
{ "email" [ [ v-email ] v-optional ] }
} validate-params
{ "password" "new-password" "verify-password" }
[ value empty? not ] contains? [
"password" value username check-login
2008-06-16 04:34:17 -04:00
[ "incorrect password" validation-error ] unless
same-password-twice
] when
] >>validate
[
logged-in-user get
2008-09-06 20:13:59 -04:00
"new-password" value
[ >>encoded-password ] unless-empty
2008-06-16 04:34:17 -04:00
"realname" value >>realname
"email" value >>email
t >>changed?
drop
2008-07-10 00:41:45 -04:00
URL" $realm" end-aside
2008-06-16 04:34:17 -04:00
] >>submit
<protected>
"edit your profile" >>description ;
2008-11-16 08:41:27 -05:00
: allow-edit-profile ( realm -- realm )
2008-06-16 04:34:17 -04:00
<edit-profile-action> <auth-boilerplate> "edit-profile" add-responder ;
: allow-edit-profile? ( -- ? )
2008-06-16 04:46:54 -04:00
realm get responders>> "edit-profile" swap key? ;