summary refs log tree commit diff stats
path: root/user
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-03-28 19:25:53 +0530
committerAndinus <andinus@nand.sh>2020-03-28 19:25:53 +0530
commit7b95d6b80dd2d1efb26f7c515383abd4f0dc9d42 (patch)
tree76dca236dc2d7c3be989896442cb3edfa1235e8d /user
parentb0b83af1c45c2d5ee587dc96847e25c95a3d50b0 (diff)
downloadperseus-7b95d6b80dd2d1efb26f7c515383abd4f0dc9d42.tar.gz
Prepare for rewrite on several functions
User struct now exports everything, encapsulation is not necessary
over here. Instead of introducing a new variable uInfo we'll use
user.User and pass that. Handlers & related functions will be
rewritten to work with this change. This will make it easier to work
on later as the program grows. I'm also rethinking error handling.
Diffstat (limited to 'user')
-rw-r--r--user/adduser.go4
-rw-r--r--user/getid.go4
-rw-r--r--user/user.go37
3 files changed, 8 insertions, 37 deletions
diff --git a/user/adduser.go b/user/adduser.go
index 873454b..d1dbcde 100644
--- a/user/adduser.go
+++ b/user/adduser.go
@@ -8,7 +8,7 @@ import (
 )
 
 // AddUser adds the user to record.
-func (u *User) AddUser(db *sqlite3.DB) error {
+func (u User) AddUser(db *sqlite3.DB) error {
 	// Acquire write lock on the database.
 	db.Mu.Lock()
 	defer db.Mu.Unlock()
@@ -30,7 +30,7 @@ INSERT INTO users(id, username, password, regTime) values(?, ?, ?, ?)`)
 	}
 	defer usrStmt.Close()
 
-	_, err = usrStmt.Exec(u.id, u.username, u.password, time.Now().UTC())
+	_, 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")
diff --git a/user/getid.go b/user/getid.go
index b8edfc7..9cf8870 100644
--- a/user/getid.go
+++ b/user/getid.go
@@ -18,12 +18,12 @@ func (u *User) GetID(db *sqlite3.DB) error {
 	defer stmt.Close()
 
 	var id string
-	err = stmt.QueryRow(u.username).Scan(&id)
+	err = stmt.QueryRow(u.Username).Scan(&id)
 	if err != nil {
 		log.Printf("user/getid.go: %s\n",
 			"query failed")
 	}
-	u.id = id
+	u.ID = id
 
 	return err
 }
diff --git a/user/user.go b/user/user.go
index a15d625..078215e 100644
--- a/user/user.go
+++ b/user/user.go
@@ -2,37 +2,8 @@ package user
 
 // User holds information about the user.
 type User struct {
-	id       string
-	username string
-	password string
-}
-
-// SetUsername will set the username.
-func (u *User) SetUsername(username string) {
-	u.username = username
-}
-
-// Username returns the username.
-func (u *User) Username() string {
-	return u.username
-}
-
-// SetPassword will set the password.
-func (u *User) SetPassword(password string) {
-	u.password = password
-}
-
-// Password returns the password.
-func (u *User) Password() string {
-	return u.password
-}
-
-// SetID will set the id.
-func (u *User) SetID(id string) {
-	u.id = id
-}
-
-// ID returns the id.
-func (u *User) ID() string {
-	return u.id
+	ID       string
+	Username string
+	Password string
+	Hash     string
 }