Apache-AppSamurai

 view release on metacpan or  search on metacpan

examples/htdocs/login.pl  view on Meta::CPAN

#!/usr/bin/perl
#
# $Id: login.pl,v 1.9 2008/05/03 06:43:24 pauldoom Exp $

# Decide which mod_perl to load
BEGIN {
    use vars qw($MP);
    if (eval{require mod_perl2;}) {
	$MP = 2;
    } else {
	require mod_perl;
	$MP = 1;
    }
}

use strict;
use warnings;
# Use the session key maker and session ID computer (which is just a
# HMAC) for CSRF protection in the login form
use Apache::AppSamurai::Util qw(CreateSessionAuthKey ComputeSessionId
				CheckSidFormat HashPass);


# Point to HTML login page
my $formsource = "login.html";

# Mod_Perl 2 does not chdir to the script's folder, so you must use
# a full path.  The list below includes common base paths.  Remove
# the other array items and enter your local path if none of these
# match you setup.
my @formpaths = ( "/var/www/htdocs/AppSamurai",
		  "/var/www/html/AppSamurai",
		  "/htdocs/AppSamurai",
		  "/html/AppSamurai"
		  );

# This is lame.  Just cycles the paths looking for the form source
# template ($formsource)
my $ffound = 0;
foreach (@formpaths) {
    if (-f "$_/$formsource") {
	$formsource = "$_/$formsource";
	$ffound = 1;
	last;
    }
}

($ffound) or die "FATAL: Could not find form source template file $formsource\n";

# These will replace any __NAME__ values in the form
my %params = ( MESSAGE => '',
	       REASON => '',
               URI => '',
	       FORMACTION => '/AppSamurai/LOGIN',
	       USERNAME => ''
	       );


my $r = shift;
($r) or die "FATAL: NO REQUEST SENT TO SCRIPT!\n";

# if there are args, append that to the uri after checking for and removing
# any ASERRCODE code.
$params{URI} = $r->prev->uri || '';



( run in 1.936 second using v1.01-cache-2.11-cpan-39bf76dae61 )