Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
issue #97 modification of session timeout mechanism
Browse files Browse the repository at this point in the history
Now session timeout worked =)
And it is described in config file and no possibility to set it for each user differently.
Furthermore added setting of session store path.
  • Loading branch information
Ovsyanka committed Dec 11, 2015
1 parent c7e1f42 commit b9cd970
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 26 deletions.
6 changes: 3 additions & 3 deletions app/classes/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function onBefore() {

//if auth is disabled
if ($server && !$server->mongoAuth() && !$server->controlAuth()) {
MUser::login("rockmongo_memo", "rockmongo_memo", xi("host"), "admin", 10800);
MUser::login("rockmongo_memo", "rockmongo_memo", xi("host"), "admin");
$this->_admin = MUser::userInSession();
}
else {
Expand Down Expand Up @@ -139,10 +139,10 @@ protected function _convertValue($mongodb, $dataType, $format, $value, $integerV
case "long":
if (class_exists("MongoInt64")) {
$realValue = new MongoInt64($longValue);
}
}
else {
$realValue = $longValue;
}
}
break;
case "float":
case "double":
Expand Down
6 changes: 1 addition & 5 deletions app/controllers/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ public function doIndex() {
$this->db = trim(xn("db"));
$this->hostIndex = xi("host");
$this->languages = rock_load_languages();
$this->expires = array(
3 => "3 " . rock_lang("hours"),
720 => "1 " . rock_lang("month"),
);
$this->moreOptions = xi("more");

if ($this->isPost()) {
Expand All @@ -44,7 +40,7 @@ public function doIndex() {

//remember user
import("models.MUser");
MUser::login($this->username, $password, $this->hostIndex, $this->db, xi("expire") * 3600);
MUser::login($this->username, $password, $this->hostIndex, $this->db);

//remember lang
setcookie("ROCK_LANG", x("lang"), time() + 365 * 86400);
Expand Down
8 changes: 1 addition & 7 deletions app/models/MUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class MUser {
private $_password;
private $_hostIndex;
private $_db;
private $_timeout;

public function __construct() {

Expand Down Expand Up @@ -63,10 +62,6 @@ public function dbs() {
return preg_split("/\\s*,\\s*/", $this->_db);
}

public function setTimeout($timeout) {
$this->_timeout = $timeout;
}

/**
* Validate User
*
Expand All @@ -90,14 +85,13 @@ public function changeHost($hostIndex) {
$_SESSION["login"]["index"] = $hostIndex;
}

public static function login($username, $password, $hostIndex, $db, $timeout) {
public static function login($username, $password, $hostIndex, $db) {
$_SESSION["login"] = array(
"username" => $username,
"password" => $password,
"index" => $hostIndex,
"db" => $db
);
setcookie(session_name(), session_id(), time() + $timeout);
}

/**
Expand Down
14 changes: 13 additions & 1 deletion config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@
* Defining default options and server configuration
* @package rockmongo
*/


// session store configurating

// Timeuot of session in seconds
ini_set('session.gc_maxlifetime', 60*60*3); //3 hours

// this defines, where session files will be stored.
// it is important in this case: http://php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime
$currentSessionPath = ini_get('session.save_path');
$save_path = $currentSessionPath . DIRECTORY_SEPARATOR . 'rockmongo';
if (!is_dir($save_path)) mkdir($save_path, 0777, true);
ini_set('session.save_path', $save_path);

$MONGO = array();
$MONGO["features"]["log_query"] = "on";//log queries
$MONGO["features"]["theme"] = "default";//theme
Expand Down
10 changes: 0 additions & 10 deletions themes/default/views/login/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,6 @@ function r_show_more_options(btn) {
<?php endforeach;?>
</select></td>
</tr>
<tr>
<td><?php hm("alive"); ?>:</td>
<td>
<select name="expire" style="width:150px">
<?php foreach ($expires as $long => $name):?>
<option value="<?php h($long);?>"><?php h($name);?></option>
<?php endforeach;?>
</select>
</td>
</tr>
</tbody>
<tr>
<td colspan="2" align="center"><input type="submit" value="<?php hm("loginandrock"); ?>"/></td>
Expand Down

0 comments on commit b9cd970

Please sign in to comment.