frame template now honors current user

This commit is contained in:
2025-09-20 17:10:37 -06:00
parent a794c5919b
commit d8648ace80
8 changed files with 84 additions and 42 deletions
+43 -18
View File
@@ -10,38 +10,63 @@
package database
import (
"encoding/gob"
"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"`
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"`
}
// init registers data types from this module.
func init() {
gob.Register(User{})
}
/* AmGetUser returns a reference to the specified user.
* Parameters:
* uid - The UID of the user.
* Returns:
* Pointer to User containing user data, or nil
* Standard Go error status
*/
func AmGetUser(uid int32) (*User, error) {
var rc []User
err := amdb.Select(&rc, "SELECT * from users WHERE uid = ?", uid)
if err != nil {
return nil, err
}
if len(rc) > 1 {
return nil, fmt.Errorf("AmGetUser(%d): too many responses(%d)", uid, len(rc))
}
return &(rc[0]), err
}
/* AmGetAmonUser returns a reference to the anonymous user.
* Returns:
* Pointer to User containing anonymous user data
* Pointer to User containing anonymous user data, or nil
* Standard Go error status
*/
func AmGetAnonUser() (*User, error) {
var rc []User
err := amdb.Select(&rc, "SELECT * from users WHERE uid = 1")
err := amdb.Select(&rc, "SELECT * from users WHERE is_anon = 1")
if err != nil {
return nil, err
}