summary refs log tree commit diff stats
path: root/user
diff options
context:
space:
mode:
Diffstat (limited to 'user')
-rw-r--r--user/getid.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/user/getid.go b/user/getid.go
new file mode 100644
index 0000000..b8edfc7
--- /dev/null
+++ b/user/getid.go
@@ -0,0 +1,29 @@
+package user
+
+import (
+	"log"
+
+	"tildegit.org/andinus/perseus/storage/sqlite3"
+)
+
+// GetID returns id from username.
+func (u *User) GetID(db *sqlite3.DB) error {
+	// Get password for this user from the database.
+	stmt, err := db.Conn.Prepare("SELECT id FROM users WHERE username = ?")
+	if err != nil {
+		log.Printf("user/getid.go: %s\n",
+			"failed to prepare statement")
+		return err
+	}
+	defer stmt.Close()
+
+	var id string
+	err = stmt.QueryRow(u.username).Scan(&id)
+	if err != nil {
+		log.Printf("user/getid.go: %s\n",
+			"query failed")
+	}
+	u.id = id
+
+	return err
+}