added database connection and ability to retrieve "Anonymous Honyak" user

This commit is contained in:
2025-09-20 15:57:29 -06:00
parent 0e65eaeef6
commit a794c5919b
8 changed files with 119 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
/*
* Amsterdam Web Communities System
* Copyright (c) 2025 Erbosoft Metaverse Design Solutions, All Rights Reserved
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
// The database package contains database management and storage logic.
package database
import (
"git.erbosoft.com/amy/amsterdam/config"
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
)
// amdb is the reference to the Amsterdam database.
var amdb *sqlx.DB
// SetupDb sets up the database and associated items.
func SetupDb() error {
db, err := sqlx.Open(config.GlobalConfig.Database.Driver, config.GlobalConfig.Database.Dsn)
if err == nil {
amdb = db
// TODO: additional initialization
}
return err
}
// ClosedownDb closes down the database and associated items.
func ClosedownDb() {
amdb.Close()
}
+52
View File
@@ -0,0 +1,52 @@
/*
* Amsterdam Web Communities System
* Copyright (c) 2025 Erbosoft Metaverse Design Solutions, All Rights Reserved
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
// The database package contains database management and storage logic.
package database
import (
"fmt"
"time"
)
// User represents a user in the Amsterdam database.
type User struct {
Uid int32 `db:"uid"`
Username string `db:"username"`
Passhash string `db:"passhash"`
Tokenauth string `db:"tokenauth"`
ContactID int32 `db:"contactid"`
IsAnon bool `db:"is_anon"`
VerifyEMail bool `db:"verify_email"`
Lockout bool `db:"lockout"`
AccessTries int16 `db:"access_tries"`
EmailConfNum int32 `db:"email_confnum"`
BaseLevel uint16 `db:"base_lvl"`
Created time.Time `db:"created"`
LastAccess time.Time `db:"lastaccess"`
PassReminder string `db:"passreminder"`
Description string `db:"description"`
DOB time.Time `db:"dob"`
}
/* AmGetAmonUser returns a reference to the anonymous user.
* Returns:
* Pointer to User containing anonymous user data
* Standard Go error status
*/
func AmGetAnonUser() (*User, error) {
var rc []User
err := amdb.Select(&rc, "SELECT * from users WHERE uid = 1")
if err != nil {
return nil, err
}
if len(rc) > 1 {
return nil, fmt.Errorf("AmGetAnonUser: too many responses(%d)", len(rc))
}
return &(rc[0]), err
}