From ad9332dcd5912005917f4bf2f4c544115008138a Mon Sep 17 00:00:00 2001 From: Andinus Date: Fri, 27 Mar 2020 18:10:32 +0530 Subject: Add token related functions --- user/getid.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 user/getid.go (limited to 'user') 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 +} -- cgit 1.4.1-2-gfad0