diff options
author | Andinus <andinus@nand.sh> | 2020-03-27 14:38:31 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2020-03-27 16:47:59 +0530 |
commit | f22adf24e886cf4382a26b4777c5b481b21c26f5 (patch) | |
tree | 6c4b05febceaeddd9f6f63373349397422723f9d /auth | |
parent | 5d65b69f75d9d812a04b816630295b2169da864b (diff) | |
download | perseus-f22adf24e886cf4382a26b4777c5b481b21c26f5.tar.gz |
Change database schema
Diffstat (limited to 'auth')
-rw-r--r-- | auth/register.go | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/auth/register.go b/auth/register.go index b253f69..086d3ce 100644 --- a/auth/register.go +++ b/auth/register.go @@ -11,7 +11,7 @@ import ( // Register takes in registration details and returns an error. If // error doesn't equal nil then the registration was unsuccessful. -// regInfo should have username, password & ip. +// regInfo should have username & password. func Register(db *sqlite3.DB, regInfo map[string]string) error { u := user.User{} u.SetID(genID(64)) @@ -29,11 +29,11 @@ func Register(db *sqlite3.DB, regInfo map[string]string) error { db.Mu.Lock() defer db.Mu.Unlock() - err = insertRecords(db, u, regInfo) + err = insertRegRecords(db, u) return err } -func insertRecords(db *sqlite3.DB, u user.User, regInfo map[string]string) error { +func insertRegRecords(db *sqlite3.DB, u user.User) error { // Start the transaction tx, err := db.Conn.Begin() if err != nil { @@ -42,26 +42,8 @@ func insertRecords(db *sqlite3.DB, u user.User, regInfo map[string]string) error return err } - // Insert the record into registration table - regStmt, err := db.Conn.Prepare(` -INSERT INTO registration(id, username, reg_time, reg_ip) values(?, ?, ?, ?)`) - if err != nil { - log.Printf("auth/register.go: %s\n", - "Failed to prepare statement") - return err - } - defer regStmt.Close() - - _, err = regStmt.Exec(u.ID(), u.Username(), time.Now().UTC(), regInfo["ip"]) - if err != nil { - log.Printf("auth/register.go: %s\n", - "Failed to execute statement") - return err - } - - // Insert the record into users table usrStmt, err := db.Conn.Prepare(` -INSERT INTO users(id, username, password) values(?, ?, ?)`) +INSERT INTO users(id, username, password, regTime) values(?, ?, ?, ?)`) if err != nil { log.Printf("auth/register.go: %s\n", "Failed to prepare statement") @@ -69,7 +51,7 @@ INSERT INTO users(id, username, password) values(?, ?, ?)`) } defer usrStmt.Close() - _, err = usrStmt.Exec(u.ID(), u.Username(), u.Password()) + _, err = usrStmt.Exec(u.ID(), u.Username(), u.Password(), time.Now().UTC()) if err != nil { log.Printf("auth/register.go: %s\n", "Failed to execute statement") |