Skip to content

Latest commit

 

History

History
59 lines (42 loc) · 1.61 KB

Logout.md

File metadata and controls

59 lines (42 loc) · 1.61 KB

Logout

This is a very short page to show you how to make sure you've logged out of your application.

lib/SessionTutorial.pm

Just looking at one file this time. Not bothering to put the code into a controller.

  $r->route('/logout')->name('do_logout')->to(cb => sub {
    my $self = shift;
    
    $self->session(expires => 1);

    $self->redirect_to('/');
  });

Expire the session and then return the user to the home page.

You can make that easier for the user by adding a link to the protected page, templates/tutorial/protected.html.ep

<h2>Test the Logout</h2>
Click here to 
%= link_to Logout => '/logout'

Try it out

Start the server with

morbo script/session_tutorial

and click through the Login link on localhost:3000/ to get to the Login page

Test the app

Make sure we can maintain sessions and the session is removed when the user visits /logout. Add a file t/02_logout.t to check that the protected page is accessible only to successful logged in users.

script/session_tutorial test 

Next Step

The bare bones are in place. The next step is to secure the passwords flying across the net. Instructions continue in HTTPS.

More information

Detail on sessions can be found in the online documentation. More on forms and logins can be found on Oliver Günther's Applications with Mojolicious