Commit 4415be6f authored by Côme Chilliet's avatar Côme Chilliet
Browse files

🚜 feat(login) Moved form handling to LoginPost method

issue #5778
parent 37e67f4b
......@@ -26,79 +26,6 @@ require_once ("variables.inc");
require_once ("class_logging.inc");
header("Content-type: text/html; charset=UTF-8");
/* Display the login page and exit() */
function displayLogin()
{
global $smarty,$message,$config,$ssl,$error_collector,$error_collector_mailto;
$lang = session::global_get('lang');
error_reporting(E_ALL | E_STRICT);
/* Fill template with required values */
$username = '';
if (isset($_POST['username'])) {
$username = trim($_POST['username']);
}
$smarty->assign ('date', gmdate('D, d M Y H:i:s'));
$smarty->assign ('username', $username);
$smarty->assign ('revision', FD_VERSION);
$smarty->assign ('year', date('Y'));
$smarty->append ('css_files', get_template_path('login.css'));
/* Some error to display? */
if (!isset($message)) {
$message = "";
}
$smarty->assign ("message", $message);
/* Display SSL mode warning? */
if (($ssl != '') && ($config->get_cfg_value('warnSSL') == 'TRUE')) {
$smarty->assign ('ssl', sprintf(_('Warning: <a href="%s">Session is not encrypted!</a>'), $ssl));
} else {
$smarty->assign ('ssl', '');
}
if (!$config->check_session_lifetime()) {
$smarty->assign ('lifetime', _('Warning: The session lifetime configured in your fusiondirectory.conf will be overridden by php.ini settings.'));
} else {
$smarty->assign ('lifetime', '');
}
/* Generate server list */
$servers = array();
if (isset($_POST['server'])) {
$selected = $_POST['server'];
} else {
$selected = $config->data['MAIN']['DEFAULT'];
}
foreach ($config->data['LOCATIONS'] as $key => $ignored) {
$servers[$key] = $key;
}
$smarty->assign ("server_options", $servers);
$smarty->assign ("server_id", $selected);
/* show login screen */
$smarty->assign ("PHPSESSID", session_id());
if (session::is_set('errors')) {
$smarty->assign("errors", session::get('errors'));
}
if ($error_collector != "") {
$smarty->assign("php_errors", preg_replace("/%BUGBODY%/", $error_collector_mailto, $error_collector)."</div>");
} else {
$smarty->assign("php_errors", "");
}
$smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
$smarty->assign("usePrototype", "false");
$smarty->assign("date", date("l, dS F Y H:i:s O"));
$smarty->assign("lang", preg_replace('/_.*$/', '', $lang));
$smarty->assign("rtl", Language::isRTL($lang));
$smarty->display (get_template_path('headers.tpl'));
$smarty->assign("version", FD_VERSION);
$smarty->display(get_template_path('login.tpl'));
exit();
}
/*****************************************************************************
* M A I N *
*****************************************************************************/
......@@ -182,8 +109,6 @@ clean_smarty_compile_dir($smarty->compile_dir);
Language::init();
$smarty->assign ('focusfield', 'username');
if (isset($_POST['server'])) {
$server = $_POST['server'];
} else {
......@@ -194,7 +119,8 @@ $config->set_current($server);
if (
($config->get_cfg_value('casActivated') == 'TRUE') ||
($config->get_cfg_value('httpAuthActivated') == 'TRUE') ||
($config->get_cfg_value('httpHeaderAuthActivated') == 'TRUE')) {
($config->get_cfg_value('httpHeaderAuthActivated') == 'TRUE') ||
in_array($config->get_cfg_value('LoginMethod'), array('LoginCas', 'LoginHTTPAuth', 'LoginHTTPHeader'))) {
session::global_set('DEBUGLEVEL', 0);
}
......@@ -221,21 +147,4 @@ if (isset($_REQUEST['message'])) {
}
LoginMethod::loginProcess();
/* Translation of cookie-warning. Whether to display it, is determined by JavaScript */
$smarty->assign ('cookies', '<b>'._('Warning').':</b> '._('Your browser has cookies disabled. Please enable cookies and reload this page before logging in!'));
/* Set focus to the error button if we've an error message */
$focus = '';
if (session::is_set('errors') && session::get('errors') != '') {
$focus = '<script type="text/javascript">';
$focus .= 'document.forms[0].error_accept.focus();';
$focus .= '</script>';
}
$smarty->assign('focus', $focus);
displayLogin();
?>
</body>
</html>
......@@ -32,13 +32,15 @@ class LoginPost extends LoginMethod
/*! \brief All login steps in the right order for standard POST login */
static function loginProcess()
{
global $config, $message;
global $smarty, $config, $message;
static::init();
/* Reset error messages */
$message = '';
$smarty->assign ('focusfield', 'username');
if (($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['login']) && isset($_POST['username']) && isset($_POST['password'])) {
static::$username = $_POST['username'];
......@@ -57,5 +59,92 @@ class LoginPost extends LoginMethod
static::redirect();
}
}
/* Translation of cookie-warning. Whether to display it, is determined by JavaScript */
$smarty->assign('cookies', '<b>'._('Warning').':</b> '._('Your browser has cookies disabled. Please enable cookies and reload this page before logging in!'));
/* Set focus to the error button if we've an error message */
$focus = '';
if (session::is_set('errors') && session::get('errors') != '') {
$focus = '<script type="text/javascript">';
$focus .= 'document.forms[0].error_accept.focus();';
$focus .= '</script>';
}
$smarty->assign('focus', $focus);
static::displayLogin();
}
/*! \brief Display the login page and exit() */
static protected function displayLogin()
{
global $smarty,$message,$config,$ssl,$error_collector,$error_collector_mailto;
$lang = session::global_get('lang');
error_reporting(E_ALL | E_STRICT);
/* Fill template with required values */
$username = '';
if (isset($_POST['username'])) {
$username = trim($_POST['username']);
}
$smarty->assign('date', gmdate('D, d M Y H:i:s'));
$smarty->assign('username', $username);
$smarty->assign('revision', FD_VERSION);
$smarty->assign('year', date('Y'));
$smarty->append('css_files', get_template_path('login.css'));
/* Some error to display? */
if (!isset($message)) {
$message = '';
}
$smarty->assign('message', $message);
/* Display SSL mode warning? */
if (($ssl != '') && ($config->get_cfg_value('warnSSL') == 'TRUE')) {
$smarty->assign('ssl', sprintf(_('Warning: <a href="%s">Session is not encrypted!</a>'), $ssl));
} else {
$smarty->assign('ssl', '');
}
if (!$config->check_session_lifetime()) {
$smarty->assign('lifetime', _('Warning: The session lifetime configured in your fusiondirectory.conf will be overridden by php.ini settings.'));
} else {
$smarty->assign('lifetime', '');
}
/* Generate server list */
$servers = array();
if (isset($_POST['server'])) {
$selected = $_POST['server'];
} else {
$selected = $config->data['MAIN']['DEFAULT'];
}
foreach ($config->data['LOCATIONS'] as $key => $ignored) {
$servers[$key] = $key;
}
$smarty->assign('server_options', $servers);
$smarty->assign('server_id', $selected);
/* show login screen */
$smarty->assign('PHPSESSID', session_id());
if (session::is_set('errors')) {
$smarty->assign('errors', session::get('errors'));
}
if ($error_collector != '') {
$smarty->assign('php_errors', preg_replace('/%BUGBODY%/', $error_collector_mailto, $error_collector).'</div>');
} else {
$smarty->assign('php_errors', '');
}
$smarty->assign('msg_dialogs', msg_dialog::get_dialogs());
$smarty->assign('usePrototype', 'false');
$smarty->assign('date', date('l, dS F Y H:i:s O'));
$smarty->assign('lang', preg_replace('/_.*$/', '', $lang));
$smarty->assign('rtl', Language::isRTL($lang));
$smarty->display(get_template_path('headers.tpl'));
$smarty->assign('version', FD_VERSION);
$smarty->display(get_template_path('login.tpl'));
exit();
}
}
  • SonarQube analysis reported 1 issue

    • 1 info

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. Complete the task associated to this "TODO" comment. 📘
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment