Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit dcf1f50

Browse files
author
mattpass
committed
Handling single user in multi user mode UX and first user is admin
1 parent 3751ea5 commit dcf1f50

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

assets/css/icecoder.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ h2 {font-size: 18px; font-weight: normal; color: #fff}
168168
.screenCenter .text {position: relative; display: block; margin-top: 15px; font-size: 10px; color: #888}
169169
.screenCenter .text input {margin-top: 1px}
170170
.screenCenter .text a {position: relative; display: block; margin-top: 15px; font-size: 10px; color: #888; text-decoration: none}
171+
.screenCenter .adminUser {margin-bottom: 15px; color: #bbb}
171172
.screenCenter .password {border: 0; background-color: #333; color: #fff; height: 20px}
172173
.screenCenter .password:focus {outline: none; background: rgba(0,198,255,0.5); color: #fff}
173174
.screenCenter .button {border: 0; background: #444; color: #eee; height: 22px; cursor: pointer}

lib/login.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,27 @@
1212

1313
$t = $text['login'];
1414

15-
$settingPW = $ICEcoder["enableRegistration"] && ($ICEcoder["multiUser"] || "" === $ICEcoder["password"]);
15+
$settingPW = true === $ICEcoder["enableRegistration"] && (true === $ICEcoder["multiUser"] || "" === $ICEcoder["password"]);
16+
17+
// If multiUser, detect which users we have
18+
if ($ICEcoder["multiUser"]) {
19+
$configUsernames = [];
20+
$handle = opendir('../data/');
21+
while (false !== ($file = readdir($handle))) {
22+
if ($file !== "config-global.php" && 0 === strpos($file, "config-")) {
23+
$configUsernames[explode("-", $file)[1]] = true;
24+
}
25+
}
26+
closedir($handle);
27+
}
1628
?>
1729
<!DOCTYPE html>
1830

1931
<html>
2032
<head>
2133
<title>ICEcoder <?php
2234
echo $ICEcoder["versionNo"] . " : ";
23-
echo $settingPW ? "Setup" : "Login";
35+
echo true === $settingPW ? "Setup" : "Login";
2436
?></title>
2537
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
2638
<meta name="robots" content="noindex, nofollow">
@@ -30,27 +42,37 @@
3042
<link rel="icon" type="image/png" href="../assets/images/favicon.png">
3143
</head>
3244

33-
<body style="background-color: #181817" onLoad="<?php if (false === isset($_GET["get"])) {$inputFocus = true === $ICEcoder["multiUser"] ? "username" : "password"; echo "document.settingsUpdate." . $inputFocus . ".focus(); ";}; ?>setTimeout(function(){document.getElementById('screenContainer').style.opacity = '1'}, 50)">
45+
<body style="background-color: #181817" onLoad="<?php if (false === isset($_GET["get"])) {$inputFocus = true === $ICEcoder["multiUser"] && (true === $ICEcoder["enableRegistration"] || 1 < count($configUsernames)) ? "username" : "password"; echo "document.settingsUpdate." . $inputFocus . ".focus(); ";}; ?>setTimeout(function(){document.getElementById('screenContainer').style.opacity = '1'}, 50)">
3446

3547
<div class="screenContainer" id="screenContainer" style="background-color: #181817; opacity: 0; transition: opacity 0.1s ease-out">
3648
<div class="screenVCenter">
3749
<div class="screenCenter">
3850
<img src="../assets/images/icecoder.png" alt="ICEcoder">
3951
<div class="version" style="margin-bottom: 22px"><?php echo $ICEcoder["versionNo"];?></div>
4052

41-
<form name="settingsUpdate" action="login.php" method="POST"<?php if ($settingPW) {?> onsubmit="return checkCanSubmit();"<?php } ?>>
53+
<form name="settingsUpdate" action="login.php" method="POST"<?php if (true === $settingPW) {?> onsubmit="return checkCanSubmit();"<?php } ?>>
54+
<?php
55+
if (true === $settingPW && false === $ICEcoder["multiUser"]) {
56+
echo '<div class="text adminUser">User: admin</div>';
57+
}
58+
?>
4259
<?php
43-
if ($ICEcoder["multiUser"]) {echo '<input type="text" name="username" class="password"><br><br>';};
60+
// Display username field if multiUser enabled
61+
if (true === $ICEcoder["multiUser"]) {
62+
// Also set value to "admin" if only 1 user (has to be admin)
63+
$showAdminValue = 1 === count($configUsernames) ? ' value="admin"' : '';
64+
echo '<input type="text" name="username"' . $showAdminValue . ' class="password"><br><br>';
65+
};
4466
?>
4567
<input type="password" name="password" class="password" id="password"<?php
46-
if ($settingPW) {
68+
if (true === $settingPW) {
4769
?> onkeyup="checkCase(event); pwStrength(this.value)" onchange="pwStrength(this.value)" onpaste="pwStrength(this.value)"<?php
4870
} else {
4971
?> onkeyup="checkCase(event)"<?php
5072
}
5173
?>><div class="iconCapsLock" style="display: none" id="iconCapsLock" title="Caps lock on"><?php echo file_get_contents(dirname(__FILE__) . "/../assets/images/icons/alert-triangle.svg");?></div><br>
5274
<?php
53-
if ($settingPW) {
75+
if (true === $settingPW) {
5476
echo '<div id="pwReqs">'.
5577
'<div class="text" style="display: inline-block" id="pwChars">10+</div> &nbsp; ' .
5678
'<div class="text" style="display: inline-block" id="pwUpper">upper</div> &nbsp; ' .

lib/settings-screen.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
array_push($themeArray,basename($file,".css"));
3131
}
3232
}
33+
closedir($handle);
3334
sort($themeArray);
3435
for ($i = 0;$i < count($themeArray); $i++) {
3536
echo '<link rel="stylesheet" href="../assets/css/theme/' . $themeArray[$i] . '.css?microtime=' . microtime(true) . '">' . PHP_EOL;

lib/settings.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
include_once dirname(__FILE__) . "/settings-common.php";
5959

6060
// Establish user settings file
61-
$username = "";
61+
$username = "admin-";
6262
if (true === isset($_POST['username']) && "" !== $_POST['username']) {$username = $_POST['username'] . "-";};
6363
if (true === isset($_SESSION['username']) && "" !== $_SESSION['username']) {$username = $_SESSION['username'] . "-";};
6464
$settingsFile = 'config-' . $username . str_replace(".", "_", str_replace("www.", "", $_SERVER['SERVER_NAME'])) . '.php';
@@ -84,6 +84,12 @@
8484

8585
// Check users config settings file exists
8686
if (false === $settingsClass->getConfigUsersFileDetails($settingsFile)['exists']) {
87+
// If on the login page and we couldn't find the file, boot back to login page
88+
if ("login.php" === basename($_SERVER['SCRIPT_NAME'])) {
89+
header('Location: login.php');
90+
echo "<script>window.location = 'login.php';</script>";
91+
die('Redirecting to login...');
92+
}
8793
$reqsFailures = ["phpUsersConfigFileExists"];
8894
include dirname(__FILE__) . "/requirements.php";
8995
}

0 commit comments

Comments
 (0)