-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit-devusers.php
More file actions
50 lines (45 loc) · 1.57 KB
/
Copy pathinit-devusers.php
File metadata and controls
50 lines (45 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
require_once(__DIR__ . "/config.php");
require_once(__DIR__ . "/vendor/autoload.php");
function addStorage($userId, $ownerWebId) {
$storageId = $userId;
try {
$pdo = new \PDO("sqlite:" . DBPATH);
$query = $pdo->prepare('INSERT INTO storage VALUES(:storageId, :owner)');
$query->execute([
':storageId' => $storageId,
':owner' => $ownerWebId
]);
} catch(\PDOException $e) {
echo $e->getMessage();
}
}
function addUser($userId) {
try {
$pdo = new \PDO("sqlite:" . DBPATH);
$query = $pdo->prepare('INSERT INTO users VALUES (:userId, :email, :passwordHash, :data)');
$webId = "https://id-" . $userId . "." . BASEDOMAIN . "/#me";
$userData = [
"id" => $userId,
"email" => $userId,
"webId" => $webId
];
$query->execute([
':userId' => $userId,
':email' => $userId,
':passwordHash' => password_hash($userId, PASSWORD_BCRYPT),
':data' => json_encode($userData)
]);
} catch(\PDOException $e) {
echo $e->getMessage();
}
return $webId;
}
$users = [
'alice',
'bob'
];
foreach ($users as $user) {
$webId = addUser($user);
addStorage($user, $webId);
}