Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@
- [v] IpAttempts
- [v] Util
- [v] PasswordValidator
- [v] User
- [ ] Mailer
- [ ] MailTemplateGenerator
- [ ] MailTemplates
- [ ] Server
- [ ] SolidNotifications
- [ ] SolidPubSub
- [ ] StorageServer
- [ ] User
- [-] Session
- [-] SolidNotifications
- [-] SolidPubSub
- [-] Middleware
- [-] Db
4 changes: 2 additions & 2 deletions docker/solid.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<VirtualHost *:443>
ServerName identity.solid.local
ServerAlias *.solid.local
DocumentRoot /opt/solid/www/profile
DocumentRoot /opt/solid/www/user

SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
Expand All @@ -39,7 +39,7 @@
RewriteCond %{HTTP_HOST} ^id-([a-zA-Z0-9-]+)\.solid\.local$ [NC]
# Example rewrite rule based on the first part of the hostname
# This will redirect to /subdomain-content/first_part_of_hostname
RewriteRule ^(.+)$ index.php [QSA,L]
RewriteRule ^(.+)$ profile.php [QSA,L]

# Extract the first part of the subdomain (before the first dot)
RewriteCond %{HTTP_HOST} ^storage-([a-zA-Z0-9-]+)\.solid\.local$ [NC]
Expand Down
20 changes: 20 additions & 0 deletions lib/Session.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace Pdsinterop\PhpSolid;

class Session {
private $cookieLifetime = 24*60*60;
public static function start($username) {
session_start([
'cookie_lifetime' => 24*60*60 // 1 day
]);
$_SESSION['username'] = $username;
}

public static function getLoggedInUser() {
session_start();
if (!isset($_SESSION['username'])) {
return false;
}
return $_SESSION['username'];
}
}
17 changes: 4 additions & 13 deletions lib/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static function getStorage($userId) {
public static function setStorage($userId, $storageUrl) {
Db::connect();
$query = Db::$pdo->prepare(
'INSERT OR REPLACE INTO storage VALUES(:userId, :storageUrl)'
'INSERT OR REPLACE INTO userStorage VALUES(:userId, :storageUrl)'
);
$query->execute([
':userId' => $userId,
Expand All @@ -187,6 +187,9 @@ public static function setStorage($userId, $storageUrl) {
}

public static function getUser($email) {
if (!isset($email)) {
return false;
}
Db::connect();
$query = Db::$pdo->prepare(
'SELECT user_id, data FROM users WHERE email=:email'
Expand Down Expand Up @@ -247,24 +250,12 @@ public static function checkPassword($email, $password) {
$result = $query->fetchAll();
if (sizeof($result) === 1) {
if (password_verify($password, $result[0]['password'])) {
session_start([
'cookie_lifetime' => 24*60*60 // 1 day
]);
$_SESSION['username'] = $email;
return true;
}
}
return false;
}

public static function getLoggedInUser() {
session_start();
if (!isset($_SESSION['username'])) {
return false;
}
return self::getUser($_SESSION['username']);
}

public static function userIdExists($userId) {
Db::connect();
$query = Db::$pdo->prepare(
Expand Down
Loading