package LATMOS::Accounts::Web;

use strict;
use warnings;
no utf8;

use Catalyst::Runtime '5.70';

# Set flags and add plugins for the application
#
#         -Debug: activates the debug mode for very useful log messages
#   ConfigLoader: will load the configuration from a YAML file in the
#                 application's home directory
# Static::Simple: will serve static files from the application's root 
#                 directory

use Catalyst qw/
    ConfigLoader
    Static::Simple
    Session
    Session::State::Cookie
    Session::Store::File
    Authentication
    I18N
    /;

our $VERSION = '6.1.0';

# Configure the application. 
__PACKAGE__->config(
    encoding => 'UTF-8',
    'Plugin::I18N' => {
        'maketext_options' => {
            Decode => 1
        }
    }
);

# Default value for active/inactive features
__PACKAGE__->config(
    features => {
        # /services/mailing, mass mailing
        mailing => 0,
        # /summary/offices
        offices_list => 0,
        # /summary/department
        departments_list => 0,
        # users/address forms
        user_addresses => 1,
        # users/email form
        user_email => 1,
        # users/my form
        user_my => 1,
        # user status managed by employment
        user_employment => 0,
        # others informations about user
        user_add => 0,
    }
);

__PACKAGE__->config(
    objects => {
        user => {
            quick_search => [ qw(cn sn givenName description comment uidNumber) ],
            list => [ qw(sn givenName mail) ],
        },
        group => {
            quick_search => [ qw(cn description comment gidNumber) ],
            list => [ qw(description) ],
        },
        nethost => {
            quick_search => [ qw(cn description ip cname otherName macaddr serialNumber inventoryNumber) ],
            list => [ qw(description owner) ],
        },
        netzone => {
            quick_search => [ qw(cn description ip) ],
            list => [ qw(type description) ],
        },
        site => {
            quick_search => [ qw(cn l) ],
            list => [ qw(l) ],
        },
        aliases => {
            quick_search => [ qw(name) ],
            list => [ qw() ],
        },
    },
);

my $config_file = '/etc/latmos-accounts/latmos-accounts-web.yml';
if (-r $config_file ) {
    __PACKAGE__->config( 'Plugin::ConfigLoader' => { 
            file => $config_file 
        } 
    );
}

# http://stackoverflow.com/questions/1664816/is-there-a-way-to-force-c-urifor-in-catalyst-to-generate-a-uri-that-begins-wit
__PACKAGE__->config( using_frontend_proxy => 1 );

__PACKAGE__->config( name => 'LATMOS::Accounts::Web' );

__PACKAGE__->config->{'Plugin::Authentication'} = {
    default_realm => 'la',
    realms => {
        la => {
            credential => {
                class => 'La'
            },
            store => {
                class => 'Null',
            },
        },
    },
};

# 1 week for session
__PACKAGE__->config->{'Plugin::Session'} = {
    expires => 3600 * 24 * 30
};


# Start the application
__PACKAGE__->setup;


=head1 NAME

LATMOS::Accounts::Web - Catalyst based application

=head1 SYNOPSIS

    script/latmos_accounts_web_server.pl

=head1 DESCRIPTION

[enter your description here]

=head1 SEE ALSO

L<LATMOS::Accounts::Web::Controller::Root>, L<Catalyst>

=head1 AUTHOR

Thauvin Olivier

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;
