aboutsummaryrefslogtreecommitdiff
path: root/internal/unsorted/users.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/unsorted/users.go')
-rw-r--r--internal/unsorted/users.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/unsorted/users.go b/internal/unsorted/users.go
new file mode 100644
index 0000000..0f72eed
--- /dev/null
+++ b/internal/unsorted/users.go
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
+
+package unsorted
+
+import (
+ "context"
+
+ "github.com/jackc/pgx/v5"
+)
+
+// addUserSSH adds a new user solely based on their SSH public key.
+//
+// TODO: Audit all users of this function.
+func (s *Server) addUserSSH(ctx context.Context, pubkey string) (userID int, err error) {
+ var txn pgx.Tx
+
+ if txn, err = s.database.Begin(ctx); err != nil {
+ return
+ }
+ defer func() {
+ _ = txn.Rollback(ctx)
+ }()
+
+ if err = txn.QueryRow(ctx, `INSERT INTO users (type) VALUES ('pubkey_only') RETURNING id`).Scan(&userID); err != nil {
+ return
+ }
+
+ if _, err = txn.Exec(ctx, `INSERT INTO ssh_public_keys (key_string, user_id) VALUES ($1, $2)`, pubkey, userID); err != nil {
+ return
+ }
+
+ err = txn.Commit(ctx)
+ return
+}