diff --git a/index.php b/index.php index 52a00465f2..3c8a0e3bed 100644 --- a/index.php +++ b/index.php @@ -59,13 +59,14 @@ elseif(OC_User::isLoggedIn()) { } } -// Someone wants to log in : -elseif(isset($_POST["user"]) && isset($_POST['password'])) { +// Semeone set remember login when login +elseif(isset($_COOKIE["oc_remember_login"]) && $_COOKIE["oc_remember_login"]) { OC_App::loadApps(); - if(OC_User::login($_POST["user"], $_POST["password"])) { - header("Location: ".$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php")); + 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"]); + OC_User::setUsernameInCookie($_POST["user"], $_POST["password"]); } else { OC_User::unsetUsernameInCookie(); @@ -81,6 +82,29 @@ elseif(isset($_POST["user"]) && isset($_POST['password'])) { } } +// 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"])){ + error_log("Setting remember login to cookie"); + OC_User::setUsernameInCookie($_POST["user"], $_POST["password"]); + } + else { + OC_User::unsetUsernameInCookie(); + } + exit(); + } + else { + if(isset($_COOKIE["oc_username"])){ + OC_Template::printGuestPage("", "login", array("error" => true, "username" => $_COOKIE["oc_username"])); + }else{ + OC_Template::printGuestPage("", "login", array("error" => true)); + } + } +} + // Someone lost their password: elseif(isset($_GET['lostpassword'])) { OC_App::loadApps(); diff --git a/lib/group/database.php b/lib/group/database.php index 7bf9c8bb5c..f35f61434f 100644 --- a/lib/group/database.php +++ b/lib/group/database.php @@ -56,7 +56,7 @@ class OC_Group_Database extends OC_Group_Backend { $query = OC_DB::prepare( "SELECT gid FROM `*PREFIX*groups` WHERE gid = ?" ); $result = $query->execute( array( $gid )); - if( !$result->fetchRow() ){ + if( $result->fetchRow() ){ // Can not add an existing group return false; } @@ -101,7 +101,7 @@ class OC_Group_Database extends OC_Group_Backend { $query = OC_DB::prepare( "SELECT uid FROM `*PREFIX*group_user` WHERE gid = ? AND uid = ?" ); $result = $query->execute( array( $gid, $uid )); - return $result->numRows() > 0 ? true : false; + return $result->fetchRow() ? true : false; } /** diff --git a/lib/user.php b/lib/user.php index 0630ebb938..72dfd7970b 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); } }