CGI::Session::Auth::Mouse::Role - Role for authentication of CGI::Session Module
This document describes CGI::Session::Auth::Mouse::Role version 0.0.3
BEGIN { package MyApp::Auth; use Mouse; with qw/CGI::Session::Auth::Mouse::Role/; has '_user_key' => ( is => 'rw', isa => 'Str', ); has 'user_info' => ( is => 'ro', isa => 'HashRef', default => sub { return { hoge => { password => 'huga', age => 20, favorite => 'orange', }, moge => { password => 'moga', age => 30, favorite => 'apple', } }; }, ); sub login { my $self = shift; my ( $username, $password ) = @_; if ( exists $self->user_info->{$username} ) { $self->user_key($username); return 1 if ( $self->user_info->{$username}->{password} eq $password ); } return; } sub load_profile { my ( $self, $user_key ) = @_; my $info = $self->user_info->{ $user_key }; delete $info->{password}; return $info; # hashref } sub user_key { my $self = shift; return $self->_user_key || 0; } } my $auth = MyApp::Auth->new( cgi => new CGI, session => new Session, ); $auth->authenticate(); if ( $auth->logged_in ) { ## show secret page } else { ## show login page }
<form method="POST" action="sample.cgi"> <input type="text" name="login_username" /> <input type="password" name="login_password" /> <input type="submit" value="submit" /> </form>
authenticate method
Returns a boolean value representing the current visitors authentication status.
logout method
Please report any bugs or feature requests to bug-cgi-session-auth-mouse-role@rt.cpan.org, or through the web interface at http://rt.cpan.org.
bug-cgi-session-auth-mouse-role@rt.cpan.org
Mouse Mouse::Role CGI::Session
CGI::Session CGI::Session::Auth Mouse Mouse::Role
<noblejasper> <<nobjas@gmail.com>>
<<nobjas@gmail.com>>
Copyright (c) 2009, <noblejasper> <<nobjas@gmail.com>>. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
To install CGI::Session::Auth::Mouse::Role, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CGI::Session::Auth::Mouse::Role
CPAN shell
perl -MCPAN -e shell install CGI::Session::Auth::Mouse::Role
For more information on module installation, please visit the detailed CPAN module installation guide.