diff options
-rw-r--r-- | index.php | 30 | ||||
-rw-r--r-- | lib/user.php | 15 |
2 files changed, 38 insertions, 7 deletions
diff --git a/index.php b/index.php index 52a00465f22..3c8a0e3bed6 100644 --- a/index.php +++ b/index.php @@ -59,13 +59,37 @@ elseif(OC_User::isLoggedIn()) { } } +// Semeone set remember login when login +elseif(isset($_COOKIE["oc_remember_login"]) && $_COOKIE["oc_remember_login"]) { + OC_App::loadApps(); + error_log("Trying to login from cookie"); + if(OC_User::login($_COOKIE["oc_username"], $_COOKIE["oc_password"])) { + header("Location: ". $WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php")); + if(!empty($_POST["remember_login"])){ + OC_User::setUsernameInCookie($_POST["user"], $_POST["password"]); + } + else { + OC_User::unsetUsernameInCookie(); + } + exit(); + } + else { + if(isset($_COOKIE["username"])){ + OC_Template::printGuestPage("", "login", array("error" => true, "username" => $_COOKIE["username"])); + }else{ + OC_Template::printGuestPage("", "login", array("error" => true)); + } + } +} + // Someone wants to log in : elseif(isset($_POST["user"]) && isset($_POST['password'])) { OC_App::loadApps(); if(OC_User::login($_POST["user"], $_POST["password"])) { header("Location: ".$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php")); if(!empty($_POST["remember_login"])){ - OC_User::setUsernameInCookie($_POST["user"]); + error_log("Setting remember login to cookie"); + OC_User::setUsernameInCookie($_POST["user"], $_POST["password"]); } else { OC_User::unsetUsernameInCookie(); @@ -73,8 +97,8 @@ elseif(isset($_POST["user"]) && isset($_POST['password'])) { exit(); } else { - if(isset($_COOKIE["username"])){ - OC_Template::printGuestPage("", "login", array("error" => true, "username" => $_COOKIE["username"])); + if(isset($_COOKIE["oc_username"])){ + OC_Template::printGuestPage("", "login", array("error" => true, "username" => $_COOKIE["oc_username"])); }else{ OC_Template::printGuestPage("", "login", array("error" => true)); } diff --git a/lib/user.php b/lib/user.php index 0630ebb9384..72dfd7970bb 100644 --- a/lib/user.php +++ b/lib/user.php @@ -215,6 +215,7 @@ class OC_User { public static function logout(){ OC_Hook::emit( "OC_User", "logout", array()); $_SESSION['user_id'] = false; + OC_User::unsetUsernameInCookie(); return true; } @@ -340,15 +341,21 @@ class OC_User { * @brief Set cookie value to use in next page load * @param string $username username to be set */ - public static function setUsernameInCookie($username){ - setcookie("username", $username, mktime().time()+60*60*24*15); + public static function setUsernameInCookie($username, $password){ + setcookie("oc_username", $username, time()+60*60*24*15); + setcookie("oc_password", $password, time()+60*60*24*15); + setcookie("oc_remember_login", true, time()+60*60*24*15); } /** * @brief Remove cookie for "remember username" */ public static function unsetUsernameInCookie(){ - unset($_COOKIE["username"]); - setcookie("username", NULL, -1); + unset($_COOKIE["oc_username"]); + unset($_COOKIE["oc_password"]); + unset($_COOKIE["oc_remember_login"]); + setcookie("oc_username", NULL, -1); + setcookie("oc_password", NULL, -1); + setcookie("oc_remember_login", NULL, -1); } } |