diff options
author | sanine-a <sanine.not@pm.me> | 2023-05-02 15:23:37 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2023-05-02 15:23:37 -0500 |
commit | b0d8eb635ccc4b95979714f93051cc8cd9757cd1 (patch) | |
tree | 6750422655e0b0e28e1fd934979ce4681835876f /db | |
parent | 9ab2e0044c8976b5669a069e61479354ca52980c (diff) |
add host address/login page configuration fields
Diffstat (limited to 'db')
-rw-r--r-- | db/db.go | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -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 +} |