dee22afd94588ded04d1257fe40667f6b6df0af0
Bernd Wurst merge passkeys feature

Bernd Wurst authored 1 year ago

1) <?php
2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
5) Written by schokokeks.org Hosting, namely
6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
9) This code is published under a 0BSD license.
10) 
11) Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
12) */
13) 
Hanno Böck Fix codingstyle

Hanno Böck authored 1 year ago

14) function save_passkey($data, $handle = null)
Bernd Wurst merge passkeys feature

Bernd Wurst authored 1 year ago

15) {
16)     require_role(ROLE_SYSTEMUSER);
17)     $args = [
18)         ":credentialId" => $data->credentialId,
19)         ":credentialPublicKey" => $data->credentialPublicKey,
20)         ":rpId" => $data->rpId,
21)         ":handle" => $handle,
Hanno Böck Fix codingstyle

Hanno Böck authored 1 year ago

22)         ":uid" => $_SESSION['userinfo']['uid'],
Bernd Wurst merge passkeys feature

Bernd Wurst authored 1 year ago

23)         ];
Hanno Böck Fix codingstyle

Hanno Böck authored 1 year ago

24)     db_query("INSERT INTO system.systemuser_passkey (uid, handle, rpId, credentialId, credentialPublicKey) VALUES " .
Bernd Wurst merge passkeys feature

Bernd Wurst authored 1 year ago

25)             "(:uid, :handle, :rpId, :credentialId, :credentialPublicKey)", $args);
26) }
27) 
Hanno Böck Fix codingstyle

Hanno Böck authored 1 year ago

28) function get_passkey($id)
Bernd Wurst merge passkeys feature

Bernd Wurst authored 1 year ago

29) {
30)     $ret = db_query("SELECT uid, handle, credentialPublicKey FROM system.systemuser_passkey WHERE credentialId=:id", [":id" => $id]);
31)     if ($data = $ret->fetch()) {
32)         return $data;
33)     }
34)     return null;
35) }
36) 
37) 
38) function list_passkeys()
39) {
40)     $result = db_query("SELECT id, handle, setuptime, rpId FROM system.systemuser_passkey WHERE uid=:uid", [":uid" => $_SESSION['userinfo']['uid']]);
41)     $ret = [];
42)     while ($item = $result->fetch()) {
43)         $ret[] = $item;
44)     }
45)     return $ret;
46) }
47) 
Hanno Böck Fix codingstyle

Hanno Böck authored 1 year ago

48) function delete_systemuser_passkey($id)
49) {
Bernd Wurst merge passkeys feature

Bernd Wurst authored 1 year ago

50)     $args = [
51)         ":id" => $id,
Hanno Böck Fix codingstyle

Hanno Böck authored 1 year ago

52)         ":uid" => $_SESSION['userinfo']['uid'],