summary refs log tree commit diff stats
path: root/user
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-03-27 18:10:32 +0530
committerAndinus <andinus@nand.sh>2020-03-27 18:10:32 +0530
commitad9332dcd5912005917f4bf2f4c544115008138a (patch)
tree2819aff280a7c4d0c109ae9038ec891e97e0b483 /user
parent5c62f93da80611fc03b96f73f8787513e86c0477 (diff)
downloadperseus-ad9332dcd5912005917f4bf2f4c544115008138a.tar.gz
Add token related functions
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
+}