straightened out the "account creation" workflow
This commit is contained in:
@@ -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
|
||||
|
||||
+4
-20
@@ -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
|
||||
}
|
||||
|
||||
+13
-2
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 <http://example.com/verifyemail>.
|
||||
Access the E-mail verification dialog at <{{ GlobalConfig.Site.BaseURL }}/verify>.
|
||||
|
||||
Thank you, and enjoy the Amsterdam conferencing system!
|
||||
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
+11
-2
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 <b>Reminder</b> button to receive
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
+12
-8
@@ -58,16 +58,20 @@
|
||||
<span class="text-white text-base">
|
||||
{{ if .CurrentUser().IsAnon }}
|
||||
You are not logged in
|
||||
<span class="mx-2">-</span>
|
||||
<a href="/login" class="text-yellow-300 hover:text-yellow-400">Log In</a>
|
||||
<span class="mx-2">|</span>
|
||||
<a href="/newacct" class="text-yellow-300 hover:text-yellow-400">Create Account</a>
|
||||
{{ if !isset(amsterdam_suppressLogin) || !amsterdam_suppressLogin }}
|
||||
<span class="mx-2">-</span>
|
||||
<a href="/login" class="text-yellow-300 hover:text-yellow-400">Log In</a>
|
||||
<span class="mx-2">|</span>
|
||||
<a href="/newacct" class="text-yellow-300 hover:text-yellow-400">Create Account</a>
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
You are logged in as <b>{{ .CurrentUser().Username }}</b>
|
||||
<span class="mx-2">-</span>
|
||||
<a href="/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>
|
||||
{{ if !isset(amsterdam_suppressLogin) || !amsterdam_suppressLogin }}
|
||||
<span class="mx-2">-</span>
|
||||
<a href="/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 }}
|
||||
{{ end }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user