Skip to content

Commit 89889dc

Browse files
committed
Refactor process_login_request 10: Invert if / unwrap else.
1 parent 3878d84 commit 89889dc

File tree

1 file changed

+65
-64
lines changed

1 file changed

+65
-64
lines changed

interface/web/login/index.php

Lines changed: 65 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -98,73 +98,74 @@ function process_login_request(app $app, &$error, $conf, $module)
9898
$user = validate_and_fetch_user($app, $username, $password, $loginAs, $conf);
9999

100100
if ($user) {
101-
if ($user['active'] == 1) {
102-
// Maintenance mode - allow logins only when maintenance mode is off or if the user is admin
103-
if (!$app->is_under_maintenance() || $user['typ'] == 'admin') {
104-
105-
// User login right, so attempts can be deleted
106-
$sql = "DELETE FROM `attempts_login` WHERE `ip`=?";
107-
$app->db->query($sql, $ip);
108-
$user = $app->db->toLower($user);
109-
110-
if ($loginAs) $oldSession = $_SESSION['s'];
111-
112-
// Session regenerate causes login problems on some systems, see Issue #3827
113-
// Set session_regenerate_id to no in security settings, it you encounter
114-
// this problem.
115-
$app->uses('getconf');
116-
$security_config = $app->getconf->get_security_config('permissions');
117-
if (isset($security_config['session_regenerate_id']) && $security_config['session_regenerate_id'] == 'yes') {
118-
if (!$loginAs) session_regenerate_id(true);
119-
}
120-
$_SESSION = array();
121-
if ($loginAs) $_SESSION['s_old'] = $oldSession; // keep the way back!
122-
$_SESSION['s']['user'] = $user;
123-
$_SESSION['s']['user']['theme'] = isset($user['app_theme']) ? $user['app_theme'] : 'default';
124-
$_SESSION['s']['language'] = $app->functions->check_language($user['language']);
125-
$_SESSION["s"]['theme'] = $_SESSION['s']['user']['theme'];
126-
if ($loginAs) $_SESSION['s']['plugin_cache'] = $_SESSION['s_old']['plugin_cache'];
127-
128-
if (is_file(ISPC_WEB_PATH.'/'.$_SESSION['s']['user']['startmodule'].'/lib/module.conf.php')) {
129-
include_once $app->functions->check_include_path(ISPC_WEB_PATH.'/'.$_SESSION['s']['user']['startmodule'].'/lib/module.conf.php');
130-
$menu_dir = ISPC_WEB_PATH.'/'.$_SESSION['s']['user']['startmodule'].'/lib/menu.d';
131-
include_menu_dir_files($menu_dir);
132-
$_SESSION['s']['module'] = $module;
133-
}
134-
// check if the user theme is valid
135-
if ($_SESSION['s']['user']['theme'] != 'default') {
136-
$tmp_path = ISPC_THEMES_PATH."/".$_SESSION['s']['user']['theme'];
137-
if (!@is_dir($tmp_path) || !@file_exists($tmp_path."/ispconfig_version") || trim(file_get_contents($tmp_path."/ispconfig_version")) != ISPC_APP_VERSION) {
138-
// fall back to default theme if this one is not compatible with current ispc version
139-
$_SESSION['s']['user']['theme'] = 'default';
140-
$_SESSION['s']['theme'] = 'default';
141-
$_SESSION['show_error_msg'] = $app->lng('theme_not_compatible');
142-
}
143-
}
101+
if ($user['active'] != 1) {
102+
$error = $app->lng('error_user_blocked');
103+
return;
104+
}
144105

145-
$app->plugin->raiseEvent('login', $username);
146-
147-
//* Save successful login message to var
148-
$authlog = 'Successful login for user \''.$username.'\' from '.$_SERVER['REMOTE_ADDR'].' at '.date('Y-m-d H:i:s').' with session ID '.session_id();
149-
$authlog_handle = fopen($conf['ispconfig_log_dir'].'/auth.log', 'a');
150-
fwrite($authlog_handle, $authlog."\n");
151-
fclose($authlog_handle);
152-
153-
/*
154-
* We need LOGIN_REDIRECT instead of HEADER_REDIRECT to load the
155-
* new theme, if the logged-in user has another
156-
*/
157-
158-
if ($loginAs) {
159-
echo 'LOGIN_REDIRECT:'.$_SESSION['s']['module']['startpage'];
160-
exit;
161-
} else {
162-
header('Location: ../index.php');
163-
die();
106+
// Maintenance mode - allow logins only when maintenance mode is off or if the user is admin
107+
if (!$app->is_under_maintenance() || $user['typ'] == 'admin') {
108+
109+
// User login right, so attempts can be deleted
110+
$sql = "DELETE FROM `attempts_login` WHERE `ip`=?";
111+
$app->db->query($sql, $ip);
112+
$user = $app->db->toLower($user);
113+
114+
if ($loginAs) $oldSession = $_SESSION['s'];
115+
116+
// Session regenerate causes login problems on some systems, see Issue #3827
117+
// Set session_regenerate_id to no in security settings, it you encounter
118+
// this problem.
119+
$app->uses('getconf');
120+
$security_config = $app->getconf->get_security_config('permissions');
121+
if (isset($security_config['session_regenerate_id']) && $security_config['session_regenerate_id'] == 'yes') {
122+
if (!$loginAs) session_regenerate_id(true);
123+
}
124+
$_SESSION = array();
125+
if ($loginAs) $_SESSION['s_old'] = $oldSession; // keep the way back!
126+
$_SESSION['s']['user'] = $user;
127+
$_SESSION['s']['user']['theme'] = isset($user['app_theme']) ? $user['app_theme'] : 'default';
128+
$_SESSION['s']['language'] = $app->functions->check_language($user['language']);
129+
$_SESSION["s"]['theme'] = $_SESSION['s']['user']['theme'];
130+
if ($loginAs) $_SESSION['s']['plugin_cache'] = $_SESSION['s_old']['plugin_cache'];
131+
132+
if (is_file(ISPC_WEB_PATH.'/'.$_SESSION['s']['user']['startmodule'].'/lib/module.conf.php')) {
133+
include_once $app->functions->check_include_path(ISPC_WEB_PATH.'/'.$_SESSION['s']['user']['startmodule'].'/lib/module.conf.php');
134+
$menu_dir = ISPC_WEB_PATH.'/'.$_SESSION['s']['user']['startmodule'].'/lib/menu.d';
135+
include_menu_dir_files($menu_dir);
136+
$_SESSION['s']['module'] = $module;
137+
}
138+
// check if the user theme is valid
139+
if ($_SESSION['s']['user']['theme'] != 'default') {
140+
$tmp_path = ISPC_THEMES_PATH."/".$_SESSION['s']['user']['theme'];
141+
if (!@is_dir($tmp_path) || !@file_exists($tmp_path."/ispconfig_version") || trim(file_get_contents($tmp_path."/ispconfig_version")) != ISPC_APP_VERSION) {
142+
// fall back to default theme if this one is not compatible with current ispc version
143+
$_SESSION['s']['user']['theme'] = 'default';
144+
$_SESSION['s']['theme'] = 'default';
145+
$_SESSION['show_error_msg'] = $app->lng('theme_not_compatible');
164146
}
165147
}
166-
} else {
167-
$error = $app->lng('error_user_blocked');
148+
149+
$app->plugin->raiseEvent('login', $username);
150+
151+
//* Save successful login message to var
152+
$authlog = 'Successful login for user \''.$username.'\' from '.$_SERVER['REMOTE_ADDR'].' at '.date('Y-m-d H:i:s').' with session ID '.session_id();
153+
$authlog_handle = fopen($conf['ispconfig_log_dir'].'/auth.log', 'a');
154+
fwrite($authlog_handle, $authlog."\n");
155+
fclose($authlog_handle);
156+
157+
/*
158+
* We need LOGIN_REDIRECT instead of HEADER_REDIRECT to load the
159+
* new theme, if the logged-in user has another
160+
*/
161+
162+
if ($loginAs) {
163+
echo 'LOGIN_REDIRECT:'.$_SESSION['s']['module']['startpage'];
164+
exit;
165+
} else {
166+
header('Location: ../index.php');
167+
die();
168+
}
168169
}
169170
} else {
170171
if (!$alreadyfailed['times']) {

0 commit comments

Comments
 (0)