From b0d8eb635ccc4b95979714f93051cc8cd9757cd1 Mon Sep 17 00:00:00 2001 From: sanine-a Date: Tue, 2 May 2023 15:23:37 -0500 Subject: add host address/login page configuration fields --- db/db.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/db/db.go b/db/db.go index 3a48858..3210846 100644 --- a/db/db.go +++ b/db/db.go @@ -39,6 +39,10 @@ type Model interface { Close() error GetSchemaVersion() (int, error) + SetHostAddress(addr string) error + GetHostAddress() (string, error) + SetLoginPage(path string) error + GetLoginPage() (string, error) CreateUser(username, password string) (User, error) DeleteUser(user User) error @@ -110,6 +114,10 @@ func (p *Phlox) Create(filename string) error { create table schema(version integer); insert into schema values(0); + create table config(key string primary key, value string); + insert into config values("hostaddress", "localhost:3333"); + insert into config values("loginpage", ""); + create table users (userid integer not null primary key, username string, passwordhash string, salt string); create table sessions (sessionid string not null primary key, userid integer, created string, modified string, foreign key(userid) references users(userid)); create table endpoints (endpointid integer not null primary key, name string, path string, address string); @@ -156,3 +164,37 @@ func (p *Phlox) GetSchemaVersion() (int, error) { return version, nil } + + +func (p *Phlox) SetHostAddress(addr string) error { + _, err := p.db.Exec("update config set value=? where key='hostaddress';", addr) + return err +} + + +func (p *Phlox) GetHostAddress() (string, error) { + row := p.db.QueryRow("select value from config where key='hostaddress';") + var addr string + err := row.Scan(&addr) + if err != nil { + return "", err + } + return addr, nil +} + + +func (p *Phlox) SetLoginPage(path string) error { + _, err := p.db.Exec("update config set value=? where key='loginpage';", path) + return err +} + + +func (p *Phlox) GetLoginPage() (string, error) { + row := p.db.QueryRow("select value from config where key='loginpage';") + var path string + err := row.Scan(&path) + if err != nil { + return "", err + } + return path, nil +} -- cgit v1.2.1