Skip to content

Commit

Permalink
Fixed #46
Browse files Browse the repository at this point in the history
  • Loading branch information
cmllr committed Dec 20, 2015
1 parent fa64091 commit c5f5b2d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Includes/Kernel/Kernel.Program.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Kernel{
* The programs version
* Structurized in {1.9.X-codenameorbranch-state}
*/
public $Version = "1.10.1-Lenticularis-rc3-0";
public $Version = "1.10.2-Lenticularis-rc3-0";
/**
* The programs release date
*/
Expand Down
2 changes: 0 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
$router = new \Redundancy\Nys\Router();
ob_start();

//Set the cookies if needed
$router->CookieInteraction();
?>
<!DOCTYPE html>

Expand Down
9 changes: 5 additions & 4 deletions nys/Nys.Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ public function LogIn($router){
}
else{
if (!isset($_SESSION['Token'])){
if (isset($_POST["stayloggedin"]) && $_POST["stayloggedin"] == "true")
$_SESSION["StayLoggedIn"] = true;
if (isset($_POST["stayloggedin"]) && $_POST["stayloggedin"] == "true"){
$_SESSION["StayLoggedIn"] = true;
setcookie("r2token",$result);
setcookie("r2lang",$_POST["lang"]);
}
$_SESSION['Token'] = $result;
$_SESSION['Language'] = $_POST['lang'];
}
Expand Down Expand Up @@ -528,7 +531,6 @@ function Changes($router){
* @todo language??
*/
function Share($router){
//$router->SetLanguage("de");
$entry = $GLOBALS['Router']->DoRequest('Kernel.SharingKernel','GetEntryByShareCode',json_encode(array($_GET["c"])));
$shareCode = $_GET["c"];
if (is_null($entry) || is_numeric($entry))
Expand Down Expand Up @@ -779,7 +781,6 @@ public function Upload($router){
* @return an array containg the session data
*/
private function InjectSessionData($router){
$router->SetLanguage(isset($_SESSION['Language']) ? $_SESSION['Language'] : $GLOBALS["Language"]);
$args = array($_SESSION['Token']);
$user = $router->DoRequest('Kernel.UserKernel','GetUser',json_encode($args));
$data = array();
Expand Down
53 changes: 17 additions & 36 deletions nys/Nys.Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,50 +40,31 @@ public function __construct(){
$GLOBALS['Router'] = $this;
$this->controller = new UIController();
if (!isset($_SESSION))
session_start();
session_start();
//Set the cookies if needed
$this->CookieInteraction();

if (isset($_SESSION["lang"]))
$lang = $_SESSION["lang"];
else
$lang = $this->DoRequest('Kernel','GetConfigValue',json_encode(array("Program_Language")));
$this->SetLanguage($lang);
$lang = $this->DoRequest('Kernel','GetConfigValue',json_encode(array("Program_Language")));
$GLOBALS['Language'] = $this->DoRequest('Kernel.InterfaceKernel','SetCurrentLanguage',json_encode(array($lang)));
}
/**
* Interacts with the cookies, creates or deletes them (if needed)
*/
public function CookieInteraction(){
//If the logged in feature is requested, set the cookie
if (isset($_SESSION["StayLoggedIn"])){
setcookie("SessionData", $_SESSION["Token"]);//,time()+5);
setcookie("SessionDataLang", $_SESSION["Language"]);//,time()+5);
unset($_SESSION["StayLoggedIn"]);
}
//If the session cookie is not empty
if (!empty($_COOKIE["SessionData"])){
//If any route except logout is requested and the token is empty, fill it with the values from the cookie
if(!isset($_GET["logout"])){
//only set the token if it is not saved already.
if (!isset($_SESSION["Token"]) ||empty($_SESSION["Token"])){
$_SESSION["Token"] = $_COOKIE["SessionData"];
$_SESSION["Language"] = $_COOKIE["SessionDataLang"];
}
}
else{
//If logout is requested, kill the cookie (SESSION will be killed in Controller)
unset($_COOKIE["SessionData"]);
unset($_COOKIE["SessionDataLang"]);
// empty value and expiration one hour before
setcookie("SessionData", '', time() - 3600);
setcookie("SessionDataLang", '', time() - 3600);
}
}
}
/**
* Sets the global language object
* @param $languageCode the language code to use (e. g. de or en)
*/
public function SetLanguage($languageCode){
$args = array($languageCode);
$GLOBALS['Language'] = $this->DoRequest('Kernel.InterfaceKernel','SetCurrentLanguage',json_encode($args));
if (isset($_COOKIE["r2token"]) && isset($_COOKIE["r2lang"]) && !isset($_GET["logout"]) && !isset($_SESSION["Token"]) && !isset($_SESSION["lang"])){

if (empty($_SESSION)){
$_SESSION["lang"] = filter_input(INPUT_COOKIE, "r2lang");
$_SESSION["Token"] = filter_input(INPUT_COOKIE, "r2token");
}
}
else if (isset($_GET["logout"])){
setcookie("r2lang","", time() -300);
setcookie("r2token","", time() -300);
}
}
/**
* Triggers the logout if the session token is not valid anymore (for example when it is already expired.)
Expand Down

0 comments on commit c5f5b2d

Please sign in to comment.