Skip to content

Commit 16d33d4

Browse files
committed
added script to add bob and alice with fixed webid and storage urls
1 parent ee67b70 commit 16d33d4

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

init-devusers.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
require_once(__DIR__ . "/config.php");
3+
require_once(__DIR__ . "/vendor/autoload.php");
4+
5+
function addStorage($userId, $ownerWebId) {
6+
$storageId = $userId;
7+
try {
8+
$pdo = new \PDO("sqlite:" . DBPATH);
9+
$query = $pdo->prepare('INSERT INTO storage VALUES(:storageId, :owner)');
10+
$query->execute([
11+
':storageId' => $storageId,
12+
':owner' => $ownerWebId
13+
]);
14+
} catch(\PDOException $e) {
15+
echo $e->getMessage();
16+
}
17+
}
18+
19+
function addUser($userId) {
20+
try {
21+
$pdo = new \PDO("sqlite:" . DBPATH);
22+
$query = $pdo->prepare('INSERT INTO users VALUES (:userId, :email, :passwordHash, :data)');
23+
$webId = "https://id-" . $userId . "." . BASEDOMAIN . "/#me";
24+
$userData = [
25+
"id" => $userId,
26+
"email" => $userId,
27+
"webId" => $webId
28+
];
29+
$query->execute([
30+
':userId' => $userId,
31+
':email' => $userId,
32+
':passwordHash' => password_hash($userId, PASSWORD_BCRYPT),
33+
':data' => json_encode($userData)
34+
]);
35+
} catch(\PDOException $e) {
36+
echo $e->getMessage();
37+
}
38+
return $webId;
39+
}
40+
41+
$users = [
42+
'alice',
43+
'bob'
44+
];
45+
46+
foreach ($users as $user) {
47+
$webId = addUser($user);
48+
addStorage($user, $webId);
49+
}
50+

0 commit comments

Comments
 (0)