frame template now honors current user
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@ site:
|
||||
title: "Amsterdam Web Communities System"
|
||||
database:
|
||||
driver: "mysql"
|
||||
dsn: "amsdb:x00yes2k@tcp(localhost)/amsterdam"
|
||||
dsn: "amsdb:x00yes2k@tcp(localhost)/amsterdam?parseTime=true&loc=Local"
|
||||
rendering:
|
||||
templatedir: custom_templates
|
||||
cookiekey: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
|
||||
|
||||
+43
-18
@@ -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
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ require (
|
||||
github.com/labstack/echo-contrib v0.17.4 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // 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/fasttemplate v1.2.2 // indirect
|
||||
golang.org/x/crypto v0.38.0 // indirect
|
||||
|
||||
@@ -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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
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/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ func init() {
|
||||
FullTimestamp: true,
|
||||
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.
|
||||
|
||||
@@ -14,14 +14,17 @@ import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
|
||||
"git.erbosoft.com/amy/amsterdam/database"
|
||||
"github.com/CloudyKit/jet/v6"
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/labstack/echo-contrib/session"
|
||||
"github.com/labstack/echo/v4"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// AmContext is the interface for Amsterdam's wapper context that exposes the required functionality.
|
||||
type AmContext interface {
|
||||
CurrentUser() *database.User
|
||||
RC() int
|
||||
OutputType() string
|
||||
Render(string) error
|
||||
@@ -44,6 +47,11 @@ type amContext struct {
|
||||
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.
|
||||
func (c *amContext) RC() int {
|
||||
return c.httprc
|
||||
@@ -143,6 +151,8 @@ func NewAmContext(ctxt echo.Context) (AmContext, error) {
|
||||
sess.Options = defoptions
|
||||
if sess.IsNew {
|
||||
SetupAmSession(sess)
|
||||
} else {
|
||||
log.Debugf("took the not-new-session path")
|
||||
}
|
||||
}
|
||||
return &rc, err
|
||||
|
||||
+2
-2
@@ -14,6 +14,7 @@ import (
|
||||
"git.erbosoft.com/amy/amsterdam/config"
|
||||
"git.erbosoft.com/amy/amsterdam/database"
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/quasoft/memstore"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -22,8 +23,7 @@ var SessionStore sessions.Store
|
||||
|
||||
// SetupSessionManager sets up the session manager.
|
||||
func SetupSessionManager() {
|
||||
log.Infof("Cookie key is %s", config.GlobalConfig.Rendering.CookieKey)
|
||||
SessionStore = sessions.NewCookieStore([]byte(config.GlobalConfig.Rendering.CookieKey))
|
||||
SessionStore = memstore.NewMemStore([]byte(config.GlobalConfig.Rendering.CookieKey))
|
||||
}
|
||||
|
||||
// SetupAmSession sets up a newly created Amsterdam session.
|
||||
|
||||
+24
-20
@@ -24,7 +24,7 @@
|
||||
<div class="flex items-center justify-between px-2 py-2">
|
||||
<!-- Site Logo -->
|
||||
<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"
|
||||
alt="Amsterdam Test"
|
||||
class="w-35 h-20 mx-2 my-2">
|
||||
@@ -34,14 +34,14 @@
|
||||
<!-- Navigation Links -->
|
||||
<div class="w-2/5 text-center">
|
||||
<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
|
||||
</a>
|
||||
</div>
|
||||
<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>
|
||||
<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>
|
||||
|
||||
@@ -56,13 +56,19 @@
|
||||
<!-- Login Section -->
|
||||
<div class="bg-blue-600 text-center py-2">
|
||||
<span class="text-white text-base">
|
||||
You are not logged in
|
||||
<span class="mx-2">-</span>
|
||||
<a href="http://necrovenice:8080/venice/login.js.vs?tgt=top.js.vs"
|
||||
class="text-yellow-300 hover:text-yellow-400">Log In</a>
|
||||
<span class="mx-2">|</span>
|
||||
<a href="http://necrovenice:8080/venice/new_account.js.vs?tgt=top.js.vs"
|
||||
class="text-yellow-300 hover:text-yellow-400">Create Account</a>
|
||||
{{ if .CurrentUser().IsAnon }}
|
||||
You are not logged in
|
||||
<span class="mx-2">-</span>
|
||||
<a href="/TODO/login" class="text-yellow-300 hover:text-yellow-400">Log In</a>
|
||||
<span class="mx-2">|</span>
|
||||
<a href="/TODO/newaccount" 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>
|
||||
</div>
|
||||
</div>
|
||||
@@ -83,8 +89,8 @@
|
||||
<div class="text-black text-sm">
|
||||
<div class="font-bold mb-1">About This Site</div>
|
||||
<div class="text-gray-500 mb-1">Documentation</div>
|
||||
<a href="http://necrovenice:8080/venice/frame/about-venice.html"
|
||||
class="text-blue-700 hover:text-blue-900">About Venice</a>
|
||||
<a href="/TODO/aboutpage"
|
||||
class="text-blue-700 hover:text-blue-900">About Amsterdam</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -106,17 +112,15 @@
|
||||
<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 messages posted by users on this page are owned by those users.<br>
|
||||
The rest: Copyright © 2001-2006
|
||||
<a href="http://www.silverwrist.com/" class="text-blue-700 hover:text-blue-900">Silverwrist Design Studios</a>,
|
||||
The rest: Copyright © 2025
|
||||
<a href="https://www.erbosoft.com/" class="text-blue-700 hover:text-blue-900">Erbosoft Metaverse Design Solutions</a>,
|
||||
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.
|
||||
</div>
|
||||
<div class="flex-shrink-0">
|
||||
<a href="http://venice.users.sf.net/" target="_blank">
|
||||
<img src="/img/builtin/powered-by-amsterdam.png"
|
||||
alt="Powered By Amsterdam"
|
||||
class="w-32 h-26">
|
||||
<a href="https://git.erbosoft.com/amy/amsterdam" target="_blank">
|
||||
<img src="/img/builtin/powered-by-amsterdam.png" alt="Powered By Amsterdam" class="w-32 h-26">
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user