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
+1 -1
View File
@@ -10,7 +10,7 @@ site:
title: "Amsterdam Web Communities System" title: "Amsterdam Web Communities System"
database: database:
driver: "mysql" driver: "mysql"
dsn: "amsdb:x00yes2k@tcp(localhost)/amsterdam" dsn: "amsdb:x00yes2k@tcp(localhost)/amsterdam?parseTime=true&loc=Local"
rendering: rendering:
templatedir: custom_templates templatedir: custom_templates
cookiekey: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz cookiekey: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
+31 -6
View File
@@ -10,6 +10,7 @@
package database package database
import ( import (
"encoding/gob"
"fmt" "fmt"
"time" "time"
) )
@@ -19,7 +20,7 @@ type User struct {
Uid int32 `db:"uid"` Uid int32 `db:"uid"`
Username string `db:"username"` Username string `db:"username"`
Passhash string `db:"passhash"` Passhash string `db:"passhash"`
Tokenauth string `db:"tokenauth"` Tokenauth *string `db:"tokenauth"`
ContactID int32 `db:"contactid"` ContactID int32 `db:"contactid"`
IsAnon bool `db:"is_anon"` IsAnon bool `db:"is_anon"`
VerifyEMail bool `db:"verify_email"` VerifyEMail bool `db:"verify_email"`
@@ -28,20 +29,44 @@ type User struct {
EmailConfNum int32 `db:"email_confnum"` EmailConfNum int32 `db:"email_confnum"`
BaseLevel uint16 `db:"base_lvl"` BaseLevel uint16 `db:"base_lvl"`
Created time.Time `db:"created"` Created time.Time `db:"created"`
LastAccess time.Time `db:"lastaccess"` LastAccess *time.Time `db:"lastaccess"`
PassReminder string `db:"passreminder"` PassReminder string `db:"passreminder"`
Description string `db:"description"` Description *string `db:"description"`
DOB time.Time `db:"dob"` 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. /* AmGetAmonUser returns a reference to the anonymous user.
* Returns: * Returns:
* Pointer to User containing anonymous user data * Pointer to User containing anonymous user data, or nil
* Standard Go error status * Standard Go error status
*/ */
func AmGetAnonUser() (*User, error) { func AmGetAnonUser() (*User, error) {
var rc []User 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 { if err != nil {
return nil, err return nil, err
} }
+1
View File
@@ -23,6 +23,7 @@ require (
github.com/labstack/echo-contrib v0.17.4 // indirect github.com/labstack/echo-contrib v0.17.4 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.20 // indirect
github.com/quasoft/memstore v0.0.0-20191010062613-2bce066d2b0b // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.38.0 // indirect golang.org/x/crypto v0.38.0 // indirect
+2
View File
@@ -36,6 +36,8 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/quasoft/memstore v0.0.0-20191010062613-2bce066d2b0b h1:aUNXCGgukb4gtY99imuIeoh8Vr0GSwAlYxPAhqZrpFc=
github.com/quasoft/memstore v0.0.0-20191010062613-2bce066d2b0b/go.mod h1:wTPjTepVu7uJBYgZ0SdWHQlIas582j6cn2jgk4DDdlg=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+1 -1
View File
@@ -25,7 +25,7 @@ func init() {
FullTimestamp: true, FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05", TimestampFormat: "2006-01-02 15:04:05",
}) })
log.SetLevel(log.InfoLevel) log.SetLevel(log.DebugLevel)
} }
/* toglog converts a Logrus logging level to a glog one. /* toglog converts a Logrus logging level to a glog one.
+10
View File
@@ -14,14 +14,17 @@ import (
"bytes" "bytes"
"net/http" "net/http"
"git.erbosoft.com/amy/amsterdam/database"
"github.com/CloudyKit/jet/v6" "github.com/CloudyKit/jet/v6"
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
"github.com/labstack/echo-contrib/session" "github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
log "github.com/sirupsen/logrus"
) )
// AmContext is the interface for Amsterdam's wapper context that exposes the required functionality. // AmContext is the interface for Amsterdam's wapper context that exposes the required functionality.
type AmContext interface { type AmContext interface {
CurrentUser() *database.User
RC() int RC() int
OutputType() string OutputType() string
Render(string) error Render(string) error
@@ -44,6 +47,11 @@ type amContext struct {
session *sessions.Session session *sessions.Session
} }
// CurrentUser returns the current user from the session.
func (c *amContext) CurrentUser() *database.User {
return c.session.Values["user"].(*database.User)
}
// RC returns the HTTP result code for the current operation. // RC returns the HTTP result code for the current operation.
func (c *amContext) RC() int { func (c *amContext) RC() int {
return c.httprc return c.httprc
@@ -143,6 +151,8 @@ func NewAmContext(ctxt echo.Context) (AmContext, error) {
sess.Options = defoptions sess.Options = defoptions
if sess.IsNew { if sess.IsNew {
SetupAmSession(sess) SetupAmSession(sess)
} else {
log.Debugf("took the not-new-session path")
} }
} }
return &rc, err return &rc, err
+2 -2
View File
@@ -14,6 +14,7 @@ import (
"git.erbosoft.com/amy/amsterdam/config" "git.erbosoft.com/amy/amsterdam/config"
"git.erbosoft.com/amy/amsterdam/database" "git.erbosoft.com/amy/amsterdam/database"
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
"github.com/quasoft/memstore"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@@ -22,8 +23,7 @@ var SessionStore sessions.Store
// SetupSessionManager sets up the session manager. // SetupSessionManager sets up the session manager.
func SetupSessionManager() { func SetupSessionManager() {
log.Infof("Cookie key is %s", config.GlobalConfig.Rendering.CookieKey) SessionStore = memstore.NewMemStore([]byte(config.GlobalConfig.Rendering.CookieKey))
SessionStore = sessions.NewCookieStore([]byte(config.GlobalConfig.Rendering.CookieKey))
} }
// SetupAmSession sets up a newly created Amsterdam session. // SetupAmSession sets up a newly created Amsterdam session.
+21 -17
View File
@@ -24,7 +24,7 @@
<div class="flex items-center justify-between px-2 py-2"> <div class="flex items-center justify-between px-2 py-2">
<!-- Site Logo --> <!-- Site Logo -->
<div class="w-1/5"> <div class="w-1/5">
<a href="http://venice.sourceforge.net/"> <a href="https://git.erbosoft.com/amy/amsterdam">
<img src="/img/builtin/powered-by-amsterdam.png" <img src="/img/builtin/powered-by-amsterdam.png"
alt="Amsterdam Test" alt="Amsterdam Test"
class="w-35 h-20 mx-2 my-2"> class="w-35 h-20 mx-2 my-2">
@@ -34,14 +34,14 @@
<!-- Navigation Links --> <!-- Navigation Links -->
<div class="w-2/5 text-center"> <div class="w-2/5 text-center">
<div class="text-white font-bold text-base mb-2"> <div class="text-white font-bold text-base mb-2">
<a href="http://necrovenice:8080/venice/top.js.vs" class="text-yellow-300 hover:text-yellow-400"> <a href="/" class="text-yellow-300 hover:text-yellow-400">
Front Page Front Page
</a> </a>
</div> </div>
<div class="text-white font-bold text-base"> <div class="text-white font-bold text-base">
<a href="http://necrovenice:8080/TODO" class="text-yellow-300 hover:text-yellow-400">Help</a> <a href="/TODO/help" class="text-yellow-300 hover:text-yellow-400">Help</a>
<span class="mx-2">|</span> <span class="mx-2">|</span>
<a href="http://necrovenice:8080/venice/find.js.vs" class="text-yellow-300 hover:text-yellow-400">Find</a> <a href="/TODO/find" class="text-yellow-300 hover:text-yellow-400">Find</a>
</div> </div>
</div> </div>
@@ -56,13 +56,19 @@
<!-- Login Section --> <!-- Login Section -->
<div class="bg-blue-600 text-center py-2"> <div class="bg-blue-600 text-center py-2">
<span class="text-white text-base"> <span class="text-white text-base">
{{ if .CurrentUser().IsAnon }}
You are not logged in You are not logged in
<span class="mx-2">-</span> <span class="mx-2">-</span>
<a href="http://necrovenice:8080/venice/login.js.vs?tgt=top.js.vs" <a href="/TODO/login" class="text-yellow-300 hover:text-yellow-400">Log In</a>
class="text-yellow-300 hover:text-yellow-400">Log In</a>
<span class="mx-2">|</span> <span class="mx-2">|</span>
<a href="http://necrovenice:8080/venice/new_account.js.vs?tgt=top.js.vs" <a href="/TODO/newaccount" class="text-yellow-300 hover:text-yellow-400">Create Account</a>
class="text-yellow-300 hover:text-yellow-400">Create Account</a> {{ else }}
You are logged in as <b>{{ .CurrentUser().Username }}</b>
<span class="mx-2">-</span>
<a href="/TODO/logout" class="text-yellow-300 hover:text-yellow-400">Log Out</a>
<span class="mx-2">|</span>
<a href="/TODO/profile" class="text-yellow-300 hover:text-yellow-400">Profile</a>
{{ end }}
</span> </span>
</div> </div>
</div> </div>
@@ -83,8 +89,8 @@
<div class="text-black text-sm"> <div class="text-black text-sm">
<div class="font-bold mb-1">About This Site</div> <div class="font-bold mb-1">About This Site</div>
<div class="text-gray-500 mb-1">Documentation</div> <div class="text-gray-500 mb-1">Documentation</div>
<a href="http://necrovenice:8080/venice/frame/about-venice.html" <a href="/TODO/aboutpage"
class="text-blue-700 hover:text-blue-900">About Venice</a> class="text-blue-700 hover:text-blue-900">About Amsterdam</a>
</div> </div>
</div> </div>
</div> </div>
@@ -106,17 +112,15 @@
<div class="text-right text-xs text-black leading-relaxed"> <div class="text-right text-xs text-black leading-relaxed">
All trademarks and copyrights on this page are owned by their respective companies.<br> All trademarks and copyrights on this page are owned by their respective companies.<br>
All messages posted by users on this page are owned by those users.<br> All messages posted by users on this page are owned by those users.<br>
The rest: Copyright © 2001-2006 The rest: Copyright © 2025
<a href="http://www.silverwrist.com/" class="text-blue-700 hover:text-blue-900">Silverwrist Design Studios</a>, <a href="https://www.erbosoft.com/" class="text-blue-700 hover:text-blue-900">Erbosoft Metaverse Design Solutions</a>,
All Rights Reserved.<br> All Rights Reserved.<br>
See our <a href="http://necrovenice:8080/TODO" class="text-blue-700 hover:text-blue-900">Policy Page</a> See our <a href="/TODO/policypage" class="text-blue-700 hover:text-blue-900">Policy Page</a>
for our copyright and privacy policies. for our copyright and privacy policies.
</div> </div>
<div class="flex-shrink-0"> <div class="flex-shrink-0">
<a href="http://venice.users.sf.net/" target="_blank"> <a href="https://git.erbosoft.com/amy/amsterdam" target="_blank">
<img src="/img/builtin/powered-by-amsterdam.png" <img src="/img/builtin/powered-by-amsterdam.png" alt="Powered By Amsterdam" class="w-32 h-26">
alt="Powered By Amsterdam"
class="w-32 h-26">
</a> </a>
</div> </div>
</div> </div>