initial support for auto login of guest user

This commit is contained in:
Uwe Steinmann 2016-01-29 16:48:21 +01:00
parent 7140b12357
commit 7dc478382f
4 changed files with 40 additions and 21 deletions

View File

@ -12,6 +12,10 @@
* @version Release: @package_version@
*/
require_once("inc.Utils.php");
require_once("inc.ClassEmailNotify.php");
require_once("inc.ClassSession.php");
$refer = $_SERVER["REQUEST_URI"];
if (!strncmp("/op", $refer, 3)) {
$refer="";
@ -19,39 +23,45 @@ if (!strncmp("/op", $refer, 3)) {
$refer = urlencode($refer);
}
if (!isset($_COOKIE["mydms_session"])) {
header("Location: " . $settings->_httpRoot . "out/out.Login.php?referuri=".$refer);
exit;
}
require_once("inc.Utils.php");
require_once("inc.ClassEmailNotify.php");
require_once("inc.ClassSession.php");
/* Load session */
$dms_session = $_COOKIE["mydms_session"];
$session = new SeedDMS_Session($db);
if(!$resArr = $session->load($dms_session)) {
setcookie("mydms_session", $dms_session, time()-3600, $settings->_httpRoot); //delete cookie
header("Location: " . $settings->_httpRoot . "out/out.Login.php?referuri=".$refer);
exit;
if($settings->_enableGuestLogin && $settings->_enableGuestAutoLogin) {
require_once("../inc/inc.ClassSession.php");
$session = new SeedDMS_Session($db);
if(!$dms_session = $session->create(array('userid'=>$settings->_guestID, 'theme'=>$settings->_theme, 'lang'=>$settings->_language))) {
header("Location: " . $settings->_httpRoot . "out/out.Login.php?referuri=".$refer);
exit;
}
$resArr = $session->load($dms_session);
} else {
header("Location: " . $settings->_httpRoot . "out/out.Login.php?referuri=".$refer);
exit;
}
} else {
/* Load session */
$dms_session = $_COOKIE["mydms_session"];
$session = new SeedDMS_Session($db);
if(!$resArr = $session->load($dms_session)) {
setcookie("mydms_session", $dms_session, time()-3600, $settings->_httpRoot); //delete cookie
header("Location: " . $settings->_httpRoot . "out/out.Login.php?referuri=".$refer);
exit;
}
}
/* Update last access time */
$session->updateAccess($dms_session);
/* Load user data */
/* Load user data */
$user = $dms->getUser($resArr["userID"]);
if($user->isAdmin()) {
if($resArr["su"]) {
$user = $dms->getUser($resArr["su"]);
}
}
if (!is_object($user)) {
setcookie("mydms_session", $dms_session, time()-3600, $settings->_httpRoot); //delete cookie
header("Location: " . $settings->_httpRoot . "out/out.Login.php?referuri=".$refer);
exit;
}
if($user->isAdmin()) {
if($resArr["su"]) {
$user = $dms->getUser($resArr["su"]);
}
}
$dms->setUser($user);
if($settings->_enableEmail) {
$notifier = new SeedDMS_EmailNotify();

View File

@ -38,6 +38,8 @@ class Settings { /* {{{ */
var $_rootFolderID = 1;
// If you want anybody to login as guest, set the following line to true
var $_enableGuestLogin = false;
// If you even want guest to be logged in automatically, set the following to true
var $_enableGuestAutoLogin = false;
// Allow users to reset their password
var $_enablePasswordForgotten = false;
// Minimum password strength (0 - x, 0 means no check)
@ -382,6 +384,7 @@ class Settings { /* {{{ */
$node = $xml->xpath('/configuration/system/authentication');
$tab = $node[0]->attributes();
$this->_enableGuestLogin = Settings::boolVal($tab["enableGuestLogin"]);
$this->_enableGuestAutoLogin = Settings::boolVal($tab["enableGuestAutoLogin"]);
$this->_enablePasswordForgotten = Settings::boolVal($tab["enablePasswordForgotten"]);
$this->_passwordStrength = intval($tab["passwordStrength"]);
$this->_passwordStrengthAlgorithm = strval($tab["passwordStrengthAlgorithm"]);
@ -655,6 +658,7 @@ class Settings { /* {{{ */
// XML Path: /configuration/system/authentication
$node = $this->getXMLNode($xml, '/configuration/system', 'authentication');
$this->setXMLAttributValue($node, "enableGuestLogin", $this->_enableGuestLogin);
$this->setXMLAttributValue($node, "enableGuestAutoLogin", $this->_enableGuestAutoLogin);
$this->setXMLAttributValue($node, "enablePasswordForgotten", $this->_enablePasswordForgotten);
$this->setXMLAttributValue($node, "passwordStrength", $this->_passwordStrength);
$this->setXMLAttributValue($node, "passwordStrengthAlgorithm", $this->_passwordStrengthAlgorithm);

View File

@ -101,6 +101,7 @@ if ($action == "saveSettings")
// SETTINGS - SYSTEM - AUTHENTICATION
$settings->_enableGuestLogin = getBoolValue("enableGuestLogin");
$settings->_enableGuestAutoLogin = getBoolValue("enableGuestAutoLogin");
$settings->_restricted = getBoolValue("restricted");
$settings->_enableUserImage = getBoolValue("enableUserImage");
$settings->_disableSelfEdit = getBoolValue("disableSelfEdit");

View File

@ -346,6 +346,10 @@ if(!is_writeable($settings->_configFilePath)) {
<td><?php printMLText("settings_enableGuestLogin");?>:</td>
<td><input name="enableGuestLogin" type="checkbox" <?php if ($settings->_enableGuestLogin) echo "checked" ?> /></td>
</tr>
<tr title="<?php printMLText("settings_enableGuestAutoLogin_desc");?>">
<td><?php printMLText("settings_enableGuestAutoLogin");?>:</td>
<td><input name="enableGuestAutoLogin" type="checkbox" <?php if ($settings->_enableGuestAutoLogin) echo "checked" ?> /></td>
</tr>
<tr title="<?php printMLText("settings_restricted_desc");?>">
<td><?php printMLText("settings_restricted");?>:</td>
<td><input name="restricted" type="checkbox" <?php if ($settings->_restricted) echo "checked" ?> /></td>