NAME
CGI::Session::Auth::Mouse::Role - Role for authentication of CGI::Session Module
VERSION
This document describes CGI::Session::Auth::Mouse::Role version 0.0.3
SYNOPSIS
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
}
SAMPLE HTML
<form method="POST" action="sample.cgi">
<input type="text" name="login_username" />
<input type="password" name="login_password" />
<input type="submit" value="submit" />
</form>
METHODS
- authenticate
-
authenticate method
- logged_in
-
Returns a boolean value representing the current visitors authentication status.
- logout
-
logout method
BUGS AND LIMITATIONS
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.
DEPENDENCIES
Mouse Mouse::Role CGI::Session
SEE ALSO
CGI::Session CGI::Session::Auth Mouse Mouse::Role
AUTHOR
<noblejasper> <<nobjas@gmail.com>>
LICENCE AND COPYRIGHT
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.