landed E-mail invites at three levels
This commit is contained in:
+96
-2
@@ -10,10 +10,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/mail"
|
||||
|
||||
"git.erbosoft.com/amy/amsterdam/database"
|
||||
"git.erbosoft.com/amy/amsterdam/email"
|
||||
"git.erbosoft.com/amy/amsterdam/ui"
|
||||
)
|
||||
|
||||
@@ -59,7 +62,7 @@ func InviteToConference(ctxt ui.AmContext) (string, any, error) {
|
||||
ctxt.VarMap().Set("amsterdam_pageTitle", "Send Invitation")
|
||||
ctxt.VarMap().Set("title", "Send Conference Invitation")
|
||||
ctxt.VarMap().Set("subtitle", conf.Name)
|
||||
ctxt.VarMap().Set("backlink", fmt.Sprintf("/comm/%s/conf/%s", comm.Alias, ctxt.GetScratch("currentAlias")))
|
||||
ctxt.VarMap().Set("backlink", fmt.Sprintf("/comm/%s/conf/%s/manage", comm.Alias, ctxt.GetScratch("currentAlias")))
|
||||
ctxt.VarMap().Set("cid", fmt.Sprintf("%d", comm.Id))
|
||||
ctxt.VarMap().Set("confid", fmt.Sprintf("%d", conf.ConfId))
|
||||
return "framed_template", "invite.jet", nil
|
||||
@@ -85,9 +88,100 @@ func InviteToTopic(ctxt ui.AmContext) (string, any, error) {
|
||||
ctxt.VarMap().Set("amsterdam_pageTitle", "Send Invitation")
|
||||
ctxt.VarMap().Set("title", "Send Topic Invitation")
|
||||
ctxt.VarMap().Set("subtitle", topic.Name)
|
||||
ctxt.VarMap().Set("backlink", fmt.Sprintf("/comm/%s/conf/%s/r/%d", comm.Alias, ctxt.GetScratch("currentAlias"), topic.Number))
|
||||
ctxt.VarMap().Set("backlink", fmt.Sprintf("/comm/%s/conf/%s/op/%d/manage", comm.Alias, ctxt.GetScratch("currentAlias"), topic.Number))
|
||||
ctxt.VarMap().Set("cid", fmt.Sprintf("%d", comm.Id))
|
||||
ctxt.VarMap().Set("confid", fmt.Sprintf("%d", conf.ConfId))
|
||||
ctxt.VarMap().Set("topicid", fmt.Sprintf("%d", topic.TopicId))
|
||||
return "framed_template", "invite.jet", nil
|
||||
}
|
||||
|
||||
/* InviteSend is the back end that handles sending invitations.
|
||||
* 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 InviteSend(ctxt ui.AmContext) (string, any, error) {
|
||||
backlink := ctxt.FormField("backlink")
|
||||
if ctxt.FormFieldIsSet("cancel") {
|
||||
return "redirect", backlink, nil
|
||||
} else if !ctxt.FormFieldIsSet("send") {
|
||||
return ui.ErrorPage(ctxt, errors.New("invalid command"))
|
||||
}
|
||||
var comm *database.Community
|
||||
if ctxt.FormFieldIsSet("cid") {
|
||||
id, err := ctxt.FormFieldInt("cid")
|
||||
if err == nil {
|
||||
comm, err = database.AmGetCommunity(ctxt.Ctx(), int32(id))
|
||||
}
|
||||
if err != nil {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
}
|
||||
} else {
|
||||
return ui.ErrorPage(ctxt, errors.New("no parameters specified"))
|
||||
}
|
||||
mode := "community"
|
||||
var conf *database.Conference = nil
|
||||
var topic *database.Topic = nil
|
||||
if ctxt.FormFieldIsSet("confid") {
|
||||
id, err := ctxt.FormFieldInt("confid")
|
||||
if err == nil {
|
||||
if conf, err = database.AmGetConference(ctxt.Ctx(), int32(id)); err == nil {
|
||||
var f bool
|
||||
if f, err = conf.InCommunity(ctxt.Ctx(), comm); err == nil {
|
||||
if !f {
|
||||
err = errors.New("invalid conference; not in community")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
}
|
||||
if ctxt.FormFieldIsSet("topicid") {
|
||||
id, err := ctxt.FormFieldInt("topicid")
|
||||
if err == nil {
|
||||
topic, err = database.AmGetTopic(ctxt.Ctx(), int32(id))
|
||||
if err == nil && topic.ConfId != conf.ConfId {
|
||||
err = errors.New("invalid topic; not in conference")
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
}
|
||||
mode = "topic"
|
||||
} else {
|
||||
mode = "conference"
|
||||
}
|
||||
}
|
||||
addr := ctxt.FormField("addr")
|
||||
_, err := mail.ParseAddress(addr)
|
||||
if err != nil {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
}
|
||||
|
||||
ci, err := database.AmGetContactInfoForUser(ctxt.Ctx(), ctxt.CurrentUserId())
|
||||
if err != nil {
|
||||
return ui.ErrorPage(ctxt, err)
|
||||
}
|
||||
|
||||
mailMessage := email.AmNewEmailMessage(ctxt.CurrentUserId(), ctxt.RemoteIP())
|
||||
if comm.Public() {
|
||||
mailMessage.SetTemplate("invite_public.jet")
|
||||
} else {
|
||||
mailMessage.SetTemplate("invite_private.jet")
|
||||
}
|
||||
mailMessage.AddTo(addr, "")
|
||||
mailMessage.AddVariable("comm", comm)
|
||||
mailMessage.AddVariable("conf", conf)
|
||||
mailMessage.AddVariable("topic", topic)
|
||||
mailMessage.AddVariable("mode", mode)
|
||||
mailMessage.AddVariable("personal", ctxt.FormField("msg"))
|
||||
mailMessage.AddVariable("fullname", ci.FullName(true))
|
||||
mailMessage.AddVariable("username", ctxt.CurrentUser().Username)
|
||||
mailMessage.Send()
|
||||
|
||||
return "redirect", backlink, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user