<%doc>
# 
# $Id: login.ipfc,v 1.4 2002/02/13 17:25:52 fpmip Exp $
#
# login.ipfc checks login credentials and sets up the session for a user

# Authors : Tycho Fruru <tycho@fruru.com>
# Copyright (C) 2001, 2002 Tycho Fruru <tycho@fruru.com>
# Copyright (C) 2001, 2002 Conostix S.A. Luxembourg - Tycho Fruru <tycho@conostix.com>

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
</%doc><%args>
$session
</%args>

<%perl>
use DBI;
my $dbh = $m->comp("db-connect.ipfc");
my $userid = $r->connection->user;
my $sth = $dbh->prepare("select login_name,fullname,email from users ".
		"where login_name = ? and user_enabled = 't' and ".
		      "start_date < now() and now() < end_date");
$sth->execute($userid) or $m->abort("Getting user information failed !");
my ($login_name,$fullname,$email) = $sth->fetchrow_array;

if (defined($login_name) && ($login_name eq $userid)) {
	$session->{'authenticated'}=1;
	$session->{'userid'}=$login_name;
	$session->{'userfullname'}=$fullname;
	$session->{'email'}=$email;
} else {
	$session->{'authenticated'}=0;
}

return $session;
</%perl>
