<div dir="ltr"><div>I found the source of the problem, and it still leaves me hanging.</div><div><br></div><div><br></div>For some hideous reason, if I redirect after making the request for the users json data, the session is undef in the main application. However, if I don't redirect. Then goto the homepage from the browser, it accesses my session! :S<div>
<br></div><div><br></div><div><div>my $jresp = $browser->get("<a href="https://api.github.com/user?access_token=$acc">https://api.github.com/user?access_token=$acc</a>");</div><div>my $json = decode_json($jresp->decoded_content);</div>
<div>$dsl->session(github_user => $json); #also tested by just setting a string instead of json!<br></div><div>$dsl->session(github_access_token => $acc);<br></div><div>return "done"; #This works fine! </div>
<div>#but if I # return $dsl->redirect("/"); #it doesn't work !<br></div></div><div><br></div><div><br></div><div>And worst of all, if I take your code and do this:</div><div><br></div><div><span style="font-family:arial,sans-serif;font-size:13px"> my $controller = sub { $dsl->session(user => "Yippikiayeeeh");</span><br style="font-family:arial,sans-serif;font-size:13px">
<span style="font-family:arial,sans-serif;font-size:13px"> return $dsl->redirect("/");};</span><br></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div>
<span style="font-family:arial,sans-serif;font-size:13px">it works! but for me it doesn't me. The session goes undef.</span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">I tried it with a YAML backend and the default (simple session)</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, Oct 4, 2013 at 4:14 AM, Cymon <span dir="ltr"><<a href="mailto:cymon.ML@gmail.com" target="_blank">cymon.ML@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I wrote a code similar to yours and it works for me.<br>
<br>
Here the routes:<br>
<br>
package Test;<br>
use Dancer2;<br>
use Dancer2::Plugin::Dummy;<br>
<div class="im"><br>
get '/' => sub {<br>
<br>
if (not defined(session->read('user'))) {<br>
</div> return "No user"<br>
}<br>
else<br>
{<br>
return "User is here"<br>
}<br>
};<br>
<br>
1;<br>
<br>
Here the dummy plugin:<br>
<br>
package Dancer2::Plugin::Dummy;<br>
use Dancer2::Plugin;<br>
<div class="im"><br>
on_plugin_import {<br>
my $dsl = shift;<br>
</div> my $controller = sub { $dsl->session(user => "Yippikiayeeeh");<br>
return "You have a user now!"};<br>
$dsl->any(['get'] => '/populate/session', $controller); };<br>
<br>
register_plugin for_versions => [ 2 ];<br>
<br>
<br>
If I go to populate/session and the on the home I can see user<br>
populated.<br>
<br>
What kind of session manager are you using? Are you sure it's working<br>
well?<br>
<br>
Cymon<br>
<a href="http://perlishscrewdriver.blogspot.it/" target="_blank">http://perlishscrewdriver.blogspot.it/</a><br>
<br>
<br>
<br>
<br>
<br>
Il giorno Fri, 4 Oct 2013 00:36:23 +0530<br>
<div class="HOEnZb"><div class="h5">"Gideon D'souza" <<a href="mailto:gidisrael@gmail.com">gidisrael@gmail.com</a>> ha scritto:<br>
<br>
> Tried it, It still goes into a redirect loop because the session is<br>
> always undef the sub for "/".<br>
><br>
> :( I'd really appreciate anyone just peeing into this!<br>
><br>
><br>
> On Tue, Oct 1, 2013 at 4:48 AM, Slavik Goltser <<a href="mailto:slavikg@gmail.com">slavikg@gmail.com</a>><br>
> wrote:<br>
><br>
> > Doesn't that get ignored in Dancer2?<br>
> ><br>
> ><br>
> > On Mon, Sep 30, 2013 at 6:51 PM, Cymon <<a href="mailto:cymon.ML@gmail.com">cymon.ML@gmail.com</a>> wrote:<br>
> ><br>
> >> Hi,<br>
> >> i tried your code.<br>
> >><br>
> >> Did you remember to add:<br>
> >><br>
> >> register_plugin for_versions => [ 2 ];<br>
> >><br>
> >> at the end of the plugin?<br>
> >> It will not work without this.<br>
> >><br>
> >> Cymon<br>
> >> <a href="http://perlishscrewdriver.blogspot.it/" target="_blank">http://perlishscrewdriver.blogspot.it/</a><br>
> >><br>
> >> Il giorno Sun, 29 Sep 2013 22:55:05 +0530<br>
> >> "Gideon D'souza" <<a href="mailto:gidisrael@gmail.com">gidisrael@gmail.com</a>> ha scritto:<br>
> >><br>
> >> > Thank you very much for your time.<br>
> >> ><br>
> >> > I tried it. No luck still.<br>
> >> ><br>
> >> > If I may bother you so:<br>
> >> ><br>
> >> > on_plugin_import {<br>
> >> > my $dsl = shift;<br>
> >> > my $controller = sub { ...; ...; $dsl->session(user =><br>
> >> > $some_json);} $dsl->any(['get'] => '/your/path', $controller);<br>
> >> > }<br>
> >> ><br>
> >> > in app that uses this plugin:<br>
> >> ><br>
> >> > get '/' => sub {<br>
> >> ><br>
> >> > if (not defined(session->read('user'))) {<br>
> >> > ######<br>
> >> > #session->Read('user') is always undef!!!<br>
> >> > ######<br>
> >> > return redirect auth_github_authenticate_url;<br>
> >> > }<br>
> >> > };<br>
> >> ><br>
> >> > Any clues here?<br>
> >> ><br>
> >> ><br>
> >> > On Sun, Sep 29, 2013 at 6:49 PM, Cymon <<a href="mailto:cymon.ML@gmail.com">cymon.ML@gmail.com</a>><br>
> >> > wrote:<br>
> >> ><br>
> >> > ><br>
> >> > > ><br>
> >> > > > Is there a way to add routes inside a plugin, on init or<br>
> >> > > > something like that? Or perhaps it's something else I've<br>
> >> > > > missed?<br>
> >> > > ><br>
> >> > > > Any reply or pointers appreciated.<br>
> >> > ><br>
> >> > > Hi,<br>
> >> > > I have no time to try your code now and help you with your<br>
> >> > > issue, but I can answer this.<br>
> >> > ><br>
> >> > > To add routes inside a plugin just define the on_plugin_import<br>
> >> > > sub in your plugin package as this.<br>
> >> > ><br>
> >> > > on_plugin_import {<br>
> >> > > my $dsl = shift;<br>
> >> > > my $controller = sub { ...do things ... }<br>
> >> > > $dsl->any(['get'] => '/your/path', $controller);<br>
> >> > > }<br>
> >> > ><br>
> >> > ><br>
> >> > > --<br>
> >> > > Cymon<br>
> >> > > <a href="http://perlishscrewdriver.blogspot.it/" target="_blank">http://perlishscrewdriver.blogspot.it/</a><br>
> >> > > _______________________________________________<br>
> >> > > dancer-users mailing list<br>
> >> > > <a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
> >> > > <a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
> >> > ><br>
> >><br>
> >><br>
> >> --<br>
> >> Cymon<br>
> >> Coniglio domina,<br>
> >> <a href="http://www.therabbit.it" target="_blank">http://www.therabbit.it</a><br>
> >> _______________________________________________<br>
> >> dancer-users mailing list<br>
> >> <a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
> >> <a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
> >><br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > dancer-users mailing list<br>
> > <a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
> > <a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
> ><br>
> ><br>
<br>
<br>
--<br>
Cymon<br>
Coniglio domina,<br>
<a href="http://www.therabbit.it" target="_blank">http://www.therabbit.it</a><br>
_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
</div></div></blockquote></div><br></div>