fork download
  1. #!/usr/bin/perl
  2. # your code goes here
  3.  
  4. # Relevant routes
  5. my $if_login = $r->under('/')->to('user#is_logged_in');
  6. $if_login->post('/logout')->name('on_logout')->to('user#on_logout');
  7.  
  8. # Controller functions
  9. sub on_logout {
  10. my $self = shift;
  11. $self->session(expires => 1);
  12.  
  13. return $self->render(json => '{success: "true"}');
  14. }
  15.  
  16. sub is_logged_in {
  17. my $self = shift;
  18.  
  19. say $self->session('username'); # Sometimes after on_logout this is still
  20. # defined and equal to the username.
  21. return 1 if($self->session('username'));
  22.  
  23. $self->render(
  24. template => 'permission/not_logged_in',
  25. status => 403
  26. );
  27. }
  28.  
  29. # Front end
  30. <a href="" onclick='do_logout();'>
  31. <%= l('Log out') %>
  32. </a>
  33.  
  34. <script>
  35. function do_logout() {
  36. $.post( "<%= url_for('on_logout') %>", function() {
  37. }).fail(function() {
  38. alert( "error logging out" );
  39. }).done(function( data ) {
  40. alert( "Data: " + data );
  41. }).always(function() {
  42. alert( "finished" );
  43. });
  44. }
  45. </script>
  46.  
Runtime error #stdin #stdout #stderr 0s 20336KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Bareword found where operator expected at prog.pl line 32, near "%= l"
	(Missing operator before l?)
Semicolon seems to be missing at prog.pl line 35.
Bareword found where operator expected at prog.pl line 37, near "$.post"
	(Missing operator before post?)
syntax error at prog.pl line 32, near "%= l"
Execution of prog.pl aborted due to compilation errors.