Hi Philippe,

On 20/01/12 11:30 AM, DOMINEAUX Philippe wrote:
> Hello,
> 
> When we create a guest account in the Guest manage page the guests
> accounts created use the email address as username.
> 
> Is it possible to use firstname dot lastname as username instead.
> 

Yes, it's possible but it's not a configuration parameter. Code is required.

>  
> 
> Do I need to modify the /lib/pf/web/guest.pm page to do that?
> 

Actually, it's preferable to put custom code in pf/web/custom.pm because
this file is not overwritten by doing a package upgrade while all the
others are.

Basically, add this to the custom.pm file inside the no warnings
redefine block:


package pf::web::guest;
*pf::web::guest::preregister = sub {
    my ($cgi, $session) = @_;
    my $logger = Log::Log4perl::get_logger('pf::web::guest');

    setlocale( LC_MESSAGES, pf::web::web_get_locale($cgi, $session) );
    bindtextdomain( "packetfence", "$conf_dir/locale" );
    textdomain("packetfence");

    # Login successful, adding person (using modify in case person
already exists)
    my $pid = $session->param("firstname") . "." .
$session->param("lastname");
    person_modify($pid, (
        'firstname' => $session->param("firstname"),
        'lastname' => $session->param("lastname"),
        'email' => $session->param("email"),
        'telephone' => $session->param("phone"),
        'company' => $session->param("company"),
        'address' => $session->param("address"),
        'notes' => $session->param("notes").". ".sprintf(i18n("Expected
on %s"), $session->param("arrival_date")),
        'sponsor' => $session->param("username")
    ));
    $logger->info("Adding guest person $pid");

    # expiration is arrival date + access duration + a tolerance window
of 24 hrs
    my $expiration = POSIX::strftime("%Y-%m-%d %H:%M:%S",
        localtime(str2time($session->param("arrival_date")) +
$session->param("access_duration") + 24*60*60)
    );

    # we create temporary password with the expiration and a 'not valid
before' value
    my $password = pf::temporary_password::generate(
        $pid, $expiration, $session->param("arrival_date"),
        valid_access_duration($session->param("access_duration"))
    );

    # failure, redirect to error page
    if (!defined($password)) {
        pf::web::generate_error_page( $cgi, $session, "error: something
went wrong creating the guest" );
    }

    # on success
    return $password;
};

For reference: it's a copy the preregister sub from pf/web/guest.pm
slightly modified to do your bidding.

Does anyone else feels that it should be configurable?

Let us know how it goes.
-- 
Olivier Bilodeau
[email protected]  ::  +1.514.447.4918 *115  ::  www.inverse.ca
Inverse inc. :: Leaders behind SOGo (www.sogo.nu) and PacketFence
(www.packetfence.org)

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Packetfence-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/packetfence-users

Reply via email to