Re: [Webtek-devel] editing session.user in a form with <% input %> fields
Status: Alpha
Brought to you by:
prozessor13
|
From: max d. <pro...@gm...> - 2008-06-30 10:32:30
|
i solve this problem with an separate user-page.
Page/User.pm
==========================
sub new_for_nickname :Path(user/(\w+)) {
my ($class, $path, $nickname) = @_;
my $user = app::Model::User->find_one(nickname => $nickname);
return $user ? $class->new_for_user($user) : undef;
}
sub new_for_user { ... }
sub index { ... }
sub edit {
my $self = shift;
if (request->is_post) {
$self->user->update(request->params->user);
$self->user->save;
session->user($self);
response->message('User edited');
response->redirect($self->href);
}
}
...
==========================
if you save a user-page in the session you have more power in the
session.user macro. e.g all this things are possible:
<% session.user.template ... %>
<% session.user.nickname ... %>
<% session.user.input name="nickname" ... %>
! but you are right. if you change the user-table layout you have to
drop the session-table! (but this is not very often ;)
On Jun 30, 2008, at 11:55 AM, Adrian Smith wrote:
> I now realize this would not be a good strategy anyway!
>
> If one writes a "my account" screen by using "update" then "save" on
> the session->user, and there is an error, then the page would be
> redisplayed with an error (correct). But the user's attributes have
> been altered, and will get persisted into the sesssion. If the user
> navigates away, and then back to the "my account" page, the user
> will still see the erroneous inputs of last time!
>
> It's necessary, in a "my account" page, to use a separate object-
> instance to edit and try and save. This can be done using a "MyUser-
> >find" in the constructor to retrieve a new instance (not "find_one"
> as this uses a cache.)
>
> In fact I'm not sure it's that clean to store the whole user object
> in the session. Maybe it would be better to just store the "id" and
> the a md5 of the currently entered password. The user could be
> fetched each time, which would mean that the user would still have
> to exist, schema changes would not require the session table to be
> deleted, etc. The md5 of the password would be necessary to check to
> see if the user has changed their password on the server e.g. using
> another session (in which case the first browser session should be
> terminated.) But this is a topic for another thread....
>
>
>
> 2008/6/30 Adrian Smith <adr...@gm...>:
> OK the bug was somewhere else in the template (the error was simply
> that "_can_macro" cannot be called on an undefined value so was
> difficult to locate!)
>
> Now the page will be displayed - which is good - but all the form
> values are blank, if I use handler="session.user" in the <%input%>
> fields. (If I set
>
> $self->user(session->user)
>
> in the constructor, and use handler="user" in the template, then the
> values are displayed.)
>
>
> 2008/6/26 Adrian Smith <adr...@gm...>:
>
> What do you think about this? Is it possible to use "session.user"
> as the "handler" in this sort of syntax? The "user" is a "Handler"
> on the "session" object, so I think I should be able to use it like
> this.
>
> But if it's not possible - then I shall just use another approach -
> e.g.
>
> make_accessor("user", "Handler")
>
> in the page class, and set
>
> $self->user(session->user)
>
> in the constructor. Should also work, I think? (But is less elegant..)
>
> 2008/6/16 Adrian Smith <adr...@gm...>:
>
> The user logs in, and then there is some kind of "my account" screen
> where various pieces of information can be edited by the user. I
> have tried the following syntax:
>
> <% input name="first_name" handler="session.user" %>
>
> However, I get the error (that's possibly unrelated, I'm not sure...)
>
> general error, details: WebTek::Exception: error in
> TariffCalc::Page::SalesPerson::DataEdit=HASH(0x2292420) during
> action 'index': WebTek::Exception: error compiling template .../
> DataEdit/index.tpl, details Can't call method "_can_macro" on an
> undefined value at D:/Adrian/customer-checkouts/webtek/lib/WebTek/
> Compiler.pm line 178.
>
> But the "session.user" should be not undef, as the following
> template works:
>
> <% session.user.email_address_lower %>
>
> How should I approach this situation?
>
> Thanks
>
>
>
|