Re: [Catalyst] Transferring control via root/auto
On 9 Dec 2010, at 14:41, Thompson wrote: How would you use a chained dispatch to solve a problem like this? Something that needs to be checked before allowing anything else (besides logging in) to happen and if so force them to a specific page? A simple example would help. The simplest example I can think of - CatalystX::SimpleLogin provides / login/required and /login/not_required as chain bases. Anything chained from /login/required requires login :) Obviously, displaying the login page is _not_ chained from /login/ required (as otherwise you have the same issue as here) I'm still have it in my head that this logic should be done in the root controller since it would supersede any action in my other controllers. There is nothing special about the root controller that implies this. It's just generally people put the start of their chains in the Root controller. As demonstrated by the above example (with the chain starts in the Login controller), this isn't mandatory. Does this help clarify? Cheers t0m ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Transferring control via root/auto
How would you use a chained dispatch to solve a problem like this? Something that needs to be checked before allowing anything else (besides logging in) to happen and if so force them to a specific page? A simple example would help. I'm still have it in my head that this logic should be done in the root controller since it would supersede any action in my other controllers. Thanks, Rob On 12/8/2010 8:31 AM, Tomas Doran wrote: On 7 Dec 2010, at 16:11, Ben van Staveren wrote: You want to $c->detach('end') -- unless that's the default these days. I use this pattern a lot and the only difference I see is that I do: The end action will _always_ be run, there is no need to detach to the end action. However I'm not sure what doing $c->detach in auto will do (I guess the same as returning 0 - i.e. stop further actions from running), but I'm not sure - you should probably return 0 (to stop further dispatch) rather than detaching in the auto action.. However as noted elsewhere in this thread, I'd seriously recommend using Chained dispatch rather than auto for this (if for no other reason then it avoids the re-entering auto in the next request after you redirect issue). Cheers t0m ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Transferring control via root/auto
On Wednesday, December 08, 2010 07:31:42 am Tomas Doran wrote: > On 7 Dec 2010, at 16:11, Ben van Staveren wrote: > > You want to $c->detach('end') -- unless that's the default these > > days. I use this pattern a lot and the only difference I see is that > > > I do: > The end action will _always_ be run, there is no need to detach to the > end action. > > However I'm not sure what doing $c->detach in auto will do (I guess > the same as returning 0 - i.e. stop further actions from running), but > I'm not sure - you should probably return 0 (to stop further dispatch) > rather than detaching in the auto action.. Since auto is internally just another step in _DISPATCH (Catalyst gets to it by calling forward and everything) detaching from it behaves as you'd expect -- the action you detach to is run, and so is end, and the current dispatch (including the rest of auto and running $c->action) is abandoned. So, possibly there are *cleaner* ways to deal with situations like that (often involving Chained), but if you want to do it, it shouldn't break on you. Andrew ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Transferring control via root/auto
Actualy I find that diagram to pretty much stick to the basic rules. His auto code is the problem. While he's redirecting to the change password, he is also re-entering auto. And, most probably the conditions are met. A pretty straight forward solution is to do something like: if ($c->user_exists()&& $c->check_any_user_role('User') && $c->user->changePassword ) { + return 1 if $c->action->reverse eq 'users/loginedit'; $c->res->redirect($c->uri_for($c->controller('Users')->action_for('loginedit'), [$c->user->id] )); $c->detach(); On Wed, Dec 8, 2010 at 6:49 PM, Ashley Pond V wrote: > On Wed, Dec 8, 2010 at 6:59 AM, Larry Leszczynski > wrote: >> >> In situations like this I find this flow diagram helpful: >> >> >> http://dev.catalystframework.org/attachment/wiki/WikiStart/catalyst-flow.png >> >> but I admit I am also not totally clear about how detach/go fit in... >> Maybe someone has an updated diagram (or can update this one)? > > I did that diagram a loong time ago (2006?). I'd be glad > to amend it and I can see obvious changes it needs but I'd probably > need input from core devs to round it out "perfectly." > > -Ashley > > ___ > List: Catalyst@lists.scsys.co.uk > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ > Dev site: http://dev.catalyst.perl.org/ > -- Cosmin Budrica Developer @ www.sinapticode.com ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Transferring control via root/auto
On Wed, Dec 8, 2010 at 6:59 AM, Larry Leszczynski wrote: > > In situations like this I find this flow diagram helpful: > > http://dev.catalystframework.org/attachment/wiki/WikiStart/catalyst-flow.png > > but I admit I am also not totally clear about how detach/go fit in... > Maybe someone has an updated diagram (or can update this one)? I did that diagram a loong time ago (2006?). I'd be glad to amend it and I can see obvious changes it needs but I'd probably need input from core devs to round it out "perfectly." -Ashley ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Transferring control via root/auto
Hi - On Wed, 08 Dec 2010 13:31 +, "Tomas Doran" wrote: > > On 7 Dec 2010, at 16:11, Ben van Staveren wrote: > > > You want to $c->detach('end') -- unless that's the default these > > days. > > The end action will _always_ be run, there is no need to detach to the > end action. > > However I'm not sure what doing $c->detach in auto will do (I guess > the same as returning 0 - i.e. stop further actions from running), but > I'm not sure - you should probably return 0 (to stop further dispatch) > rather than detaching in the auto action.. In situations like this I find this flow diagram helpful: http://dev.catalystframework.org/attachment/wiki/WikiStart/catalyst-flow.png but I admit I am also not totally clear about how detach/go fit in... Maybe someone has an updated diagram (or can update this one)? Thanks! Larry ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Transferring control via root/auto
On 7 Dec 2010, at 16:11, Ben van Staveren wrote: You want to $c->detach('end') -- unless that's the default these days. I use this pattern a lot and the only difference I see is that I do: The end action will _always_ be run, there is no need to detach to the end action. However I'm not sure what doing $c->detach in auto will do (I guess the same as returning 0 - i.e. stop further actions from running), but I'm not sure - you should probably return 0 (to stop further dispatch) rather than detaching in the auto action.. However as noted elsewhere in this thread, I'd seriously recommend using Chained dispatch rather than auto for this (if for no other reason then it avoids the re-entering auto in the next request after you redirect issue). Cheers t0m ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Transferring control via root/auto
your redirect will make "auto" be executed again and redirecting again to loginedit On Tue, Dec 7, 2010 at 1:53 PM, Thompson wrote: > Here is my problem, > > If a user logs in for the 1st time I want to force them to change their > password. I have a specific action in my Users controller to handle > that. What I'm having a problem with is (redirecting or forwarding or > detaching - i've tried them all) from the root/auto function to my > specific controller function. I either get an internal server error or > page isn't redirecting properly, depending what i use. I've put my > logic in the root/auto because regardless of the request changing their > password is mandatory. > > Here is my current root/auto using redirect. > > sub auto : Private { > my ($self, $c) = @_; > > if ($c->user_exists()&& $c->check_any_user_role('User') > && $c->user->changePassword ) { > > $c->res->redirect($c->uri_for($c->controller('Users')->action_for('loginedit'), > > [$c->user->id] )); > $c->detach(); > } > > return 1; > } > > Any help would be appreciated. > Rob T > > ___ > List: Catalyst@lists.scsys.co.uk > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > Searchable archive: > http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ > Dev site: http://dev.catalyst.perl.org/ > ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Transferring control via root/auto
On Tue, Dec 7, 2010 at 4:53 PM, Thompson wrote: > Here is my problem, > > If a user logs in for the 1st time I want to force them to change their > password. I have a specific action in my Users controller to handle > that. What I'm having a problem with is (redirecting or forwarding or > detaching - i've tried them all) from the root/auto function to my > specific controller function. I either get an internal server error or > page isn't redirecting properly, depending what i use. I've put my > logic in the root/auto because regardless of the request changing their > password is mandatory. > > Here is my current root/auto using redirect. > > sub auto : Private { > my ($self, $c) = @_; > > if ($c->user_exists()&& $c->check_any_user_role('User') > && $c->user->changePassword ) { > > $c->res->redirect($c->uri_for($c->controller('Users')->action_for('loginedit'), > [$c->user->id] )); > $c->detach(); > } > > return 1; > } > > Any help would be appreciated. > Rob T > > ___ > List: Catalyst@lists.scsys.co.uk > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ > Dev site: http://dev.catalyst.perl.org/ > I wouldn't put that into an auto method. I remember t0m saying that you can use Chained Dispatchtype instead of auto most of the time. Anyways, the error message of your devel server would sure help finding the problem. david ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Transferring control via root/auto
You want to $c->detach('end') -- unless that's the default these days. I use this pattern a lot and the only difference I see is that I do: $c->detach('end') and return 0; $c->res->redirect($c->uri_for($c->controller('Users')->action_for('loginedit'), [$c->user->id] )); $c->detach(); -- Ben van Staveren phone: +62 81 70777529 email: benvanstave...@gmail.com ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Transferring control via root/auto
Here is my problem, If a user logs in for the 1st time I want to force them to change their password. I have a specific action in my Users controller to handle that. What I'm having a problem with is (redirecting or forwarding or detaching - i've tried them all) from the root/auto function to my specific controller function. I either get an internal server error or page isn't redirecting properly, depending what i use. I've put my logic in the root/auto because regardless of the request changing their password is mandatory. Here is my current root/auto using redirect. sub auto : Private { my ($self, $c) = @_; if ($c->user_exists()&& $c->check_any_user_role('User') && $c->user->changePassword ) { $c->res->redirect($c->uri_for($c->controller('Users')->action_for('loginedit'), [$c->user->id] )); $c->detach(); } return 1; } Any help would be appreciated. Rob T ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/