Skip to content

Commit fde560e

Browse files
committed
add profile page for user
1 parent adb3eb8 commit fde560e

6 files changed

Lines changed: 170 additions & 25 deletions

File tree

docker/000-solid-idp.conf

Lines changed: 0 additions & 20 deletions
This file was deleted.

docker/Dockerfile.php-apache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ RUN apt-get install -y ssl-cert
66
RUN a2enmod rewrite allowmethods ssl
77

88
COPY . /opt/solid
9-
COPY 000-solid-idp.conf /etc/apache2/sites-enabled/000-solid-idp.conf
9+
COPY solid.conf /etc/apache2/sites-enabled/000-default.conf

docker/solid.conf

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<VirtualHost *:443>
2+
ServerName solid.local
3+
DocumentRoot /opt/solid/www/idp
4+
5+
SSLEngine on
6+
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
7+
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
8+
9+
ErrorLog ${APACHE_LOG_DIR}/error.log
10+
CustomLog ${APACHE_LOG_DIR}/access.log combined
11+
<Directory />
12+
Require all granted
13+
RewriteEngine On
14+
RewriteBase /
15+
RewriteCond %{REQUEST_FILENAME} !-d
16+
RewriteCond %{REQUEST_FILENAME} !-f
17+
RewriteRule ^(.+)$ index.php [QSA,L]
18+
</Directory>
19+
</VirtualHost>
20+
<VirtualHost *:443>
21+
ServerName identity.solid.local
22+
ServerAlias *.solid.local
23+
DocumentRoot /opt/solid/www/profile
24+
25+
SSLEngine on
26+
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
27+
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
28+
29+
ErrorLog ${APACHE_LOG_DIR}/error.log
30+
CustomLog ${APACHE_LOG_DIR}/access.log combined
31+
32+
<Directory />
33+
Require all granted
34+
</Directory>
35+
36+
RewriteEngine on
37+
38+
# Extract the first part of the subdomain (before the first dot)
39+
RewriteCond %{HTTP_HOST} ^id-([a-zA-Z0-9-]+)\.solid\.local$ [NC]
40+
# Example rewrite rule based on the first part of the hostname
41+
# This will redirect to /subdomain-content/first_part_of_hostname
42+
RewriteRule ^(.+)$ index.php [QSA,L]
43+
44+
# Extract the first part of the subdomain (before the first dot)
45+
RewriteCond %{HTTP_HOST} ^storage-([a-zA-Z0-9-]+)\.solid\.local$ [NC]
46+
# Example rewrite rule based on the first part of the hostname
47+
# This will redirect to /subdomain-content/first_part_of_hostname
48+
RewriteRule ^(.+)$ storage.php [QSA,L]
49+
</VirtualHost>

lib/User.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,32 @@ public static function getAllowedClients($userId) {
101101
return $result;
102102
}
103103

104+
public static function getStorage($userId) {
105+
self::connect();
106+
$query = self::$pdo->prepare(
107+
'SELECT storage FROM userStorage WHERE userId=:userId'
108+
);
109+
$query->execute([
110+
':userId' => $userId
111+
]);
112+
$result = [];
113+
while($row = $query->fetch()) {
114+
$result[] = $row['storage'];
115+
}
116+
return $result;
117+
}
118+
119+
public static function setStorage($userId, $storageUrl) {
120+
self::connect();
121+
$query = self::$pdo->prepare(
122+
'INSERT OR REPLACE INTO storage VALUES(:userId, :storageUrl)'
123+
);
124+
$query->execute([
125+
':userId' => $userId,
126+
':storageUrl' => $storageUrl
127+
]);
128+
}
129+
104130
public static function getUser($email) {
105131
self::connect();
106132
$query = self::$pdo->prepare(
@@ -114,14 +140,38 @@ public static function getUser($email) {
114140
$userData = json_decode($result[0]['data'], true);
115141
$userData['userId'] = $result[0]['user_id'];
116142

143+
$allowedClients = self::getAllowedClients($userData['userId']);
144+
$userData['allowedClients'] = $allowedClients;
145+
$userData['issuer'] = BASEURL;
146+
$storage = self::getStorage($userData['userId']);
147+
if ($storage) {
148+
$userData['storage'] = $storage;
149+
}
150+
return $userData;
151+
}
152+
return false;
153+
}
154+
155+
public static function getUserById($userId) {
156+
self::connect();
157+
$query = self::$pdo->prepare(
158+
'SELECT user_id, data FROM users WHERE user_id=:userId'
159+
);
160+
$query->execute([
161+
':userId' => $userId
162+
]);
163+
$result = $query->fetchAll();
164+
if (sizeof($result) === 1) {
165+
$userData = json_decode($result[0]['data'], true);
166+
$userData['userId'] = $result[0]['user_id'];
167+
117168
$allowedClients = self::getAllowedClients($userData['userId']);
118169
$userData['allowedClients'] = $allowedClients;
119170
return $userData;
120171
}
121172
return false;
122173
}
123174

124-
125175
public static function checkPassword($email, $password) {
126176
self::connect();
127177
$query = self::$pdo->prepare(

www/idp/index.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
2-
require_once(__DIR__ . "/../config.php");
3-
require_once(__DIR__ . "/../vendor/autoload.php");
2+
require_once(__DIR__ . "/../../config.php");
3+
require_once(__DIR__ . "/../../vendor/autoload.php");
44

55
use Pdsinterop\PhpSolid\Middleware;
66
use Pdsinterop\PhpSolid\Server;
@@ -346,7 +346,6 @@
346346
break;
347347
}
348348
break;
349-
break;
350349
case "OPTIONS":
351350
break;
352351
case "PUT":

www/profile/index.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
require_once(__DIR__ . "/../../config.php");
3+
require_once(__DIR__ . "/../../vendor/autoload.php");
4+
5+
use Pdsinterop\PhpSolid\Middleware;
6+
use Pdsinterop\PhpSolid\Server;
7+
use Pdsinterop\PhpSolid\User;
8+
9+
$request = explode("?", $_SERVER['REQUEST_URI'], 2)[0];
10+
$method = $_SERVER['REQUEST_METHOD'];
11+
12+
Middleware::cors();
13+
14+
switch($method) {
15+
case "GET":
16+
switch ($request) {
17+
case "/":
18+
$serverName = $_SERVER['SERVER_NAME'];
19+
[$idPart, $rest] = explode(".", $serverName, 2);
20+
$userId = preg_replace("/^id-/", "", $idPart);
21+
22+
$user = User::getUserById($userId);
23+
if (!isset($user['storage'])) {
24+
$user['storage'] = "https://storage-" . $userId . "." . BASEDOMAIN;
25+
}
26+
if (!isset($user['issuer'])) {
27+
$user['issuer'] = BASEURL;
28+
}
29+
30+
$profile = <<<"EOF"
31+
@prefix : <#>.
32+
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
33+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
34+
@prefix ldp: <http://www.w3.org/ns/ldp#>.
35+
@prefix schema: <http://schema.org/>.
36+
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
37+
@prefix space: <http://www.w3.org/ns/pim/space#>.
38+
@prefix vcard: <http://www.w3.org/2006/vcard/ns#>.
39+
@prefix pro: <./>.
40+
@prefix inbox: <{$user['storage']}/inbox/>.
41+
42+
<> a foaf:PersonalProfileDocument; foaf:maker :me; foaf:primaryTopic :me.
43+
44+
:me
45+
a schema:Person, foaf:Person;
46+
ldp:inbox inbox:;
47+
space:preferencesFile </storage/settings/prefs.ttl>;
48+
space:storage <{$user['storage']}>;
49+
solid:account <{$user['storage']}>;
50+
solid:oidcIssuer <{$user['issuer']}>;
51+
solid:privateTypeIndex <{$user['storage']}/settings/privateTypeIndex.ttl>;
52+
solid:publicTypeIndex <{$user['storage']}/settings/publicTypeIndex.ttl>.
53+
EOF;
54+
header('Content-Type: text/turtle');
55+
echo $profile;
56+
break;
57+
}
58+
break;
59+
case "OPTIONS":
60+
break;
61+
case "POST":
62+
case "PUT":
63+
default:
64+
header($_SERVER['SERVER_PROTOCOL'] . " 405 Method not allowed");
65+
break;
66+
}
67+

0 commit comments

Comments
 (0)