diff --git a/lib/Core.php b/lib/Core.php index b3ec65e1..e1822d80 100644 --- a/lib/Core.php +++ b/lib/Core.php @@ -28,3 +28,15 @@ if(SITE_STATUS == SITE_STATUS_LIVE){ } $GLOBALS['User'] = Session::GetLoggedInUser(); + +if($GLOBALS['User'] === null){ + $httpBasicAuthLogin = $_SERVER['PHP_AUTH_USER'] ?? null; + + if($httpBasicAuthLogin !== null){ + // If there's no logged in user, but a username was sent via HTTP basic auth, + // log them in while we're here. + + $session = new Session(); + $session->Create($httpBasicAuthLogin); + } +} diff --git a/lib/Session.php b/lib/Session.php index 1e7d4a8f..705fe54b 100644 --- a/lib/Session.php +++ b/lib/Session.php @@ -48,17 +48,18 @@ class Session extends PropertiesBase{ $this->Created = new DateTime(); Db::Query('INSERT into Sessions (UserId, SessionId, Created) values (?, ?, ?)', [$this->UserId, $this->SessionId, $this->Created]); } + + $this->SetSessionCookie($this->SessionId); } public static function GetLoggedInUser(): ?User{ $sessionId = HttpInput::Str(COOKIE, 'sessionid'); if($sessionId !== null){ - $result = Db::Query('select u.* from Users u inner join Sessions s using (UserId) where s.SessionId = ?', [$sessionId], 'User'); + $result = Db::Query('SELECT u.* from Users u inner join Sessions s using (UserId) where s.SessionId = ?', [$sessionId], 'User'); if(sizeof($result) > 0){ - // Refresh the login cookie for another 2 weeks - setcookie('sessionid', $sessionId, time() + 60 * 60 * 24 * 14 * 1, '/', SITE_DOMAIN, true, false); // Expires in two weeks + self::SetSessionCookie($sessionId); return $result[0]; } } @@ -66,6 +67,10 @@ class Session extends PropertiesBase{ return null; } + public static function SetSessionCookie($sessionId): void{ + setcookie('sessionid', $sessionId, time() + 60 * 60 * 24 * 14 * 1, '/', SITE_DOMAIN, true, false); // Expires in two weeks + } + public static function Get(?string $sessionId): Session{ if($sessionId === null){ throw new Exceptions\InvalidSessionException(); diff --git a/templates/FeedHowTo.php b/templates/FeedHowTo.php index 54842d60..e6560f81 100644 --- a/templates/FeedHowTo.php +++ b/templates/FeedHowTo.php @@ -7,6 +7,10 @@
Produce an ebook for Standard Ebooks to get lifetime access to our ebook feeds. (If you’ve already done that, contact us to enable your access.)
Corporate sponsors get access to all of our ebook feeds for the duration of their sponsorship. Contact us to chat about having your organization sponsor our mission.
If you’re a Patrons Circle member, when prompted enter your email address and leave the password field blank to access a feed.
+ }elseif($GLOBALS['User']->Benefits->CanAccessFeeds){ ?> +When prompted enter your email address and leave the password field blank to access a feed.
+ }else{ ?> +If you’re a Patrons Circle member, when prompted enter your email address and leave the password field blank to access a feed.
+ } ?> diff --git a/www/css/core.css b/www/css/core.css index 56d31722..0ee91c32 100644 --- a/www/css/core.css +++ b/www/css/core.css @@ -3130,9 +3130,6 @@ ul.feed p{ margin: 0 10px; } - - .ebooks-toolbar{ - } .ebooks-toolbar a.button{ font-size: 0; gap: 0; diff --git a/www/polls/votes/get.php b/www/polls/votes/get.php index f2580df7..ddae7c30 100644 --- a/www/polls/votes/get.php +++ b/www/polls/votes/get.php @@ -30,7 +30,6 @@ catch(Exceptions\SeException $ex){ }else{ ?>Your vote in the = Formatter::ToPlainText($vote->PollItem->Poll->Name) ?> poll was submitted on = $vote->Created->format('F j, Y g:i A') ?>.
} ?> - diff --git a/www/sessions/post.php b/www/sessions/post.php index 81f49f1f..a7b6f65d 100644 --- a/www/sessions/post.php +++ b/www/sessions/post.php @@ -24,8 +24,6 @@ try{ $session->Create($email); - setcookie('sessionid', $session->SessionId, time() + 60 * 60 * 24 * 14 * 1, '/', SITE_DOMAIN, true, false); // Expires in two weeks - if($requestType == WEB){ http_response_code(303); header('Location: ' . $redirect);