Compare commits

..

5 commits

8 changed files with 94 additions and 8 deletions

1
example/data/sessions/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
sess_*

View file

@ -102,8 +102,12 @@ i18n:
# Session # Session
# #
session: session:
timeout: 1800 # Session timeout dur to inactivity (in seconds) # Session timeout due to inactivity (in seconds)
max_duration: 43200 # Session max duration (in seconds, default : 12h) timeout: 1800
# Session max duration (in seconds, default : 12h)
max_duration: 43200
# Directory path where to store PHP sessions data (optional, default: use system default)
directory_path: "${data_directory}/sessions"
# #
# Database configuration # Database configuration
@ -143,7 +147,7 @@ db:
# #
auth: auth:
# Enabled authentication # Enabled authentication
enabled: false enabled: true
# Methods to authenticate users # Methods to authenticate users
methods: methods:
@ -153,12 +157,15 @@ auth:
# User backends # User backends
backends: backends:
- ldap - db
# #
# Login form # Login form
# #
login_form: login_form:
# Include application navbar (default: true)
include_navbar: true
# Display link for other authentication methods # Display link for other authentication methods
# Note: method as key and label as value # Note: method as key and label as value
display_other_methods: display_other_methods:
@ -219,6 +226,30 @@ auth:
# CAS Fake authenticated user # CAS Fake authenticated user
#fake_authenticated_user: 'myusername' #fake_authenticated_user: 'myusername'
#
# Database user backend
#
db:
# DSN (required)
dsn: "${db.dsn}"
# Username (optional but could be required with some PDO drivers)
user: "${db.user}"
# Password (optional)
password: "${db.password}"
# PDO options (optional)
options: "${db.options}"
# Users table name (optional, default: users)
users_table: "users"
# Username field name (optional, default: username)
username_field: "username"
# Password field name (optional, default: password)
password_field: "password"
# Exposed users table fields in resulting EesyPHP\Auth\User object
# (optional, defailt: name, mail)
exposed_fields:
- "name"
- "mail"
# #
# LDAP user backend # LDAP user backend
# #

View file

@ -102,8 +102,12 @@ i18n:
# Session # Session
# #
session: session:
timeout: 1800 # Session timeout dur to inactivity (in seconds) # Session timeout due to inactivity (in seconds)
max_duration: 43200 # Session max duration (in seconds, default : 12h) timeout: 1800
# Session max duration (in seconds, default : 12h)
max_duration: 43200
# Directory path where to store PHP sessions data (optional, default: use system default)
directory_path: "${data_directory}/sessions"
# #
# Database configuration # Database configuration
@ -159,6 +163,9 @@ auth:
# Login form # Login form
# #
login_form: login_form:
# Include application navbar (default: true)
include_navbar: true
# Display link for other authentication methods # Display link for other authentication methods
# Note: method as key and label as value # Note: method as key and label as value
display_other_methods: display_other_methods:
@ -219,6 +226,30 @@ auth:
# CAS Fake authenticated user # CAS Fake authenticated user
#fake_authenticated_user: 'myusername' #fake_authenticated_user: 'myusername'
#
# Database user backend
#
db:
# DSN (required)
dsn: "${db.dsn}"
# Username (optional but could be required with some PDO drivers)
user: "${db.user}"
# Password (optional)
password: "${db.password}"
# PDO options (optional)
options: "${db.options}"
# Users table name (optional, default: users)
#users_table: "users"
# Username field name (optional, default: username)
#username_field: "username"
# Password field name (optional, default: password)
#password_field: "password"
# Exposed users table fields in resulting EesyPHP\Auth\User object
# (optional, defailt: name, mail)
#exposed_fields:
# - "name"
# - "mail"
# #
# LDAP user backend # LDAP user backend
# #

1
skel/data/sessions/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
sess_*

View file

@ -84,6 +84,10 @@ class Db extends Backend {
) )
); );
self :: $dsn = App::get('auth.db.dsn', null, 'string'); self :: $dsn = App::get('auth.db.dsn', null, 'string');
if (!self :: $dsn) {
Log :: warning('No database DSN configured, can not initialize this authentication backend');
return false;
}
self :: $user = App::get('auth.db.user', null, 'string'); self :: $user = App::get('auth.db.user', null, 'string');
self :: $password = App::get('auth.db.password', null, 'string'); self :: $password = App::get('auth.db.password', null, 'string');
self :: $options = App::get('auth.db.options', null, 'array'); self :: $options = App::get('auth.db.options', null, 'array');
@ -91,7 +95,7 @@ class Db extends Backend {
self :: $username_field = App::get('auth.db.username_field', null, 'string'); self :: $username_field = App::get('auth.db.username_field', null, 'string');
self :: $password_field = App::get('auth.db.password_field', null, 'string'); self :: $password_field = App::get('auth.db.password_field', null, 'string');
self :: $exposed_fields = App::get('auth.db.exposed_fields', null, 'array'); self :: $exposed_fields = App::get('auth.db.exposed_fields', null, 'array');
return boolval(self :: $dsn); return true;
} }
/** /**

View file

@ -21,6 +21,7 @@ class Form extends Method {
'auth.login_form', 'auth.login_form',
array( array(
'display_other_methods' => array(), 'display_other_methods' => array(),
'include_navbar' => true,
) )
); );
Url :: add_url_handler('#^login$#', array('EesyPHP\\Auth\\Form', 'handle_login'), null, false); Url :: add_url_handler('#^login$#', array('EesyPHP\\Auth\\Form', 'handle_login'), null, false);
@ -69,6 +70,7 @@ class Form extends Method {
else else
Tpl :: assign('next', (isset($_REQUEST['next'])?urldecode($_REQUEST['next']):'')); Tpl :: assign('next', (isset($_REQUEST['next'])?urldecode($_REQUEST['next']):''));
Tpl :: assign('display_other_methods', $display_other_methods); Tpl :: assign('display_other_methods', $display_other_methods);
Tpl :: assign('include_navbar', App::get('auth.login_form.include_navbar', null, 'bool'));
Tpl :: display('login.tpl', I18n::_('Sign in')); Tpl :: display('login.tpl', I18n::_('Sign in'));
} }

View file

@ -30,6 +30,7 @@ class Session {
array( array(
'max_duration' => 43200, // 12h 'max_duration' => 43200, // 12h
'timeout' => null, 'timeout' => null,
'directory_path' => null,
) )
); );
@ -38,6 +39,16 @@ class Session {
Config :: ini_set('session.gc_maxlifetime', strval(self :: $max_duration)); Config :: ini_set('session.gc_maxlifetime', strval(self :: $max_duration));
Config :: ini_set('session.cookie_lifetime', strval(self :: $max_duration)); Config :: ini_set('session.cookie_lifetime', strval(self :: $max_duration));
// Set custom session directory (if configured)
$directory_path = App::get('session.directory_path', null, 'string');
if ($directory_path) {
Log :: trace('Set session directory path as "%s"', $directory_path);
if (!session_save_path($directory_path)) {
Log :: warning('Fail to set session directory path as "%s"', $directory_path);
}
}
Log :: debug('Use session directory "%s"', session_save_path());
// Start session // Start session
session_start(); session_start();

View file

@ -1,9 +1,14 @@
{extends file='Tpl:empty.tpl'} {extends file='Tpl:empty.tpl'}
{if !$include_navbar}
{block name="navbar"}{/block}
{/if}
{block name="pagetitle"}{/block} {block name="pagetitle"}{/block}
{block name="content"} {block name="main"}
<main class="form-signin w-100 m-auto text-center"> <main class="form-signin w-100 m-auto text-center">
<form action="login" method="POST"> <form action="login" method="POST">
{if !$include_navbar}
<img class="mb-4" src="{static_url path="images/logo.svg"}" alt="" width="100"> <img class="mb-4" src="{static_url path="images/logo.svg"}" alt="" width="100">
{/if}
<h1 class="h3 mb-3 fw-normal">{t domain=$CORE_TEXT_DOMAIN}Sign in{/t}</h1> <h1 class="h3 mb-3 fw-normal">{t domain=$CORE_TEXT_DOMAIN}Sign in{/t}</h1>
{include file='Tpl:errors.tpl'} {include file='Tpl:errors.tpl'}