From 60b0ec8a5d48cd1347ca951b7b09bfda8d9adcd6 Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Wed, 8 Oct 2025 16:36:23 -0600 Subject: [PATCH] straightened out the "account creation" workflow --- database/contactinfo.go | 2 +- database/sidebox.go | 24 ++++-------------------- database/user.go | 15 +++++++++++++-- email/templates/email_confirm.jet | 2 +- login.go | 13 +++++++++---- ui/dialog.go | 13 +++++++++++-- ui/dialogs/login.yaml | 1 + ui/dialogs/newaccount.yaml | 1 + ui/dialogs/verify_email.yaml | 1 + ui/views/frame.jet | 20 ++++++++++++-------- 10 files changed, 54 insertions(+), 38 deletions(-) diff --git a/database/contactinfo.go b/database/contactinfo.go index 12b6f58..5b9105f 100644 --- a/database/contactinfo.go +++ b/database/contactinfo.go @@ -130,7 +130,7 @@ func (ci *ContactInfo) Save() (bool, error) { addr2, locality, region, pcode, country, phone, fax, mobile, email, pvt_addr, pvt_phone, pvt_fax, pvt_email, owner_uid, owner_commid, photo_url, url, lastupdate) VALUES (:given_name, :family_name, :middle_init, :prefix, :suffix, :company, :addr1, :addr2, :locality, - :region:, :pcode, :country, :phone, :fax, :mobile, :email, :pvt_addr, :pvt_phone, :pvt_fax, :pvt_email, + :region, :pcode, :country, :phone, :fax, :mobile, :email, :pvt_addr, :pvt_phone, :pvt_fax, :pvt_email, :owner_uid, :owner_commid, :photo_url, :url, NOW())`, ci) if err != nil { return false, err diff --git a/database/sidebox.go b/database/sidebox.go index c56ade8..18463d1 100644 --- a/database/sidebox.go +++ b/database/sidebox.go @@ -19,7 +19,7 @@ type Sidebox struct { // copySideboxes copies sideboxes from one user to another. func copySideboxes(toUid int32, fromUid int32) error { sbox := make([]Sidebox, 0, 3) - err := amdb.Select(sbox, "SELECT * from sideboxes WHERE uid = ?", fromUid) + err := amdb.Select(&sbox, "SELECT * from sideboxes WHERE uid = ?", fromUid) if err == nil { for _, sb := range sbox { _, err := amdb.Exec("INSERT INTO sideboxes (uid, boxid, sequence, param) VALUES (?, ?, ?, ?)", toUid, sb.Boxid, sb.Sequence, sb.Param) @@ -39,23 +39,7 @@ func copySideboxes(toUid int32, fromUid int32) error { * Standard Go error status */ func AmGetSideboxes(uid int32) ([]*Sidebox, error) { - stmt, err := amdb.Preparex("SELECT * FROM sideboxes WHERE uid = ? ORDER BY SEQUENCE") - if err == nil { - defer stmt.Close() - rows, err := stmt.Queryx(uid) - if err == nil { - defer rows.Close() - sboxes := make([]*Sidebox, 0, 3) - for i := 0; rows.Next(); i++ { - box := Sidebox{} - rows.StructScan(&box) - sboxes = append(sboxes, &box) - } - if rows.Err() == nil { - return sboxes, nil - } - return nil, rows.Err() - } - } - return nil, err + sboxes := make([]*Sidebox, 0, 3) + err := amdb.Select(&sboxes, "SELECT * FROM sideboxes WHERE uid = ? ORDER BY SEQUENCE", uid) + return sboxes, err } diff --git a/database/user.go b/database/user.go index 0519b29..b7eb167 100644 --- a/database/user.go +++ b/database/user.go @@ -120,6 +120,17 @@ func (u *User) ContactInfo() (*ContactInfo, error) { return AmGetContactInfo(u.ContactID) } +// SetContactID sets the contact ID of a user. +func (u *User) SetContactID(cid int32) error { + u.Mutex.Lock() + defer u.Mutex.Unlock() + if _, err := amdb.Exec("UPDATE users SET contactid = ? WHERE uid = ?", cid, u.Uid); err != nil { + return err + } + u.ContactID = cid + return nil +} + /* NewAuthToken generates and returns a new authentication token for the user. * Returns: * Authentication token value @@ -495,12 +506,12 @@ func AmCreateNewUser(username string, password string, reminder string, dob *tim // add user properties props := make([]UserProperties, 0) anon, _ := getAnonUserID() - err = amdb.Select(props, "SELECT * FROM propuser WHERE uid = ?", anon) + err = amdb.Select(&props, "SELECT * FROM propuser WHERE uid = ?", anon) if err != nil { return nil, err } for _, p := range props { - _, err := amdb.Exec("INSTERT INTO propuser (uid, ndx, data) VALUES (?, ?, ?)", user.Uid, p.Index, p.Data) + _, err := amdb.Exec("INSERT INTO propuser (uid, ndx, data) VALUES (?, ?, ?)", user.Uid, p.Index, p.Data) if err != nil { return nil, err } diff --git a/email/templates/email_confirm.jet b/email/templates/email_confirm.jet index 1221c58..54d959d 100644 --- a/email/templates/email_confirm.jet +++ b/email/templates/email_confirm.jet @@ -6,7 +6,7 @@ E-mail Address" dialog on the system when indicated. Your confirmation number for your account "{{ username }}" is {{ confnum }}. -Access the E-mail verification dialog at . +Access the E-mail verification dialog at <{{ GlobalConfig.Site.BaseURL }}/verify>. Thank you, and enjoy the Amsterdam conferencing system! diff --git a/login.go b/login.go index 22040e0..aed2bb9 100644 --- a/login.go +++ b/login.go @@ -174,7 +174,7 @@ func VerifyEmailForm(ctxt ui.AmContext) (string, any, error) { // If user is not logged in, this is an error. user := ctxt.CurrentUser() - if !user.IsAnon { + if user.IsAnon { return ui.ErrorPage(ctxt, errors.New("you must log in before you can verify your account's E-mail address")) } @@ -196,7 +196,7 @@ func sendEmailConfirmationEmail(user *database.User, ci *database.ContactInfo, r if ci != nil && ci.Email != nil && *ci.Email != "" { msg := email.AmNewEmailMessage(user.Uid, remoteIP) msg.AddTo(*ci.Email, "") - msg.SetTemplate("verify_email.jet") + msg.SetTemplate("email_confirm.jet") msg.AddVariable("username", user.Username) msg.AddVariable("confnum", user.EmailConfNum) msg.Send() @@ -217,7 +217,7 @@ func sendEmailConfirmationEmail(user *database.User, ci *database.ContactInfo, r func VerifyEMail(ctxt ui.AmContext) (string, any, error) { // If user is not logged in, this is an error. user := ctxt.CurrentUser() - if !user.IsAnon { + if user.IsAnon { return ui.ErrorPage(ctxt, errors.New("you must log in before you can verify your account's E-mail address")) } @@ -256,7 +256,8 @@ func VerifyEMail(ctxt ui.AmContext) (string, any, error) { if action == "ok" { err = dlg.Validate() if err == nil { - err = user.ConfirmEMailAddress(dlg.Field("num").AuxData.(int32), ctxt.RemoteIP()) + cn, _ := dlg.Field("num").ValueInt() + err = user.ConfirmEMailAddress(int32(cn), ctxt.RemoteIP()) if err == nil { return "redirect", target, nil } @@ -290,6 +291,7 @@ func NewAccountUserAgreement(ctxt ui.AmContext) (string, any, error) { ctxt.VarMap().Set("target", target) ctxt.VarMap().Set("amsterdam_pageTitle", "New Account User Agreement") + ctxt.VarMap().Set("amsterdam_suppressLogin", true) return "framed_template", "agreement.jet", nil } @@ -382,6 +384,9 @@ func NewAccount(ctxt ui.AmContext) (string, any, error) { ci.Country = dlg.Field("country").ValPtr() ci.Email = dlg.Field("email").ValPtr() _, err = ci.Save() + if err == nil { + err = user.SetContactID(ci.ContactId) + } if err == nil { err = sendEmailConfirmationEmail(user, ci, ctxt.RemoteIP()) } diff --git a/ui/dialog.go b/ui/dialog.go index 54f4e5e..a661f4c 100644 --- a/ui/dialog.go +++ b/ui/dialog.go @@ -40,6 +40,7 @@ type DialogItem struct { type Dialog struct { Name string `yaml:"name"` FormName string `yaml:"formName"` + Options string `yaml:"options,omitempty"` MenuSelector string `yaml:"menuSelector,omitempty"` Title string `yaml:"title"` Action string `yaml:"action"` @@ -104,6 +105,11 @@ func (fld *DialogItem) IsChecked() bool { return false } +// ValueInt returns the value of the field as an integer. +func (fld *DialogItem) ValueInt() (int, error) { + return strconv.Atoi(fld.Value) +} + // ValueRange returns the minimum and maximum values for an integer field. func (fld *DialogItem) ValueRange() VRange { if fld.Type == "integer" && fld.Param != "" { @@ -169,6 +175,9 @@ func (d *Dialog) Render(ctxt AmContext) (string, any, error) { ctxt.VarMap().Set("amsterdam_required", required) ctxt.VarMap().Set("amsterdam_dialog", d) ctxt.VarMap().Set("amsterdam_pageTitle", d.Title) + if strings.Contains(d.Options, "suppresslogin") { + ctxt.VarMap().Set("amsterdam_suppressLogin", true) + } return "framed_template", "dialog.jet", nil } @@ -417,11 +426,11 @@ var validators = map[string]validatorFunc{ * Standard Go error status. */ func (d *Dialog) Validate() error { - for _, fld := range d.Fields { + for i, fld := range d.Fields { if len(fld.Value) > 0 || fld.Required { vfunc := validators[fld.Type] if vfunc != nil { - err := vfunc(&fld) + err := vfunc(&(d.Fields[i])) if err != nil { return err } diff --git a/ui/dialogs/login.yaml b/ui/dialogs/login.yaml index 41a7d93..4def7e0 100644 --- a/ui/dialogs/login.yaml +++ b/ui/dialogs/login.yaml @@ -10,6 +10,7 @@ name: "login" formName: "loginform" menuSelector: "top" title: "Log In" +options: "suppresslogin" action: "/login" instructions: > Forgot your password? Enter your user name and click the Reminder button to receive diff --git a/ui/dialogs/newaccount.yaml b/ui/dialogs/newaccount.yaml index 09bc833..d9f7df0 100644 --- a/ui/dialogs/newaccount.yaml +++ b/ui/dialogs/newaccount.yaml @@ -10,6 +10,7 @@ name: "newaccount" formName: "createform" menuSelector: "top" title: "Create New Account" +options: "suppresslogin" action: "/newacct2" instructions: > To create a new account, please enter your information below. diff --git a/ui/dialogs/verify_email.yaml b/ui/dialogs/verify_email.yaml index 744df85..2e196f4 100644 --- a/ui/dialogs/verify_email.yaml +++ b/ui/dialogs/verify_email.yaml @@ -10,6 +10,7 @@ name: "verify" formName: "verifyform" menuSelector: "top" title: "Verify E-mail Address" +options: "suppresslogin" action: "/verify" instructions: > Check your E-mail, then enter the confirmation number that was E-mailed to you in the field below. diff --git a/ui/views/frame.jet b/ui/views/frame.jet index ab3ed2b..cc0422b 100644 --- a/ui/views/frame.jet +++ b/ui/views/frame.jet @@ -58,16 +58,20 @@ {{ if .CurrentUser().IsAnon }} You are not logged in - - - Log In - | - Create Account + {{ if !isset(amsterdam_suppressLogin) || !amsterdam_suppressLogin }} + - + Log In + | + Create Account + {{ end }} {{ else }} You are logged in as {{ .CurrentUser().Username }} - - - Log Out - | - Profile + {{ if !isset(amsterdam_suppressLogin) || !amsterdam_suppressLogin }} + - + Log Out + | + Profile + {{ end }} {{ end }}