"Remember Me" should work now but needs more fine tuning

This commit is contained in:
Michael Vogel 2016-04-25 07:10:40 +02:00
parent b4369d51f5
commit a214fc798a
2 changed files with 29 additions and 34 deletions

View File

@ -1,6 +1,4 @@
<?php
require_once('include/security.php');
require_once('include/datetime.php');
@ -13,7 +11,6 @@ function nuke_session() {
// When the "Friendica" cookie is set, take the value to authenticate and renew the cookie.
if(isset($_COOKIE["Friendica"])) {
$data = json_decode($_COOKIE["Friendica"]);
if (isset($data->uid)) {
$r = q("SELECT `user`.*, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey`
FROM `user` WHERE `uid` = %d AND `blocked` = 0 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1",
@ -26,7 +23,7 @@ if(isset($_COOKIE["Friendica"])) {
// Do the authentification if not done by now
if(!isset($_SESSION) OR !isset($_SESSION['authenticated'])) {
authenticate_success($r[0], false, false, false);
authenticate_success($r[0]);
if (get_config('system','paranoia'))
$_SESSION['addr'] = $data->ip;
@ -35,6 +32,7 @@ if(isset($_COOKIE["Friendica"])) {
}
}
// login/logout
if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-params'))) || ($_POST['auth-params'] !== 'login'))) {
@ -44,7 +42,6 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p
// process logout request
call_hooks("logging_out");
nuke_session();
new_cookie(-1);
info(t('Logged out.').EOL);
goaway(z_root());
}
@ -96,9 +93,7 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p
}
} else {
if(isset($_SESSION)) {
nuke_session();
}
session_unset();
if((x($_POST,'password')) && strlen($_POST['password']))
$encrypted = hash('whirlpool',trim($_POST['password']));
@ -163,8 +158,7 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p
if(($addon_auth['authenticated']) && (count($addon_auth['user_record']))) {
$record = $addon_auth['user_record'];
}
else {
} else {
// process normal login request
@ -206,7 +200,8 @@ function new_cookie($time, $value = "") {
if ($time != 0)
$time = $time + time();
setcookie("Friendica", $value, $time);
setcookie("Friendica", $value, $time, "/", "",
(get_config('system', 'ssl_policy') == SSL_POLICY_FULL), true);
return;
}

View File

@ -147,7 +147,7 @@ if((x($_GET,'zrl')) && (!$install && !$maintenance)) {
// header('Link: <' . $a->get_baseurl() . '/amcd>; rel="acct-mgmt";');
if((x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login'))
if(x($_COOKIE["Friendica"]) || (x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login'))
require("include/auth.php");
if(! x($_SESSION,'authenticated'))