summaryrefslogtreecommitdiff
path: root/user.go
diff options
context:
space:
mode:
Diffstat (limited to 'user.go')
-rw-r--r--user.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/user.go b/user.go
index b686f74..f2a5afd 100644
--- a/user.go
+++ b/user.go
@@ -8,14 +8,20 @@ type User struct {
isAdmin bool
}
-func createUser(db *sqlite3.Conn, name string, isAdmin bool) {
+func createUser(db *sqlite3.Conn, name string, isAdmin bool) (User, error) {
+
+ user := getUserForName(db, name)
//Check if a user with this name already exists
- if (getUserForName(db, name).id == 0) {
+ if (user.id == 0) {
args := sqlite3.NamedArgs{"$a": name, "$b": isAdmin}
sql := "INSERT INTO users (name, admin) VALUES ($a, $b)"
- db.Exec(sql, args)
+ err := db.Exec(sql, args)
+
+ return User{id:db.LastInsertId(), name:name, isAdmin:isAdmin}, err
+ } else {
+ return user, nil
}
}