From a6826055bf4e6a23f80da047ccfe4509a209f3a6 Mon Sep 17 00:00:00 2001 From: Andinus Date: Sun, 29 Mar 2020 16:10:59 +0530 Subject: Initial perseus rewrite --- user/adduser.go | 42 ------------------------------------------ user/getid.go | 29 ----------------------------- user/user.go | 9 --------- 3 files changed, 80 deletions(-) delete mode 100644 user/adduser.go delete mode 100644 user/getid.go delete mode 100644 user/user.go (limited to 'user') diff --git a/user/adduser.go b/user/adduser.go deleted file mode 100644 index d1dbcde..0000000 --- a/user/adduser.go +++ /dev/null @@ -1,42 +0,0 @@ -package user - -import ( - "log" - "time" - - "tildegit.org/andinus/perseus/storage/sqlite3" -) - -// AddUser adds the user to record. -func (u User) AddUser(db *sqlite3.DB) error { - // Acquire write lock on the database. - db.Mu.Lock() - defer db.Mu.Unlock() - - // Start the transaction - tx, err := db.Conn.Begin() - if err != nil { - log.Printf("user/adduser.go: %s\n", - "failed to begin transaction") - return err - } - - usrStmt, err := db.Conn.Prepare(` -INSERT INTO users(id, username, password, regTime) values(?, ?, ?, ?)`) - if err != nil { - log.Printf("user/adduser.go: %s\n", - "failed to prepare statement") - return err - } - defer usrStmt.Close() - - _, err = usrStmt.Exec(u.ID, u.Username, u.Password, time.Now().UTC()) - if err != nil { - log.Printf("user/adduser.go: %s\n", - "failed to execute statement") - return err - } - - tx.Commit() - return err -} diff --git a/user/getid.go b/user/getid.go deleted file mode 100644 index 9cf8870..0000000 --- a/user/getid.go +++ /dev/null @@ -1,29 +0,0 @@ -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 -} diff --git a/user/user.go b/user/user.go deleted file mode 100644 index 078215e..0000000 --- a/user/user.go +++ /dev/null @@ -1,9 +0,0 @@ -package user - -// User holds information about the user. -type User struct { - ID string - Username string - Password string - Hash string -} -- cgit 1.4.1-2-gfad0 >) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16