diff --git a/login.go b/login.go new file mode 100644 index 0000000..466926c --- /dev/null +++ b/login.go @@ -0,0 +1,29 @@ +/* + * 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/. + */ +// Package main contains the high-level Amsterdam logic. +package main + +import "git.erbosoft.com/amy/amsterdam/ui" + +/* LoginForm renders the Amsterdam login form. + * Parameters: + * ctxt - The AmContext for the request. + * Returns: + * Command string dictating what to be rendered. + * Data as a parameter for the command string. + * Standard Go error status. + */ +func LoginForm(ctxt ui.AmContext) (string, any, error) { + dlg, err := ui.AmLoadDialog("login") + if err == nil { + ctxt.VarMap().Set("amsterdam_pageTitle", "Log In") + return dlg.Render(ctxt) + } + return ui.ErrorPage(ctxt, err) +} diff --git a/main.go b/main.go index e00132b..5d1f099 100644 --- a/main.go +++ b/main.go @@ -35,10 +35,14 @@ func setupEcho() *echo.Echo { e.Use(LogrusMiddleware) e.Use(session.Middleware(ui.SessionStore)) - e.GET("/TODO/*", ui.AmWrap(NotImplPage)) + fn := ui.AmWrap(NotImplPage) + e.GET("/TODO/*", fn) + e.POST("/TODO/*", fn) e.GET("/img/*", ui.AmWrap(ui.AmServeImage)) - e.GET("/about", ui.AmWrap(AboutPage)) + e.GET("/", ui.AmWrap(TopPage)) + e.GET("/about", ui.AmWrap(AboutPage)) + e.GET("/login", ui.AmWrap(LoginForm)) return e } diff --git a/ui/dialog.go b/ui/dialog.go new file mode 100644 index 0000000..ea6baad --- /dev/null +++ b/ui/dialog.go @@ -0,0 +1,75 @@ +/* + * 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/. + */ + +// Package ui holds the support for the Amsterdam user interface, wrapping Echo and Jet templates. +package ui + +import ( + "embed" + "fmt" + + "gopkg.in/yaml.v3" +) + +// DialogItem holds the dialog item definition. +type DialogItem struct { + Type string `yaml:"type"` + Name string `yaml:"name"` + Caption string `yaml:"caption,omitempty"` + Size int `yaml:"size,omitempty"` + MaxLength int `yaml:"maxlength,omitempty"` + Value string `yaml:"value,omitempty"` + Tone string `yaml:"tone,omitempty"` +} + +// Dialog holds the dialog definition. +type Dialog struct { + Name string `yaml:"name"` + FormName string `yaml:"formName"` + MenuSelector string `yaml:"menuSelector,omitempty"` + Title string `yaml:"title"` + Action string `yaml:"action"` + Instructions string `yaml:"instructions,omitempty"` + Fields []DialogItem `yaml:"fields"` +} + +//go:embed dialogs/* +var dialogs embed.FS + +/* AmLoadDialog loads a dialog definition. + * Parameters: + * name - The name of the dialog to load + */ +func AmLoadDialog(name string) (*Dialog, error) { + b, err := dialogs.ReadFile(fmt.Sprintf("dialogs/%s.yaml", name)) + if err == nil { + var d Dialog + err = yaml.Unmarshal(b, &d) + if err == nil { + if d.MenuSelector == "" { + d.MenuSelector = "nochange" + } + return &d, nil + } + } + return nil, err +} + +/* Render sets up the rendering parameters to send this dialog to the output. + * Parameters: + * ctxt - The AmContext for this request. + * Returns: + * Command string dictating what to be rendered. + * Data as a parameter for the command string. + * Standard Go error status. + */ +func (d *Dialog) Render(ctxt AmContext) (string, any, error) { + ctxt.VarMap().Set("amsterdam_dialog", d) + return "framed_template", "dialog.jet", nil +} diff --git a/ui/dialogs/login.yaml b/ui/dialogs/login.yaml new file mode 100644 index 0000000..aec6b24 --- /dev/null +++ b/ui/dialogs/login.yaml @@ -0,0 +1,45 @@ +# +# 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/. +# +name: "login" +formName: "loginform" +menuSelector: "top" +title: "Log In" +action: "/TODO/login" +instructions: > + Forgot your password? Enter your user name and click the Reminder button to receive + a password reminder via E-mail. +fields: + - type: "hidden" + name: "tgt" + value: "" + - type: "veniceid" + name: "user" + caption: "User Name" + size: 32 + maxlength: 64 + - type: "password" + name: "pass" + caption: "Password" + size: 32 + maxlength: 128 + - type: "checkbox" + name: "saveme" + caption: "Remember me for next time so I can log in automatically" + - type: "button" + name: "login" + caption: "Log In" + tone: "blue" + - type: "button" + name: "remind" + caption: "Password Reminder" + tone: "gray" + - type: "button" + name: "cancel" + caption: "Cancel" + tone: "red" diff --git a/ui/views/dialog.jet b/ui/views/dialog.jet new file mode 100644 index 0000000..a6f3490 --- /dev/null +++ b/ui/views/dialog.jet @@ -0,0 +1,68 @@ +{* + * 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/. + *} +