89 lines
2.7 KiB
Go
89 lines
2.7 KiB
Go
// Package models defines the data structures for URIT BBS.
|
|
//
|
|
// These are the modernized equivalents of the original TAG-BBS header
|
|
// file structures (USER.H, BOARD.H, MAIL.H, LIBRARY.H, BULLETIN.H).
|
|
// Fixed-size char arrays become strings, USHORT slot numbers become
|
|
// int64 database IDs, and raw binary timestamps become time.Time.
|
|
package models
|
|
|
|
import "time"
|
|
|
|
// User represents a BBS user account.
|
|
//
|
|
// Original: struct User in USER.H
|
|
// Changes:
|
|
// - ID replaces Slot_Number (database-assigned, not positional)
|
|
// - PasswordHash replaces Pass[9] (bcrypt instead of plaintext)
|
|
// - Comments collapsed from [3][81] to a single text field
|
|
// - Time fields use time.Time instead of long epoch seconds
|
|
// - Active flag replaces the "Slot_Number==0 means deleted" convention
|
|
type User struct {
|
|
ID int64
|
|
Name string
|
|
PasswordHash string
|
|
Comments string
|
|
Active bool
|
|
|
|
// Security levels — same concept as the original's Sec_* fields.
|
|
// Each level is checked against board/library/bulletin access ranges.
|
|
SecStatus int // Overall tier: 0=Guest, 1=New, 2+=Valid, 100+=BoardOp, 150+=LibOp, 255=Sysop
|
|
SecBoard int // Board access level
|
|
SecLibrary int // Library access level
|
|
SecBulletin int // Bulletin access level
|
|
|
|
// Statistics — direct equivalents of the original fields
|
|
MessagesPosted int
|
|
MailSent int
|
|
MailReceived int
|
|
Uploads int
|
|
Downloads int
|
|
|
|
// Time tracking
|
|
TimeLimit int64 // Seconds allowed per session
|
|
TimeUsed int64 // Seconds used in current/last session
|
|
TimeTotal int64 // Cumulative seconds across all sessions
|
|
LastOn *time.Time // Last login time (nil if never logged in)
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
// IsGuest returns true if this is a guest (unauthenticated) user.
|
|
func (u *User) IsGuest() bool {
|
|
return u.SecStatus == 0
|
|
}
|
|
|
|
// IsNew returns true if this user hasn't been validated yet.
|
|
func (u *User) IsNew() bool {
|
|
return u.SecStatus == 1
|
|
}
|
|
|
|
// IsSysop returns true if this user has sysop privileges.
|
|
func (u *User) IsSysop() bool {
|
|
return u.SecStatus == 255
|
|
}
|
|
|
|
// IsBoardOp returns true if this user has board operator privileges.
|
|
func (u *User) IsBoardOp() bool {
|
|
return u.SecStatus >= 100
|
|
}
|
|
|
|
// StatusLabel returns a human-readable label for the user's status.
|
|
// Mirrors the original's StatPrintUser() display logic.
|
|
func (u *User) StatusLabel() string {
|
|
switch {
|
|
case u.SecStatus == 0:
|
|
return "Guest"
|
|
case u.SecStatus == 1:
|
|
return "New"
|
|
case u.SecStatus >= 2 && u.SecStatus < 100:
|
|
return "Valid"
|
|
case u.SecStatus >= 100 && u.SecStatus < 150:
|
|
return "BoardOp"
|
|
case u.SecStatus >= 150 && u.SecStatus < 255:
|
|
return "LibOp"
|
|
case u.SecStatus == 255:
|
|
return "Sysop"
|
|
default:
|
|
return "Unknown"
|
|
}
|
|
}
|