[dancer-users] route handler for a URL that matches a token

Andrew Solomon andrew at geekuni.com
Wed Sep 16 22:46:29 BST 2015


Hi Richard

Firstly with the GET request when you click on this

 http://myapp.com/reset/JiOk49ld9oekdisJkflSS3ed
<http://myapp.com/resetJiOk49ld9oekdisJkflSS3ed>

your route handler will be something like this (note ':' instead of '$'):

get '/reset/:token' => sub {

  return template 'pass_reset' => {
    token => params->{token}
  };

};

This template views/pass_reset.tt will contain something like

<form action="/reset/[% token %]" method="post">
  <input type="password" name="password1"><br/>
  <input type="password" name="password2"><br/>
  <input type="submit" value="Submit">
</form>


and back in the controller on clicking submit, it will be handled by

post '/reset/:token' => sub {

   # do something to check params->{password1} eq params->{password2} ...

};


(Please imagine the code above is scribbled on a blackboard - I haven't run
it:)

Andrew

On Wed, Sep 16, 2015 at 10:26 PM, Richard Reina <gatorreina at gmail.com>
wrote:

> Forgive me for being clueless, but can someone tell me how I can have
> route handler for a URL that matches a token. Such that a user can receive
> an email that says:
>
> Go here to reset your password
> http://myapp.com/resetJiOk49ld9oekdisJkflSS3ed (where
> JiOk49ld9oekdisJkflSS3ed is the token ) and then dancer would bring them to
> the template where they can reset their password.
>
> I can't seem to wrap my mind around how such a thing would work.
>
> get '/reset/'$token => sub {
>
>    template 'pass_reset';
>
> }
>
> post '/reset/'$token => sub { # let user reset password
>
>    my $input_hash = {
>
>        Pswd => param('password1'),
>        PswdConfirm => param('password2'),
>
>    };
>
> template 'pass_reset';
>
> };
>
> Any help would be greatly appreciated.
>
> Thanks
>
> _______________________________________________
> dancer-users mailing list
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>
>


-- 
Andrew Solomon

Mentor at Geekuni http://geekuni.com/
http://www.linkedin.com/in/asolomon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150916/2cade187/attachment.html>


More information about the dancer-users mailing list